Skip to content

fix: propagators/aws/xray: handle ALB headers missing Parent field (#8024)#8615

Open
piy3 wants to merge 1 commit intoopen-telemetry:mainfrom
piy3:fix/xray-propagator-alb-extraction
Open

fix: propagators/aws/xray: handle ALB headers missing Parent field (#8024)#8615
piy3 wants to merge 1 commit intoopen-telemetry:mainfrom
piy3:fix/xray-propagator-alb-extraction

Conversation

@piy3
Copy link
Copy Markdown

@piy3 piy3 commented Mar 2, 2026

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)

@piy3 piy3 requested a review from a team as a code owner March 2, 2026 17:29
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 2, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: piy3 / name: Piyush Yadav (d413eef)

@github-actions github-actions bot requested a review from akats7 March 2, 2026 17:30
@piy3 piy3 changed the title propagators/aws/xray: handle ALB headers missing Parent field (#8024) fix: propagators/aws/xray: handle ALB headers missing Parent field (#8024) Mar 2, 2026
Copy link
Copy Markdown
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.2%. Comparing base (5995ae8) to head (d413eef).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8615   +/-   ##
=====================================
  Coverage   82.2%   82.2%           
=====================================
  Files        179     179           
  Lines      13724   13724           
=====================================
  Hits       11289   11289           
  Misses      2033    2033           
  Partials     402     402           
Files with missing lines Coverage Δ
propagators/aws/xray/propagator.go 97.3% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants