Repository navigation
fix(otel): send the Langfuse environment, release and version on OTel v2 - #51385
Conversation
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
[Medium impact] The PR appears safe to merge, with no outstanding findings. SummaryAdds 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.
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
|
bugbot run |
There was a problem hiding this comment.
✅ 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.
) * 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>
Relevant issues
Fixes LIT-10174. Fixes #47898.
Problem
With
LITELLM_OTEL_V2on,langfuse_oteltraces land in Langfuse environmentdefaultwith no release or version:LANGFUSE_TRACING_ENVIRONMENTis ignored on the proxy's own Langfuse export.langfuse_environmentis ignored on its own Langfuse destination when the proxy also hasLANGFUSE_PUBLIC_KEY/LANGFUSE_SECRET_KEY.trace_release/trace_versionon the request are dropped.Fix
presets/langfuse.py,plumbing/providers.pylangfuse.environmentfromLANGFUSE_TRACING_ENVIRONMENTto its own copy of each span (newExporterSpec.resource_attributes)presets/destinations.pymodel/trace_controls.py,mappers/langfuse.pylangfuse.release/langfuse.versionon the root and model spans, next to name, user, session and tagsThe 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_environmentin a request body stays rejected.langfuse_environmentwithout Langfuse credentials of its own does not relabel the proxy's traces.langfuse.release/langfuse.versionon 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_V2on. Nothing changes with it off.LANGFUSE_TRACING_ENVIRONMENTset: its Langfuse traces move to that environment. They came fromdefault, or from theOTEL_ENVIRONMENT_NAME/OTEL_RESOURCE_ATTRIBUTESvalue when one of those was also set, sincelangfuse.environmentwins overdeployment.environmentin Langfuse.defaultto the key's or team'slangfuse_environment, elseLANGFUSE_TRACING_ENVIRONMENT.trace_release,trace_versionorversionmetadata, or thelangfuse_trace_release/langfuse_trace_version/langfuse_versionheaders, now setlangfuse.release/langfuse.version.trace_versionfrom either place wins overversion.langfuse.release/langfuse.versionto every exporter that shares thelangfuse_otellogger (a generic OTLP collector, Arize), the same way it already carrieslangfuse.trace.name,langfuse.trace.tags,user.idandsession.idon main. The model span carries them to Langfuse only.ExporterSpecaccepts a new optionalresource_attributesfield. Every spec that parsed before still parses.langfuse.environmentalready in the proxy's resource (OTEL_RESOURCE_ATTRIBUTES) keeps winning overLANGFUSE_TRACING_ENVIRONMENT.langfuse_otelentry, or per-request credentials in the SDK) carries nolangfuse.environment, as on main.No migration needed.
Proof
Real self-hosted Langfuse, same request on base and head, proxy with
LANGFUSE_TRACING_ENVIRONMENT=aud-proxyandtrace_release/trace_versionmetadata.default, no release or versionaud-proxy,rel-body,ver-bodyA key with its own Langfuse keys and
langfuse_environment=aud-key, on the same proxy:Rerun: same request on base
52d1c4cd801and head6efa17798e3, real Langfuse v3.225.15config.yaml(the model upstream was a local OpenAI-compatible stub; any model works):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.Base
52d1c4cd801(release / version sent asrel-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:langfuse_otelincallbacks, proxy has Langfuse keys, plain keyfin-proxy, release, versionlangfuse_environment=fin-keyfin-key, release, versionlangfuse_environmentfin-proxy, release, versionlangfuse_environment=fin-teamfin-team, release, versioncallbacks: ["langfuse_otel"]andcallbacks: []), key withlangfuse_environment=fin-keyfin-key, version on the generationlangfuse_environmentfin-proxy, version on the generationlangfuse_environment=fin-teamfin-team, release, versionTests
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.environmentis applied per exporter via a newExporterSpec.resource_attributesfield and an_ExporterResourcespan processor that merges those attributes onto each exporter’s copy of a span. The proxy’s Langfuse exporter sets it fromLANGFUSE_TRACING_ENVIRONMENT(or key/teamlangfuse_environmenton their destination), without the old behavior that skipped this when the proxy had its own Langfuse keys. Tenant credential routing clears operatorresource_attributesso environments do not leak across accounts.langfuse.releaseandlangfuse.versionare parsed inTraceControls(trace_release,trace_version, with headers winning over body), mapped byLangfuseMapper, and stamped on the request root inLangfuseOpenTelemetryV2. 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.