fix: propagators/aws/xray: handle ALB headers missing Parent field (#8024)#8615
Open
piy3 wants to merge 1 commit intoopen-telemetry:mainfrom
Open
fix: propagators/aws/xray: handle ALB headers missing Parent field (#8024)#8615piy3 wants to merge 1 commit intoopen-telemetry:mainfrom
piy3 wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
pellared
requested changes
Mar 4, 2026
Member
There was a problem hiding this comment.
AWS ALB injects X-Amzn-Trace-Id with only a Root field when it is the first node in the request chain — no Parent span exists yet.
This seems an improper behavior of AWS ALB. How would you have a trace without a span?
CC @akats7
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8615 +/- ##
=====================================
Coverage 82.2% 82.2%
=====================================
Files 179 179
Lines 13724 13724
=====================================
Hits 11289 11289
Misses 2033 2033
Partials 402 402
🚀 New features to boost your workflow:
|
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.
AWS ALB injects X-Amzn-Trace-Id with only a Root field when it is the first node in the request chain — no Parent span exists yet.For Example :
X-Amzn-Trace-Id: Root=1-68ef9936-5f4df7cb590e654d2f659b2c
Before
The Extract() method guarded context propagation with sc.IsValid(), which is defined in the OTel SDK as:
func (sc SpanContext) IsValid() bool { return sc.HasTraceID() && sc.HasSpanID() // both must be non-zero}Since there is no Parent field in the ALB header, SpanID stays all-zeros after parsing. sc.IsValid() returned false, so the trace context was silently dropped and the downstream service started a completely new unrelated trace — breaking trace continuity.
After
Changed the guard to sc.TraceID().IsValid(), which only requires the TraceID to be non-zero:
if err == nil && sc.TraceID().IsValid() { return trace.ContextWithRemoteSpanContext(ctx, sc)}Now a header carrying only Root is accepted and the TraceID is correctly propagated into the context. The downstream service creates a root span that belongs to the existing ALB-originated trace instead of starting a new one.
Tests
Added three test cases covering:
Root only (no Parent, no Sampled)
Root + Sampled=1 (no Parent)
Root + Sampled=0 (no Parent)