-
Notifications
You must be signed in to change notification settings - Fork 16
[APMSVLS-197] Add fallback to extract trace context from event.request.headers #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a fallback mechanism to extract distributed tracing context from event.request.headers for AppSync integration scenarios. This enhancement eliminates the need for custom extractors when RUM injects trace context into AppSync → Lambda resolver flows.
Changes:
- Added nested extraction logic to check
event.request.headersafter primary headers extraction fails
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f267045 to
5e936c4
Compare
5e936c4 to
e4d03a2
Compare
…request.headers Add automatic trace context extraction from event.request.headers for AppSync integration scenarios. This eliminates the need for customers to use customized extractors for RUM → AppSync → Lambda resolver flows where RUM-injected trace context is nested under event["request"]["headers"].
4043feb to
8a2baca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some unit testing and show an example trace in the PR description? Just to see what were we missing
96d4cb4 to
b0619c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b0619c2 to
391f38c
Compare
| } | ||
|
|
||
| if let Some(request_obj) = payload_value.get("request") { | ||
| if let Some(request_headers) = request_obj.get("headers") { | ||
| if let Some(sc) = propagator.extract(request_headers) { | ||
| debug!("Extracted trace context from event.request.headers"); | ||
| return Some(sc); | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you decided that this should be last priority?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed there was some reason for the original order, so I didn't take a stance on where exactly it should go and added it as the last case..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on other projects which support AppSync extraction, it seems that they are considered in the same order as inferred spans would do it – I'd suggest to follow that same order
https://github.com/DataDog/datadog-lambda-js/blob/main/src/trace/context/extractor.ts#L92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That's a good point.
…or service-specific traces
f76c2a8 to
6d228b0
Compare
APMSVLS-197 feat: Add fallback to extract trace context from event.request.headers
Overview
This PR adds automatic trace context extraction from
event.request.headersfor AppSync integration scenarios. This eliminates the need for customers to use customized extractors for RUM → AppSync → Lambda resolver flows where RUM-injected trace context is nested underevent["request"]["headers"].Problem
Previously, trace context from RUM was not propagated through AppSync to Lambda resolvers because the extension only checked:
event.headers(top-level event headers)For AppSync, the trace context is nested under
event.request.headers, which was not checked, causing traces to break at the AppSync boundary.Solution
Added a fallback extraction step that checks
event.request.headersafter all other trace context sources have been attempted.Trace Examples
Before
Without this change, trace context is lost at the AppSync boundary:
Trace showing broken propagation through AppSync
Log showing the passed header value for x-datadog-trace-id does not align with the given trace_id
Flow:
RUM → AppSync → Lambda(trace ID not propagated)After
With this change, trace context is properly extracted and propagated:
Trace showing successful propagation through AppSync
Flow:
RUM → AppSync → Lambda resolver(trace continues using value within x-datadog-trace-id)Testing
Unit Tests
Added 10 unit tests covering:
event.request.headerswith Datadog headersevent.request.headerswith W3C TraceContext headersRun tests with:
cargo test test_extract_span_context -- --nocapture