Preserve local OpenTelemetry parent context - #6902
Conversation
🦋 Changeset detectedLatest commit: 5dd44a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — one new reproduction test file exercising OtelSpan parent resolution when the active OpenTelemetry context carries a local SpanContext with traceState.
OtelTracerActiveParentRepro.test.ts: directly constructsOtelSpanwithparent: Option.none()androot: falsewhile a local, non-remoteSpanContext(withtraceState) is set as the active OTel context viatrace.setSpanContext. Asserts that the context passed totracer.startSpanpreservestraceStateandisRemote: false.
The reproduction correctly isolates the gap in getOtelParent (OtelTracer.ts:526): tracer.getSpan(context) misses parents set via setSpanContext. The test assertion (deepStrictEqual on exact expected values) properly fails when the bug is present, producing [undefined, true] vs the expected ["vendor=value", false].
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — implementation fix for preserving active OTel parent context, plus a consolidated test case.
getOtelParentnow usesgetSpanContext:tracer.getSpan(context)missed parents set viasetSpanContext;getSpanContextcovers both active spans and active span contexts.- Full
Otel.SpanContextstored in annotations: newOtelParentSpanContextcontext service carries the complete parent context (includingtraceStateandisRemote) through the external span. makeSpanContextrecovers stored context: the guard clause returns the parent's fullSpanContextwhen present, with annotations-suppliedOtelTraceFlags/OtelTraceStateoverriding when provided.- Test moved into main suite: the reproduction test is now in
OtelTracer.test.tsand passes against the fixed implementation.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
Child spans lose an active parent's trace state and reconstruct a local parent as remote, affecting propagation and parent-based sampling.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Active local OpenTelemetry parents become remote without trace state
Module:
opentelemetry/OtelTracerAudit ID:
adapters-otel-8-active-parent-context-lossSeverity / confidence: high / high
What happens
Child spans lose an active parent's trace state and reconstruct a local parent as remote, affecting propagation and parent-based sampling.
Why it happens
getOtelParent converts active context to an ExternalSpan with only IDs and sampled state; makeSpanContext then infers remote solely from the ExternalSpan tag.
Expected behavior
Spans attached to active OpenTelemetry context preserve the complete parent SpanContext, including traceState and isRemote.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/opentelemetry/src/OtelTracer.ts:521-533packages/opentelemetry/src/OtelTracer.ts:536-548View problematic code at
packages/opentelemetry/src/OtelTracer.ts:521-533View exact lines on GitHub
View problematic code at
packages/opentelemetry/src/OtelTracer.ts:536-548View exact lines on GitHub
Reproduction
pnpm test --run packages/opentelemetry/test/OtelTracerActiveParentRepro.test.tsObserved failure: Observed [undefined, true] instead of trace state/local parent (1/1 failed).
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
pnpm test --run packages/opentelemetry/test/OtelTracerActiveParentRepro.test.tsAudit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715fadapters-otel-8-active-parent-context-lossCloses EFF-347