Skip to content

Make the trace collector the trace segment and request context - #13008

Draft
dougqh wants to merge 3 commits into
masterfrom
dougqh/collector-trace-segment
Draft

dougqh wants to merge 3 commits into
masterfrom
dougqh/collector-trace-segment

Conversation

@dougqh

@dougqh dougqh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Makes TraceCollector, which already exists once per local trace, implement TraceSegment and RequestContext. Trace-level state moves off DDSpanContext onto it:

  • the request-scoped product data for AppSec, IAST and CI Visibility;
  • the block-response function;
  • the client IP data.

The TraceSegment "top" operations now act on the collector's local root span.

TraceSegment also loses its span-relative *Current methods. Nothing called them except DDSpanContext, which used them to implement the "top" methods.

Motivation

This is the first step of the TraceSegment work (APMLP-2049): give per-trace state a per-trace home. Until now, each span either carried its own copy of the trace's request data or reached the root through getRootSpanContextOrThis(). Child spans also no longer copy the parent's request data, which skips three getData calls per child.

Shallow sizes from JOL ClassLayout.instanceSize(), JDK 17, compressed oops:

class master this PR
DDSpanContext (per span) 152 B 136 B
PendingTrace (per trace) 96 B 120 B
StreamingTraceCollector (per trace) 40 B 64 B

Net per trace: 24 − 16·N bytes for N spans. A single-span trace grows by 8 B; a 20-span trace shrinks by 296 B. This is independent of #13000.

Benchmarks

TraceShapeBenchmark. Base a7194ed640 (merge base) vs head c3b3bfb00e. Temurin 17, 3 forks, 8 threads, dense store off. Run on a Bits worker: 5 vCPUs with 38% steal, so treat timings as noisy. B/op is unaffected.

Allocation (B/op, head − base). This matches the predicted 24 − 16·N, with an extra ~16–24 B saved per trace:

children expected legacy normal newApi
1 −8 3736 → 3712 (−24) 3448 → 3424 (−24) 3448 → 3416 (−32)
5 −72 8096 → 8016 (−80) 7432 → 7344 (−88) 7424 → 7344 (−80)
20 −312 24488 → 24129 (−359) 22368 → 22032 (−336) 22352 → 22147 (−305, median fork¹)

Time (ops/µs, head vs base):

children legacy normal newApi
1 +0.8% +1.3% +0.6%²
5 −0.7% +1.6% +1.7%²
20 −0.7% +0.7% +0.2%²
  • legacy and normal are neutral at every size: every delta is within ±2% and the error bars overlap.
  • ² newApi is from a rerun with 6 forks per side, alternated one fork at a time. The first run showed −10.2% at ch=1 and −7.1% at ch=5, but some forks sat in a low mode. In the rerun no fork on either side is in that mode, and head is neutral to slightly faster at every size, within the error bars. So the first run's slowdown was a scheduling or JIT mode, not a regression.
  • ¹ In the first run, one newApi head fork at ch=20 got none of the B/op saving (forks: 22040 / 22360 / 22040). In the rerun all six head forks got it (22,368 → 22,040, −328).

Additional Notes

  • withRequestContextData is now trace-level. Data set through SpanBuilder.withRequestContextData applies to the local trace. On a span that joins an existing local trace, it only fills a slot that trace hasn't set. The only production caller is CI Visibility's TestImpl, which always starts a new local trace, so its behavior is unchanged. The Javadoc and CoreSpanBuilderTest are updated to match.
  • Before the root span registers, "top" operations on the collector do nothing, and getOrCreateMetaStructTop returns null. That window only exists while the root span's own context is being constructed, and none of the getTraceSegment() or getRequestContext() callers run then.
  • Request data is set once, by compare-and-set: the first non-null value for each slot wins.
  • Out of scope: propagation state (the root's PropagationTags, origin, and sampling) stays where it is. It moves in a follow-up.

Tests: dd-trace-core (4818 tests), dd-trace-api, dd-trace-ot, AppSec, the internal-api gateway tests, and the instrumentation-testing compile were run locally on JDK 17. Three dd-trace-core tests failed, none related to this change:

  • TracerConnectionReliabilityTest (2 tests) needs Docker.
  • PendingTraceBufferTest.testingTracerFlareDumpWithMultipleTraces failed in the full-suite runs but passes when run on its own. It looks order-dependent.

🤖 Generated with Claude Code

@dougqh dougqh added comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring comp: api Tracer public API tag: ai generated Largely based on code generated by an AI or LLM labels Oct 23, 2026
@datadog-prod-us1-3

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Oct 23, 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.83 s 14.64 s [+0.6%; +2.1%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.59 s 13.66 s [-1.1%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.79 s 17.70 s [-0.3%; +1.4%] (no difference)
startup:petclinic:iast:Agent 17.64 s 17.00 s [-0.6%; +8.2%] (no difference)
startup:petclinic:profiling:Agent 17.44 s 17.31 s [-0.3%; +1.8%] (no difference)
startup:petclinic:sca:Agent 17.84 s 17.74 s [-0.6%; +1.7%] (no difference)
startup:petclinic:tracing:Agent 16.84 s 16.93 s [-1.4%; +0.4%] (no difference)

Commit: c3b3bfb0 · 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.

dougqh and others added 3 commits November 11, 2026 20:01
TraceCollector, already one object per local trace, now implements
TraceSegment and RequestContext. Request-scoped product data (AppSec,
IAST, CI Visibility), the block response function and client IP data
move off DDSpanContext onto it, so spans no longer each carry a copy
and child spans no longer copy them from their parent.

TraceSegment drops its span-relative *Current methods, which had no
callers outside DDSpanContext's own implementation. Request context
data set through the span builder now applies to the local trace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The buffer writes out a trace untouched for 500ms, so the second dump only
saw its traces if it ran sooner. Every other registered flare reporter runs
first, which in a full test run took it past that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/collector-trace-segment branch from 2277afb to c3b3bfb Compare November 12, 2026 01:53

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: api Tracer public API comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant