Repository navigation
fix(trace): keep sampling priority numeric in SpanContextWrapper.fromTraceContext - #850
Conversation
…TraceContext Co-authored-by: Cursor <cursoragent@cursor.com>
…-extractor snapshot Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi @SiddhithaBhoopathy this change looks pretty straightforward and should work fine. I copied your changes into #854 to run the ci. Pending that, should be good to merge. |
|
@lucaspimentel asking since you've been working on sampling recently: would changing the type of sampling-priority (string -> number) break anything? |
There was a problem hiding this comment.
More details
Keeping sampling priorities numeric matches the context type contract and dd-trace’s propagation requirements. The completed static review found no reportable regressions across the four sampling modes.
🤖 Bits Code Review · Commit 8f15251
Yes, sampling priority values must be integers. |
What does this PR do?
Keeps the sampling priority numeric in
SpanContextWrapper.fromTraceContext.fromTraceContextwas convertingsampleModeto a string ("2","-1") before passing it toDatadogSpanContext. dd-trace only injectsx-datadog-sampling-prioritywhen the priority is an integer (text_map.js_injectSamplingPriority), and only emits the_sampling_priority_v1metric when it is a number (span_format.js). Because child spans share the parent's_samplingobject and the priority sampler skips contexts that already have a priority, the string sticks for the whole trace and the sampling decision is dropped downstream.Motivation
Escalation SLES-3080: an API Gateway custom authorizer's sampling decision is not preserved by the integration Lambda. With no Datadog/W3C headers on the request, the authorizer falls back to X-Ray (
USER_KEEP/USER_REJECT), injects_datadogwithoutx-datadog-sampling-priority, and the integration Lambda (extract orderdatadog,tracecontext) re-samples independently. The customer confirmed that normalizing the priority to a number in the authorizer restores the header and preserves the upstream decision in all keep/reject × success/error cases.Testing Guidelines
fromTraceContextproduces an integer priority forUSER_KEEP,USER_REJECT,AUTO_KEEPandAUTO_REJECT.span-context-wrapper.spec.ts,xray-service.spec.ts,custom.spec.ts,extractor.spec.ts,sns.spec.ts,sqs.spec.ts,sns-sqs.spec.ts).cjs-custom-extractorintegration log snapshot: its spans now include"_sampling_priority_v1": 1, matching every other case (e.g.cjs-capture-payload). Before this fix, the custom-extractor case was the only one exported without a sampling priority, which is the bug itself showing up in the existing goldens.Additional Notes
Affected paths (all callers of
fromTraceContext):XrayService.extract)AWSTraceHeaderwith Datadog-injected IDs (XrayService.extraceDDContextFromAWSTraceHeader)CustomTraceExtractor)Regression introduced in #429 (W3C support). The
TraceContext.sampleModetype and thesampleMode(): numbergetter already expect a number.Types of Changes
Check all that apply