Otel Integration Openlit
title: OpenLIT Integration via OpenTelemetry description: Example cookbook for the OpenLIT Langfuse integration using OpenTelemetry. category: Integrations
OpenLIT Integration via OpenTelemetry
Langfuse is an OpenTelemetry backend, allowing trace ingestion from various OpenTelemetry instrumentation libraries. This guide demonstrates how to use the OpenLit instrumentation library to instrument a compatible framework or LLM provider.
Step 1: Install Dependencies
Install the necessary Python packages: openai, langfuse, and openlit. These will allow you to interact with OpenAI as well as setup the instrumentation for tracing.
Step 2: Configure Environment Variables
Before sending any requests, you need to configure your credentials and endpoints. First, set up the Langfuse authentication by providing your public and secret keys. Then, configure the OpenTelemetry exporter endpoint and headers to point to Langfuse's backend. You should also specify your OpenAI API key.
With the environment variables set, we can now initialize the Langfuse client. get_client() initializes the Langfuse client using the credentials provided in the environment variables.
Step 3: Initialize Instrumentation
With the environment set up, import the needed libraries and initialize OpenLIT instrumentation. We set tracer=tracer to use the tracer we created in the previous step.
Step 4: Make a Chat Completion Request
For this example, we will make a simple chat completion request to the OpenAI Chat API. This will generate trace data that you can later view in the Langfuse dashboard.
Step 5: See Traces in Langfuse
You can view the generated trace data in Langfuse. You can view this example trace in the Langfuse UI.
