[SLES-2971] fix(traces): don't propagate X-Ray Sampled=0 as a drop decision - #1325
Draft
lym953 wants to merge 1 commit into
Draft
[SLES-2971] fix(traces): don't propagate X-Ray Sampled=0 as a drop decision#1325lym953 wants to merge 1 commit into
lym953 wants to merge 1 commit into
Conversation
|
…cision When an SQS record carries no readable `_datadog` attribute, the extension falls back to the X-Ray `AWSTraceHeader` for trace context. That fallback mapped the header's `Sampled` flag straight onto a Datadog sampling priority, so a `Sampled=0` header handed the tracer an explicit priority of 0 at start-invocation and every span the tracer produced was dropped. Only honor `Sampled=1` as a keep. Leave the priority unset otherwise, so the tracer applies its own sampling decision. The trace id is still taken from the header, so X-Ray-based correlation is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lym953
force-pushed
the
yiming.luo/sles-2971-xray-sampled-priority
branch
from
August 14, 2026 00:24
0bb1180 to
00c42b5
Compare
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.
https://datadoghq.atlassian.net/browse/SLES-2971
Overview
A customer's Go Lambda dropped from ~14 spans per invocation to 2 after moving from extension
v87+DD_EXTENSION_VERSION=compatibilitytov98. The spans weren't lost in transit — the tracer built the full tree, but the whole trace was marked sampled-out.With no readable
_datadogattribute on the SQS record,extract_span_contextfalls back to the X-RayAWSTraceHeaderand mapped itsSampledflag straight onto a Datadog priority:The function is X-Ray
PassThrough, soSampled != 1yields priority0. That gets injected into thestart-invocationresponse (listener.rs:216-224), dd-trace-go adopts it for the whole local trace, and the backend drops the tracer's chunk. The extension's own inferred + invocation spans survive because a priority is only read for them whentrace_id == 0(processor.rs:1401-1419) — hence exactly 2 spans left.From the customer's flare:
Extracted trace context from inferred span0×,Returning generated span context24×, and every app span logged with_sampling_priority_v1:0in an otherwise correct tree.v87avoided this because the Go extension guards the same fallback withrootRegex = "Root=1-[0-9a-fA-F]{8}-00000000[0-9a-fA-F]{16}"(datadog-agent,carriers.go:37), rejecting AWS-generated ids and returning no headers, so the tracer sampled for itself.Fix
Only honor
Sampled=1as a keep; leave the priority unset otherwise so the tracer decides. The trace id still comes from the header, so correlation is unchanged.I did not port Go's regex: #452 appears to accept AWS-native ids deliberately (the
eventbridge_sqs_java_header_event.jsonfixture would fail that regex), so porting it would likely regress that correlation.Open questions
AWSTraceHeaderis AWS-generated rather than Datadog-planted. The flare never logs the raw value; a raw SQS record would confirm.Testing
cargo test --lib543 pass,clippy -D warningsclean,fmtcleanextract_java_sqs_header_context(fixture carriesSampled=0) and added explicitSampled=0/Sampled=1casesVerified on a live Lambda (Go, arm64,
provided.al2023, SQS trigger,TracingConfig Mode=PassThrough, us-east-2,datadog-lambda-go v1.32.0+dd-trace-go/v2 v2.9.2to match the customer). Messages sent with an AWS-nativeAWSTraceHeaderand no_datadogattribute:SampledDatadog-Extension-ARM:980_sampling_priority_v1:00_sampling_priority_v1:11_sampling_priority_v1:1The before-case reproduces the customer's signature exactly — every span including the
aws.lambdaroot stamped priority 0. Both cases logReturning generated span context, so the fallback still runs; and the tracer's trace id still equals the header's low 64 bits before and after, so X-Ray correlation is unchanged:Not re-verified: the resulting backend span count (the customer's "14 -> 2"). Traces flushed fine, but the sandbox API key's org isn't one I can query, so I could not count spans in the UI. That step follows from p0 traces being dropped rather than from a measurement here.
🤖 Generated with Claude Code