Skip to content

Introduce SpanContents for eager tag post-processors (dense store - part 3) - #13001

Draft
dougqh wants to merge 1 commit into
dougqh/tagmap-slot-bucketsfrom
dougqh/eager-postprocessors-span-context
Draft

dougqh wants to merge 1 commit into
dougqh/tagmap-slot-bucketsfrom
dougqh/eager-postprocessors-span-context

Conversation

@dougqh

@dougqh dougqh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Introduces SpanContents, a read/write interface over a span's tags. The eager tag post-processors now run against it instead of a TagMap.

  • SpanContents extends two facets: ReadableSpanContents (getObject, getString) and WritableSpanContents (set(tag, value), set(EntryReader)). Writes go straight to storage, with no interception.
    • The facets describe what a caller may do; they don't enforce it. Code handed one facet must not cast to the other.
    • Thread safety is left to each implementation.
  • DDSpanContext implements SpanContents. Its four methods are unsynchronized, like unsafeGetTag, because callers already hold the span's tag lock, as earlyProcessTags does.
  • TagMap implements SpanContents too, so standalone maps and tests can be passed directly.
  • The eager processors switch to EagerTagsPostProcessor, which takes a SpanContents. They are PeerServiceCalculator, InternalTagsAdder and HttpEndpointPostProcessor, chained by EagerPostProcessorChain. NamingSchema.ForPeerService and EndpointResolver take the same interface.

This is the first slice: only what the eager processors need. Name and id variants, primitive setters and typed getters come as more readers and writers move over.

Motivation

The eager post-processors run on the application thread as a span finishes. Once a span's tags are no longer one TagMap (see the split PR in the stack), handing them a TagMap means building a view per span on the application thread. In that PR the view cost +4–5% per trace. With SpanContents, the span passes itself, and nothing is allocated.

Additional Notes

  • No behavior change, and no allocation change: the probe gives identical bytes at every step of the trace, 7,936 B per trace both before and after.
  • Tests: internal-api passes, as do the dd-trace-core post-processor, naming, DDSpanContext and DDSpan suites. EndpointResolverTest now uses TagMap instead of HashMap.

Where this is going

This PR is one step in replacing the span's single TagMap with storage that knows each tag's kind. The goal is to cut what every span allocates on the application thread, without changing behavior.

The end state

  • A tag is classified once, at the boundary. A known tag becomes an id (from the tag registry, Resolve direction-scoped OpenTelemetry names at the OpenTelemetry boundary (otlp - tag registry - phase 3) #12731), and a custom tag stays a name. Instrumentation sets known tags by id (Route intercepted tags by id instead of by name (otlp - tag registry - phase 3) #12817), so the JIT can constant-fold the routing.
  • The span owns its tag stores directly. Known tags are kept by id and custom tags by name. TagMap becomes a thin view for code outside the span.
  • Known tags live in a dense store by default. Parallel arrays of serials and values replace an Entry object per tag, and each span's store is presized from a per-operation hint. With the flag on, a web-request-shaped trace allocates about 30% less on the application thread than on master.
  • Core reads and writes a span through SpanContents, not a TagMap. That covers post-processors now and serializers later, so no TagMap view gets built for them. SpanContents starts with four methods and grows a name, id and primitive API as more readers move to it.

Later, not in this stack: cheaper read-through to parent spans, trace-level tags in a per-trace holder (TraceSegment), and primitive tag values without boxing.

The stack. This replaces #12918, split into pieces that can each be reviewed, and measured, on their own.

PR Step Allocation per 7-span trace (flag off unless noted)
#12999 A null tag value removes the tag in TagMap. This is the stack's only behavior change, kept separate on purpose. unchanged
#12992 Bucket known tags by slot in TagMap, and add TraceShapeBenchmark −96 B vs master
#13001 SpanContents for the eager post-processors unchanged
#13002 Extract TagMap's bucket mechanics into HashSupport (a pure move) unchanged
#13006 Add the id and name tag stores, not yet used unchanged
#13007 Make TagMap a facade over the two stores unchanged
#13003 Have the span own its tag stores directly +104 B (+1.3%)
#13004 Dense id store behind trace.experimental.dense.tags.enabled (off by default) flag on: −30.6%
#12926 Turn the dense store on by default, add sizing hints and bulk prototype seeding flag on: about 3% less again

Every PR after #12999 is behavior-preserving.

The pieces' allocation figures come from a deterministic per-thread probe (ThreadMXBean allocated bytes) that builds the same 7-span trace as TraceShapeBenchmark. The #12992 and #12926 figures come from TraceShapeBenchmark itself.

🤖 Generated with Claude Code

Eager post-processors run on the application thread as a span finishes.
They now take a SpanContents (read/write facets over a span's tags)
instead of a TagMap, and DDSpanContext implements SpanContents directly,
so no TagMap view needs to be built for them once span storage stops
being a single TagMap.

This is the first slice: only getObject/getString/set. Writes bypass
interception; thread safety is left to each implementation
(DDSpanContext's methods are unsynchronized, called under the tag lock).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@datadog-prod-us1-6

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

🟡 Java Benchmark SLOs — Performance SLO warning (near threshold)

Suite Status
Startup 🟡 warning

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.77 s 14.67 s [-0.1%; +1.4%] (no difference)
startup:insecure-bank:tracing:Agent 13.53 s 13.70 s [-1.9%; -0.6%] (maybe better)
startup:petclinic:appsec:Agent 17.84 s 17.66 s [+0.0%; +2.0%] (maybe worse)
startup:petclinic:iast:Agent 17.37 s 17.65 s [-2.5%; -0.7%] (maybe better)
startup:petclinic:profiling:Agent 17.04 s 17.45 s [-7.0%; +2.3%] (no difference)
startup:petclinic:sca:Agent 17.79 s 17.74 s [-0.7%; +1.3%] (no difference)
startup:petclinic:tracing:Agent 16.66 s 16.72 s [-1.2%; +0.5%] (no difference)

Commit: 195841c0 · 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 dougqh changed the title Introduce SpanContents for eager tag post-processors Introduce SpanContents for eager tag post-processors (dense store - part 3) Oct 23, 2026

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