feat(tracing): opt-in to record the caller's remote parent as a span link - #2450
Open
jeremypng wants to merge 2 commits into
Open
feat(tracing): opt-in to record the caller's remote parent as a span link#2450jeremypng wants to merge 2 commits into
jeremypng wants to merge 2 commits into
Conversation
…link By default the extproc continues the caller's propagated traceparent, so gateway spans join the calling application's trace. When the caller also instruments its own LLM client (e.g. OpenInference), one request produces two LLM spans in the same trace, and trace backends that group traces into projects — such as Phoenix, whose span ingestion assigns a span to the project of the existing trace row (trace IDs are globally unique there) — double-count the request's token/cost rollups in the caller's project. The gateway's own project is also left with no root spans. Add AI_GATEWAY_TRACING_REMOTE_PARENT_AS_LINK: when "true", a wrapper on the shared tracer starts every span as the root of a new trace whenever the start context carries a remote span context, recording that context as a span link plus caller.trace_id/caller.span_id attributes (some backends, including Phoenix, do not ingest OTLP links). One seam covers the generic request tracer behind every LLM endpoint and the MCP tracer. Unset, behavior is byte-for-byte unchanged. OTEL_PROPAGATORS=none is not a substitute: it also disables Inject, so the upstream provider stops receiving any traceparent and MCP _meta propagation dies, and all correlation with the caller is lost. Signed-off-by: Jeremy Sanders <23668453+jeremypng@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2450 +/- ##
==========================================
- Coverage 84.86% 84.86% -0.01%
==========================================
Files 154 155 +1
Lines 22419 22432 +13
==========================================
+ Hits 19026 19036 +10
- Misses 2237 2239 +2
- Partials 1156 1157 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nacx
approved these changes
Jul 30, 2026
nacx
enabled auto-merge (squash)
July 30, 2026 11:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2449.
By default the extproc continues the caller's propagated traceparent, so gateway spans join the calling application's trace. When the caller also instruments its own LLM client (e.g. OpenInference), one request produces two LLM spans in the same trace, and trace backends that group traces into projects — such as Phoenix, whose span ingestion assigns a span to the project of the existing trace row — double-count the request's token/cost rollups in the caller's project. The gateway's own project is also left with no root spans.
This adds
AI_GATEWAY_TRACING_REMOTE_PARENT_AS_LINK: when"true", a wrapper on the shared tracer starts every span as the root of a new trace whenever the start context carries a remote span context, recording that context as a span link pluscaller.trace_id/caller.span_idattributes (some backends, including Phoenix, do not ingest OTLP links). One seam covers the generic request tracer behind every LLM endpoint and the MCP tracer. Unset, behavior is byte-for-byte unchanged.OTEL_PROPAGATORS=noneis not a substitute: it also disables Inject, so the upstream provider stops receiving any traceparent, MCP_metapropagation dies, and all correlation with the caller is lost.Notes:
NewTracingFromEnv._metapath.site/docs/capabilities/observability/tracing.md.caller.*correlation attributes, and consumer projects stop double-counting.AI_GATEWAY_TRACING_*precedent from feat: add OpenTelemetry GenAI semantic convention for tracing #2405.