Skip to content

Conversation

@Dogbu-cyber
Copy link

@Dogbu-cyber Dogbu-cyber commented Jan 28, 2026

APMSVLS-197 feat: Add fallback to extract trace context from event.request.headers

Overview

This PR adds 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"].

Problem

Previously, trace context from RUM was not propagated through AppSync to Lambda resolvers because the extension only checked:

  1. Trigger-specific headers (via span inferrer)
  2. event.headers (top-level event headers)
  3. Request headers (HTTP request 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.headers after 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:

  • Extraction from event.request.headers with Datadog headers
  • Extraction from event.request.headers with W3C TraceContext headers
  • Edge cases (missing headers, empty objects, invalid data)

Run tests with:

cargo test test_extract_span_context -- --nocapture

@Dogbu-cyber Dogbu-cyber changed the title David.ogbureke/extract tracecontext appsync https://datadoghq.atlassian.net/browse/APMSVLS-197 [APMSVLS-197] Add fallback to extract trace context from event.request.headers Jan 28, 2026
@Dogbu-cyber Dogbu-cyber reopened this Jan 28, 2026
@Dogbu-cyber Dogbu-cyber requested a review from Copilot January 28, 2026 18:51
Copy link
Contributor

Copilot AI left a 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.headers after primary headers extraction fails

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Dogbu-cyber Dogbu-cyber marked this pull request as draft January 28, 2026 18:54
@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch from f267045 to 5e936c4 Compare January 28, 2026 18:56
@Dogbu-cyber Dogbu-cyber marked this pull request as ready for review January 28, 2026 20:31
@Dogbu-cyber Dogbu-cyber marked this pull request as draft January 28, 2026 20:46
@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch from 5e936c4 to e4d03a2 Compare January 28, 2026 20:47
…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"].
@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch 2 times, most recently from 4043feb to 8a2baca Compare January 28, 2026 20:54
@Dogbu-cyber Dogbu-cyber marked this pull request as ready for review January 28, 2026 20:59
Copy link
Contributor

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

@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch from 96d4cb4 to b0619c2 Compare January 29, 2026 17:54
@duncanista duncanista requested a review from Copilot January 29, 2026 18:48
Copy link
Contributor

Copilot AI left a 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.

@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch from b0619c2 to 391f38c Compare January 29, 2026 18:50
Comment on lines 1075 to 1085
}

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);
}
}
}

Copy link
Contributor

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?

Copy link
Author

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..

Copy link
Contributor

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

Copy link
Author

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.

@Dogbu-cyber Dogbu-cyber force-pushed the david.ogbureke/extract-tracecontext-appsync branch from f76c2a8 to 6d228b0 Compare January 29, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants