Skip to content

fix(otel): send the Langfuse environment, release and version on OTel v2 - #51385

Merged
yucheng-berri merged 6 commits into
mainfrom
litellm_langfuse_otel_v2_environment
Nov 14, 2026
Merged

yucheng-berri merged 6 commits into
mainfrom
litellm_langfuse_otel_v2_environment

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes LIT-10174. Fixes #47898.

Problem

With LITELLM_OTEL_V2 on, langfuse_otel traces land in Langfuse environment default with no release or version:

  • LANGFUSE_TRACING_ENVIRONMENT is ignored on the proxy's own Langfuse export.
  • A key's or team's langfuse_environment is ignored on its own Langfuse destination when the proxy also has LANGFUSE_PUBLIC_KEY / LANGFUSE_SECRET_KEY.
  • trace_release / trace_version on the request are dropped.

Fix

What Where How
Proxy environment presets/langfuse.py, plumbing/providers.py the proxy's Langfuse exporter adds resource attribute langfuse.environment from LANGFUSE_TRACING_ENVIRONMENT to its own copy of each span (new ExporterSpec.resource_attributes)
Key / team environment presets/destinations.py the destination's resource attribute no longer depends on whether the proxy has Langfuse keys
Release, version model/trace_controls.py, mappers/langfuse.py langfuse.release / langfuse.version on the root and model spans, next to name, user, session and tags

The environment is set per exporter, so a generic OTLP collector, the OTel metrics resource and a key's or team's non-Langfuse destination never see it. A key's or team's environment labels only that key's or team's Langfuse destination; the proxy's own export always carries the proxy's environment.

Not in this PR

  • langfuse_environment in a request body stays rejected.
  • A key or team that sets langfuse_environment without Langfuse credentials of its own does not relabel the proxy's traces.
  • On a proxy with no Langfuse keys of its own, a key's or team's Langfuse destination gets langfuse.release / langfuse.version on the model span only, as it gets name, user, session and tags on main. Langfuse fills the trace's own Release / Version from a non-root span only when that span also updates the trace (name, user, session, tags or metadata), so a request that sends release or version alone shows the version on the generation and not on the trace.

Behavior changes

All with LITELLM_OTEL_V2 on. Nothing changes with it off.

  • Proxy with Langfuse keys and LANGFUSE_TRACING_ENVIRONMENT set: its Langfuse traces move to that environment. They came from default, or from the OTEL_ENVIRONMENT_NAME / OTEL_RESOURCE_ATTRIBUTES value when one of those was also set, since langfuse.environment wins over deployment.environment in Langfuse.
  • Key / team Langfuse destination on a proxy with Langfuse keys: traces move from default to the key's or team's langfuse_environment, else LANGFUSE_TRACING_ENVIRONMENT.
  • Requests carrying trace_release, trace_version or version metadata, or the langfuse_trace_release / langfuse_trace_version / langfuse_version headers, now set langfuse.release / langfuse.version. trace_version from either place wins over version.
  • The request's root span carries langfuse.release / langfuse.version to every exporter that shares the langfuse_otel logger (a generic OTLP collector, Arize), the same way it already carries langfuse.trace.name, langfuse.trace.tags, user.id and session.id on main. The model span carries them to Langfuse only.
  • ExporterSpec accepts a new optional resource_attributes field. Every spec that parsed before still parses.
  • At a span attribute limit, release and version never push out another attribute: the model span sheds them first, and the root span takes them only when they fit.
  • A langfuse.environment already in the proxy's resource (OTEL_RESOURCE_ATTRIBUTES) keeps winning over LANGFUSE_TRACING_ENVIRONMENT.
  • An export routed to a key's own Langfuse credentials without a destination (a failure-only langfuse_otel entry, or per-request credentials in the SDK) carries no langfuse.environment, as on main.

No migration needed.

Proof

Real self-hosted Langfuse, same request on base and head, proxy with LANGFUSE_TRACING_ENVIRONMENT=aud-proxy and trace_release / trace_version metadata.

Base: default, no release or version Head: aud-proxy, rel-body, ver-body
base head

A key with its own Langfuse keys and langfuse_environment=aud-key, on the same proxy:

key

Rerun: same request on base 52d1c4cd801 and head 6efa17798e3, real Langfuse v3.225.15

config.yaml (the model upstream was a local OpenAI-compatible stub; any model works):

model_list:
  - model_name: gpt-fin
    litellm_params:
      model: openai/gpt-4o-mini
      api_base: http://127.0.0.1:26701/v1
      api_key: sk-stub
litellm_settings:
  callbacks: ["langfuse_otel"]

Env: DATABASE_URL, LITELLM_MASTER_KEY, LITELLM_SALT_KEY, LITELLM_LICENSE, LITELLM_OTEL_V2=true, OTEL_BSP_SCHEDULE_DELAY=500, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST=http://127.0.0.1:13398, LANGFUSE_TRACING_ENVIRONMENT=fin-proxy.

litellm --config config.yaml --port 26710 --num_workers 2

KEY=$(curl -s http://127.0.0.1:26710/key/generate -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -H 'Content-Type: application/json' -d '{}' | jq -r .key)

curl -s http://127.0.0.1:26710/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"model": "gpt-fin", "messages": [{"role": "user", "content": "hi"}], "metadata": {"trace_release": "rel-950038", "trace_version": "ver-950038"}}'

curl -s -u "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" "$LANGFUSE_HOST/api/public/traces?name=litellm-acompletion&limit=1" \
  | jq '.data[0] | {id, name, environment, release, version}'

Base 52d1c4cd801 (release / version sent as rel-5fa0a0 / ver-5fa0a0):

{"id": "dcbddee3ebacb8d63a6cf62252cdd240", "name": "litellm-acompletion", "environment": "default", "release": null, "version": null}

Head 6efa17798e3:

{"id": "a7bff3aef07b7b8aaa8f65cd33a6e339", "name": "litellm-acompletion", "environment": "fin-proxy", "release": "rel-950038", "version": "ver-950038"}

Head 6efa17798e3, 20 requests (chat and streaming) across the three setups, read back from Langfuse. The key or team destination has its own Langfuse keys and project:

Setup Proxy's Langfuse project Key's / team's Langfuse project
langfuse_otel in callbacks, proxy has Langfuse keys, plain key fin-proxy, release, version no trace
same proxy, key with langfuse_environment=fin-key request not exported, as on main fin-key, release, version
same proxy, key with no langfuse_environment request not exported fin-proxy, release, version
same proxy, team with langfuse_environment=fin-team request not exported fin-team, release, version
proxy without Langfuse keys (callbacks: ["langfuse_otel"] and callbacks: []), key with langfuse_environment=fin-key no trace fin-key, version on the generation
same, key with no langfuse_environment no trace fin-proxy, version on the generation
same, team with langfuse_environment=fin-team no trace fin-team, release, version
same, plain key no trace no trace

Tests

  • tests/integration/observability/test_langfuse_otel_v2_environment.py: live proxy, every span of a request names the environment on chat, responses and messages, streaming and failed calls; key and team destinations; release and version from metadata and headers.
  • tests/unit/integrations/otel/: only the proxy's Langfuse exporter gets the environment (a collector beside it does not), destination resource with and without proxy keys, trace controls, mapper.

Note

Medium Risk
Changes span export plumbing, per-tenant routing, and Langfuse attribute stamping on hot paths, which can relabel traces in Langfuse but is mostly additive and gated on OTel v2.

Overview
OTel v2 Langfuse traces now carry the correct environment on exports, plus release and version from request metadata/headers.

langfuse.environment is applied per exporter via a new ExporterSpec.resource_attributes field and an _ExporterResource span processor that merges those attributes onto each exporter’s copy of a span. The proxy’s Langfuse exporter sets it from LANGFUSE_TRACING_ENVIRONMENT (or key/team langfuse_environment on their destination), without the old behavior that skipped this when the proxy had its own Langfuse keys. Tenant credential routing clears operator resource_attributes so environments do not leak across accounts.

langfuse.release and langfuse.version are parsed in TraceControls (trace_release, trace_version, with headers winning over body), mapped by LangfuseMapper, and stamped on the request root in LangfuseOpenTelemetryV2. When the root span is at its attribute limit, release/version are dropped first so name, user, session, and tags are not displaced.

Coverage is extended with integration tests for proxy/key/team environments and release/version, plus unit tests for mapping, destinations, routing, and attribute limits.

Reviewed by Cursor Bugbot for commit 6efa177. Bugbot is set up for automated code reviews on this repo. Configure here.

@veria-ai

veria-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@codspeed

codspeed Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing litellm_langfuse_otel_v2_environment (6efa177) with main (6abacd3)

Open in CodSpeed

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/integrations/otel/plumbing/providers.py 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Summary

Adds Langfuse environment labels per exporter and carries request release and version onto root and model spans.

The latest changes add test annotations and explain import suppressions. No new issues were found.

yucheng-berri accepted sharing root-span release and version with other exporters because existing trace fields already follow that pattern and generic collectors may forward to Langfuse.

  • Langfuse exports carry the environment for their own destination.
  • Request release and version values appear on Langfuse spans.
  • The source-of-truth test keeps the same call while its arguments wrap onto separate lines.

Reviews (4) · Last reviewed commit: "test(otel): annotate the new attribute-l..." · Reviewed by Greptile

… do not fit

- the model span sheds release and version before the identity fields
- the request root takes release and version only when they fit under its attribute limit
- an exporter routed to a tenant's credentials drops the proxy's Langfuse environment
- a langfuse.environment the proxy's resource already names wins over LANGFUSE_TRACING_ENVIRONMENT
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6efa177. Configure here.

@yucheng-berri
yucheng-berri merged commit 580203c into main Nov 14, 2026
97 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_langfuse_otel_v2_environment branch November 14, 2026 19:40
yucheng-berri added a commit to BerriAI/litellm-docs that referenced this pull request Nov 15, 2026
)

* docs(langfuse): document OTel v2 release, version and environment

langfuse_otel on OpenTelemetry v2 now sets langfuse.release, langfuse.version
and langfuse.environment (BerriAI/litellm#51385). The migration guide still
listed release and version as having no V2 equivalent.

* docs(langfuse): shorten the OTel v2 release, version and environment notes

---------

Co-authored-by: yucheng-berri <293926326+yucheng-berri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OTel v2 LangfuseMapper drops langfuse.environment / release / version (parity regression from OTel v1)

2 participants