Skip to main content

Migrate the Langfuse SDK callback to OpenTelemetry v2

This guide moves a proxy from the SDK-based langfuse callback to the langfuse_otel callback on OpenTelemetry v2. Read the breaking changes before you start. With default settings, V2 sends far more data to Langfuse than the SDK callback did and leaves prompts out, so a plain callback swap changes both your Langfuse bill and what your traces show.

If you already run langfuse_otel without LITELLM_OTEL_V2, follow the general V2 migration guide instead.

Breaking changes​

Each of these takes effect as soon as you switch, and each has a setting that brings back the SDK behavior.

What changedWhat you see after switchingWhat to do
Trace volume. V2 sends the whole request tree by defaultEvery request adds HTTP, auth, Postgres, Redis, guardrail, MCP and spend-write spans, and admin calls such as /model/info become traces of their own. Langfuse ingestion can grow by an order of magnitude or more at the same request rateSet LITELLM_OTEL_LANGFUSE_SPAN_SCOPE=llm_only for your own project and LITELLM_OTEL_LANGFUSE_DESTINATION_SPAN_SCOPE=llm_only Since v1.111.0 for key and team projects. On older releases, set langfuse_span_scope: llm_only on each key and team callback
Prompt capture. V2 captures no message content by defaultInput and output are empty in LangfuseSet OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=span_only. This applies to every V2 OTel callback on the proxy. A key or team can override it with capture_message_content Since v1.108.0
Default host. Without LANGFUSE_HOST, V2 sends to the US cloud (https://us.cloud.langfuse.com), while the SDK callback used the EU cloud (https://cloud.langfuse.com). LANGFUSE_BASE_URL is not readExports go to the wrong region and fail with 401Set LANGFUSE_HOST explicitly
Stored key and team callbacks. Saved langfuse entries are not convertedThose keys and teams keep logging through the SDK callback, or log twice once you add langfuse_otelRe-register each one as langfuse_otel and delete the old entry (step 3)
Secret field name. V2 reads langfuse_secret_key onlyAn entry saved with the older langfuse_secret field logs to your project instead of the tenant's, with no errorUse langfuse_secret_key when you re-register
Custom tenant hosts. A langfuse_host on a key or team needs an allowlist entryThat tenant's traces are not sent to its host, and the proxy logs a warningAdd the host to provider_url_destination_allowed_hosts
Other OTel callbacks. LITELLM_OTEL_V2=true moves every OTel callback on the proxy to V2, except logfireYour otel, Arize, Phoenix and similar exports change tooCheck them against the general V2 migration guide before you set the flag
Self-hosted servers. V2 exports to /api/public/otel/v1/tracesLangfuse v2 servers return HTTP 404Upgrade the server first. The SDK callback has used the same endpoint since v1.104.0, so a server that works with your current setup on that release or newer is fine

Metadata fields also change shape. See Field changes before you rely on dashboards, filters or masking.

Migrate​

1. Prepare​

Upgrade the proxy. Since v1.109.0 is the minimum this guide assumes, since it is the first release where key and team projects work without proxy-wide Langfuse keys.

Record Langfuse ingestion for a fixed sample of requests on the SDK callback, so you have a baseline to compare against. Then save your current callbacks, success_callback and failure_callback config and every stored key and team langfuse entry (GET /team/<team-id>/callback, GET /key/info). You need these to roll back.

2. Switch the proxy callback​

Replace langfuse with langfuse_otel. Remove langfuse from callbacks, success_callback and failure_callback, because running both callbacks logs every request twice.

litellm_settings:
callbacks: ["langfuse_otel"]
export LITELLM_OTEL_V2=true
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_HOST="https://cloud.langfuse.com" # your region or self-hosted URL
export LITELLM_OTEL_LANGFUSE_SPAN_SCOPE=llm_only
export LITELLM_OTEL_LANGFUSE_DESTINATION_SPAN_SCOPE=llm_only # key and team projects
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=span_only

Restart the proxy. Spell the scope values exactly as llm_only or full. An invalid LITELLM_OTEL_LANGFUSE_SPAN_SCOPE stops every V2 callback from loading, and the presets quietly fall back to the older OTel integration.

If you only want traces in key and team projects, with no proxy-wide Langfuse project, leave out LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY and the callbacks line, and keep LITELLM_OTEL_V2=true.

3. Move key and team callbacks​

Register langfuse_otel on each team that had a langfuse entry, with the same credentials, then delete the old entry.

curl -X POST 'http://localhost:4000/team/<team-id>/callback' \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"callback_name": "langfuse_otel",
"callback_type": "success",
"callback_vars": {
"langfuse_public_key": "pk-lf-...",
"langfuse_secret_key": "sk-lf-...",
"langfuse_span_scope": "llm_only",
"capture_message_content": "span_only"
}
}'

curl -X DELETE 'http://localhost:4000/team/<team-id>/callback/langfuse' \
-H "Authorization: Bearer $LITELLM_API_KEY"

For a key, replace the langfuse entry in its metadata.logging with the same object, through /key/update or the key's logging settings in the Admin UI. With LITELLM_OTEL_LANGFUSE_DESTINATION_SPAN_SCOPE set you can leave langfuse_span_scope out of each entry. Use callback_type: success. V2 picks the destination before the request has an outcome, so a success entry also receives that tenant's failed requests.

If a key or team sets langfuse_host, pass its key pair with it and allowlist the host. Your own LANGFUSE_HOST needs no entry.

litellm_settings:
provider_url_destination_allowed_hosts: ["langfuse.example.com"]

A key or team project replaces your own project for that request. To keep a copy in yours as well, set otel_tenant_destination_mode: additive under litellm_settings. See per-key and per-team credentials for the full routing rules.

4. Verify on staging​

Point staging at a separate Langfuse project and send a plain request, a streaming request, a request that fails at the provider, and a request a guardrail blocks if you use guardrails. Send the same metadata and redaction settings your apps send in production.

Open each trace's observation tree in Langfuse and count the observations in the tree, not the rows in the trace list. Under llm_only you should see one generation per provider call and nothing else, with input, output, token usage, cost, trace name, user, session and tags filled in. A guardrail block before the model call leaves nothing under llm_only. Requests from a key or team with its own callback should land in that project. Compare ingestion for your sample against the baseline from step 1.

5. Roll out​

Roll out in stages. Watch the proxy logs for exporter errors, where a 404 means the server has no OTLP endpoint and a 401 means the wrong key pair or region, and watch Langfuse ingestion. Update dashboards and saved filters using Field changes.

Roll back​

Restore the saved callback config and the stored key and team langfuse entries, remove langfuse_otel, unset LITELLM_OTEL_V2 if you turned it on for this migration only, and restart. Turning off the flag while langfuse_otel is still configured does not bring back the SDK callback. It switches langfuse_otel to the older OTel integration instead. Confirm that one generation arrives through the SDK callback before you send all traffic back.

Field changes​

SDK callback fieldOn V2
trace_name, langfuse_trace_name headerUnchanged. With no name set, a full trace is named litellm-{call_type} and an llm_only trace takes the generation's name
generation_nameIgnored. Generations are named {operation} {model}, for example chat gpt-4o, where the SDK callback used litellm:{key_alias} or litellm-{call_type}. Update name filters
trace_user_id, langfuse_trace_user_id headerUnchanged, but no longer falls back to the end-user ID
session_id, langfuse_session_id headerUnchanged
tagsUnchanged. Key tags, team tags and the x-litellm-tags header are included
trace_release, trace_version, LANGFUSE_TRACING_ENVIRONMENTMapped Since v1.111.0. LANGFUSE_RELEASE is not read
trace_id, langfuse_trace_id headerCalls that send the same value will share one trace Since v1.113.0 (see trace ID with langfuse_otel). A W3C traceparent header takes precedence if both are present. The x-litellm-trace-id header does not name a trace.
existing_trace_id, update_trace_keysIgnored. V2 can't add calls to an existing trace or modify it in any way and simply logs a warning once for existing_trace_id
generation_id, parent_observation_idIgnored. The observation ID is the LiteLLM call ID, which a caller can set with the x-litellm-call-id header
trace_metadata, custom generation metadataNot passed through. Allowlist the keys you need with LITELLM_OTEL_BAGGAGE_METADATA_KEYS, see request identity
Usage cache_read_input_tokens, cache_creation_input_tokensRenamed to input_cached_tokens and input_cache_creation. Reasoning tokens move out of output into output_reasoning_tokens
mask_input, mask_output, langfuse_masking_functionIgnored. With capture on, a caller that relied on them sends its prompt. Use turn_off_message_logging with llm_only, or capture_message_content: no_content on that destination
redact_user_api_key_infoStill strips key fields from Langfuse metadata, but not the litellm.metadata.user_api_key_alias, user_api_key_user_id, user_api_key_end_user_id and user_api_key_org_id attributes V2 adds to every span
Langfuse prompt linkNot supported. Generations are no longer linked to Langfuse prompts
debug_langfuseIgnored

Keep the full trace instead​

If you want auth, database, cache and guardrail spans in Langfuse, set both scopes to full. Unset also means full, but setting it explicitly records that someone accepted the extra ingestion.

export LITELLM_OTEL_LANGFUSE_SPAN_SCOPE=full
export LITELLM_OTEL_LANGFUSE_DESTINATION_SPAN_SCOPE=full

Dashboards that counted observations no longer count LLM calls. Filter on the model-call observations, such as chat gpt-4o, for usage and cost, and use the full tree for latency and failures. Spend writes and background database polls arrive as separate traces, and requests blocked before the model call have no generation.

Redaction under full

With capture on, turn_off_message_logging redacts the generation only. The request root span (POST /v1/chat/completions) still carries the raw prompt and response, including for no-log requests, and MCP tool arguments, tool results and guardrail responses are sent unredacted. If prompts must not reach Langfuse, use llm_only. no_content under full still sends guardrail responses, so pair it with llm_only too.

For every V2 setting, see OpenTelemetry v2.