Skip to content

Inject an unchanged trace's extracted x-datadog-tags as it arrived - #13662

Draft
dougqh wants to merge 2 commits into
dougqh/tracestate-lower-priority-mergefrom
dougqh/xdd-tags-passthrough
Draft

dougqh wants to merge 2 commits into
dougqh/tracestate-lower-priority-mergefrom
dougqh/xdd-tags-passthrough

Conversation

@dougqh

@dougqh dougqh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Injects a forwarded trace's extracted x-datadog-tags value as it arrived, instead of rebuilding it tag by tag, while nothing about the trace's propagation tags has changed.

  • Extraction seeds the Datadog header cache with the raw value when every member was kept as written. That means nothing was dropped (non-_dd.p keys, _dd.p.upstream_services, rejected keys), no known key repeats, there is no zero trace source and no trailing separator.
  • The seed is keyed on the starting sampling state, so any decision or other change discards it exactly as the cache already did.
  • The injection path's headerValue overload now reads that cache when there's no parent-id override, and fills it after encoding. A second injection of the same trace (several outbound calls) no longer re-encodes either.

Motivation

The header cache is per trace, and the Datadog injector called an overload that never read it. So a trace injected once, as in a Kafka consume → produce enricher (one trace per record), always paid the full encode. This is the first half of the inject "passthrough" from the Kafka per-record cost work. The second half, splicing the new parent id into the extracted tracestate, follows in a separate PR. The Kafka profile puts most of the inject cost there.

Behavior change

An unchanged forwarded trace now sends the sender's member order, which can differ from the order we encode in (for example _dd.p.tid before _dd.p.dm). The members are the same. Tests that asserted our order on unchanged traces now expect the sender's. The compound extraction golden changes in 132 of 1,274 cases, and I checked that all 132 are order-only.

Results

PropagationTagsBenchmark.extractInjectHeader (Datadog → Datadog, _dd.p.anytag=value,_dd.p.dm=934086a686-4), 2 forks × 5 iterations:

base this PR
time 0.265 ± 0.019 µs 0.236 ± 0.005 µs (−11%)
allocation 448 B/op 208 B/op (−54%)

In whole-request benchmarks the saving is below the noise:

  • HeaderPathBenchmark datadog: −144 B/op of about 7.1 KB.
  • PropagationScenariosBenchmark.intermediate: within ±90 B of about 4 KB.

End to end (Kafka enricher, 10% sampling, 5 rotated reps): a combined build with #13662 and #13664 on the 4i roll-up cuts tracer cost per record from 3.53 to 3.36 µs at 1g (+3.5% throughput) and from 4.89 to 4.70 µs at 96m (+3.2%); 4j beat 4i in 8 of 10 paired reps. The two PRs were measured together, so this is their combined effect. The consumer, which doesn't inject, is flat (2.56 vs 2.58 µs at 1g).

Additional Notes

  • XDatadogTagsPassthroughTest covers verbatim headers (including another SDK's member order), each case that must fall back to encoding, and a decision change discarding the seed.
  • XDatadogTagsPassthroughInjectionTest covers the real extract → child span → inject path with Datadog-only headers, both formats, and both with an otel member.
  • Stacked on Read only the priority and parent id from a lower-priority W3C tracestate #13650.

🤖 Generated with Claude Code

A forwarded trace whose propagation tags didn't change still had its
x-datadog-tags rebuilt tag by tag on every injection: the header cache is per
trace and the injection path never read it, so a trace injected once (one per
Kafka record) always paid the full encode.

Extraction now seeds the Datadog header cache with the raw value when every
member was kept as written: nothing dropped (non-_dd.p keys, upstream
services, rejected keys), no repeated known key, no zero trace source, no
trailing separator. The seed is keyed on the starting sampling state, so any
decision or other change discards it as before. The injection path's
headerValue overload now reads and fills that cache when there is no
parent-id override.

The forwarded header keeps the sender's member order, which may differ from
ours (for example _dd.p.tid before _dd.p.dm): the members are the same. Tests
that asserted our order for unchanged traces now expect the sender's, and the
compound extraction golden changes in 132 cases, all order-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: performance Performance related changes type: refactoring tag: ai generated Largely based on code generated by an AI or LLM labels Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.00 s 14.04 s [-1.1%; +0.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 13.02 s [-1.7%; -0.1%] (maybe better)
startup:petclinic:appsec:Agent 17.70 s 17.39 s [+0.9%; +2.7%] (maybe worse)
startup:petclinic:iast:Agent 16.88 s 17.52 s [-7.9%; +0.5%] (no difference)
startup:petclinic:profiling:Agent 17.17 s 16.72 s [-1.8%; +7.2%] (no difference)
startup:petclinic:sca:Agent 17.72 s 17.59 s [-0.5%; +2.0%] (no difference)
startup:petclinic:tracing:Agent 16.59 s 16.87 s [-2.6%; -0.7%] (maybe better)

Commit: c4210ed0 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@datadog-datadog-us1-prod

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 80.65%
• Overall Coverage: 59.89% (+0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c4210ed | Docs | Give us feedback!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant