Default configuration

LiteLLM is well integrated with OpenTelemetry, so you only need to specify the configuration through the environment variables.

1

Install the opentelemetry packages

First, install the opentelemetry packages:

pip install opentelemetry-api opentelemetry-sdk\
  opentelemetry-exporter-otlp
2

install LiteLLM

For opentelemetry callback to work, you need to install LiteLLM with the proxy extra of the LiteLLM package.

pip install litellm[proxy]
3

Set the environment variables

LMNR_PROJECT_API_KEY="<your-project-api-key>"
OTEL_EXPORTER="otlp_grpc"
OTEL_ENDPOINT="https://api.lmnr.ai:8443"
OTEL_HEADERS="authorization=Bearer $LMNR_PROJECT_API_KEY"

authorization must start with a lowercase a. This is different from common HTTP headers convention.

4

Enable otel callback in the code

litellm.callbacks = ['otel']
5

Run your code and see traces in Laminar

Using Laminar’s features

If you want to use Laminar’s features, such as sessions, manual spans, observe decorator, you will need to install and initialize Laminar.

1

Install Laminar

pip install lmnr
2

Initialize Laminar

from lmnr import Laminar
Laminar.initialize(project_api_key="LMNR_PROJECT_API_KEY")

This, however, will most likely result in your LLM calls being double-traced – once by LiteLLM and once by Laminar. To avoid this, you can disable automatic Laminar instruments at initialization.

Laminar.initialize(project_api_key="LMNR_PROJECT_API_KEY", instruments=set())