Skip to content

Have the span own its tag stores directly (dense store - part 7) - #13003

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 12 commits into
masterfrom
dougqh/tagmap-split-known-custom
Nov 17, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 12 commits into
masterfrom
dougqh/tagmap-split-known-custom

Conversation

@dougqh

@dougqh dougqh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

DDSpanContext owns its tag stores directly, instead of one TagMap:

  • Known tags go in an IdStore, which is also the span's tag lock.
  • Custom tags go in a HashStore, borrowed read-only from the read-through parent until the span's first custom write.

Each write is routed to the store that holds the tag. A name is resolved once and routed, and a write by id goes straight to the id store.

  • The eager post-processors already read and write the span through TagStore (Introduce TagStore for eager tag post-processors (dense store - part 3) #13001), so they need no TagMap.
  • The lazy post-processors and the serializer still take a TagMap. The span builds a view over its stores once, at serialization, and caches it. That costs about 32 B per span until they move to TagStore.
  • TagMap.Internals is gone, since the stores are now the direct path. The forbidden-API entry for it goes too.
  • The constructors drop the unused tagsSize parameter, which is why many tests change by one line.

Motivation

This is the last of three PRs that replace the span's single TagMap with two stores split by tag kind. The stores and the TagMap facade are in the two PRs below this one. Here, the span stops going through TagMap for its own reads and writes. That gives the dense store (#13004) a place as the known-tag half.

Additional Notes

Allocation, 7-span web-request trace, application thread only (JDK 25, per-thread allocated bytes, TraceShapeBenchmark's shapes):

arm master (base) this PR
legacy: every tag by name 8,104 B 7,992 B (−112 B, −1.4%)
normal: the calls today's decorators make 7,432 B 7,320 B (−112 B, −1.5%)
newApi: prototype at construction, tags by id 7,432 B 7,320 B (−112 B, −1.5%)
  • 16 B less per span. That's consistent with the span no longer holding a TagMap object of its own (about 24 B) while gaining three fields in DDSpanContext (about 8 B).
  • A first custom tag costs the same 160 B before and after, so creating the span's custom HashStore adds nothing over the old path.
  • Not counted: the tag view built at serialization (about 32 B per span), because it runs on the writer thread.

Tests: internal-api and dd-trace-core pass. The only failures are the two TracerConnectionReliabilityTest cases, which need Docker.

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

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 (merged) A null tag value removes the tag in TagMap. This is the stack's only behavior change, kept separate on purpose. unchanged
#12992 (merged) Bucket known tags by slot in TagMap, and add TraceShapeBenchmark −96 B vs master
#13001 (merged) TagStore for the eager post-processors unchanged
#13002 (merged) Extract TagMap's bucket mechanics into HashSupport (a pure move) unchanged
#13006 (merged) Add the id and name tag stores, not yet used unchanged
#13007 (merged) Make TagMap a facade over the two stores unchanged
#13003 Have the span own its tag stores directly −112 B (−1.5%)
#13004 Dense id store behind trace.experimental.dense.tags.enabled (off by default) flag on: −21% (decorator calls) to −31% (tags by name)
#12926 Turn the dense store on by default, add sizing hints and bulk prototype seeding flag on: −26% to −33% vs master, about 6% less than #13004

Every PR after #12999 is behavior-preserving.

The #13003, #13004 and #12926 figures were re-measured on 2026-11-03, after #13006 and #13007 merged, with a deterministic per-thread probe (ThreadMXBean allocated bytes, JDK 25) that builds TraceShapeBenchmark's 7-span trace and, like serialization, feeds each span's size back into the sizing hints. The #12992 figure comes from TraceShapeBenchmark itself.

🤖 Generated with Claude Code

@datadog-official

datadog-official Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 93.47%
• Overall Coverage: 60.37% (+0.02%)

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

@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.02 s 14.02 s [-0.7%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.93 s 13.01 s [-1.4%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.14 s 17.06 s [-0.6%; +1.5%] (no difference)
startup:petclinic:iast:Agent 17.00 s 17.10 s [-1.5%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.17 s 16.86 s [-8.4%; +0.1%] (no difference)
startup:petclinic:sca:Agent 16.70 s 16.98 s [-6.2%; +2.9%] (no difference)
startup:petclinic:tracing:Agent 16.17 s 16.40 s [-2.3%; -0.5%] (maybe better)

Commit: 0c5f591d · 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 force-pushed the dougqh/tagmap-split-known-custom branch from c6d9c8c to 074d3db Compare October 23, 2026 04:14
@dougqh dougqh changed the title Split a span's tags into known and custom stores it owns Have the span own its tag stores directly Oct 23, 2026
@dougqh
dougqh changed the base branch from dougqh/tagmap-hash-support to dougqh/tagmap-store-facade October 23, 2026 04:14
@dougqh dougqh changed the title Have the span own its tag stores directly Have the span own its tag stores directly (dense store - part 7) Oct 23, 2026
@bric3
bric3 added this pull request to stack #13019 October 23, 2026 16:02
@dougqh
dougqh force-pushed the dougqh/tagmap-split-known-custom branch from 074d3db to 0696fab Compare October 23, 2026 16:57
@dougqh
dougqh force-pushed the dougqh/tagmap-split-known-custom branch from 0696fab to 0d8077c Compare October 26, 2026 15:04
@dougqh
dougqh force-pushed the dougqh/tagmap-split-known-custom branch from 5920fe6 to b2616d7 Compare November 2, 2026 21:53
@dougqh
dougqh force-pushed the dougqh/tagmap-split-known-custom branch from b2616d7 to bb4ef29 Compare November 3, 2026 16:05
@dougqh
dougqh marked this pull request as ready for review November 3, 2026 16:40
@dougqh
dougqh requested a review from a team as a code owner November 3, 2026 16:40
dougqh and others added 2 commits November 6, 2026 12:37
DDSpanContext holds its IdStore (also its tag lock) and its HashStore
instead of one TagMap, and routes each write to the store that holds the
tag: a name is resolved once and routed, and a write by id goes straight
to the id store. The custom store is borrowed read-only from the
read-through parent until the span's first custom write.

The eager post-processors already read and write the span through
TagStore. The lazy post-processors and the serializer still take a
TagMap: the span builds a view over its stores once, at serialization,
and caches it (about 32 B per span until they move to TagStore).

TagMap.Internals, the core's trusted side door, is gone: the stores are
the direct path. The constructors drop the unused tagsSize parameter.

Allocation, 7-span web-request trace: +104 B (+1.3%), from the new
DDSpanContext fields (8 B per span) and the first custom store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#13061 named an id after its tag with no _ID suffix. Rename only; the
ids are the same values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/tagmap-split-known-custom branch from ebb2581 to 96d6797 Compare November 6, 2026 17:49
dougqh and others added 4 commits November 10, 2026 09:48
setAllTags and unsafeSetTag passed null values straight to the stores, which
take none, leaving a null-valued entry: the tag still showed in getTags() and
could break serialization. TagMap.set removed the tag on null, as setTag does;
route a null to removal again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With builder-tag precedence, root spans read their trace-level tags through a
shared parent. The OTLP span writer emits only a span's own tags, so root-only
tags (process_id, runtime-id, language, profiling) dropped out of OTLP exports.
Turn the read-through off when OTLP export is on, decided once at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ough

With builder-tag precedence, root spans read their root-span tags through a
shared frozen parent. A parent is always the lowest layer, which is the same as
applying it first, but root tags used to be applied after the inbound request's
tags: a request header mapped onto a root-tag name (process_id, runtime-id,
language, ...) now overrode it. The OTLP span writer also emits only local
tags, so it lost them.

Copy root tags into root spans again, as on master. Only the merged tracer
tags, which were already applied first, stay in the read-through parent. That
also makes the OTLP-export exception unnecessary. Root spans keep about 5-7
more tags locally.

RootSpanTagsReadThroughTest becomes RootSpanTagsTest, which checks root and
child spans in both precedence modes and that root tags win over same-named
inbound tags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Static inspection identified no concrete regression in tag routing, inherited-store handling, or serialization. Runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 00a78fe

@PerfectSlayer PerfectSlayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one question about the overall design: was there a cost of having an intermediate object like TagMap?
It was nice because it holds all the logic related to tags into a dedicated class, instead of mixing it into the span context concern, which still need to be cleaned of anything other than IDs and few propagation info, so the tags should end up in DDSpan at some point.

Otherwise, the changes are quite verbose about tag. I would try to trim it down. Maybe @bric3 skill would be useful for this purpose?

Otherwise, I got this report from my tooling:
🤖 A tag can be lost between the cached view and the span (latent):

  • When it happens: during processTagsAndBaggage, the view creates its own custom store and something then calls a span setter for a custom tag.
  • What goes wrong: the span's setter drops the view, so adoptViewStores skips adopting it. The span and Metadata then end up with different custom tags.
  • Why it's latent: no post-processor calls back into span setters today, but the field Javadoc says they do. Either fix the Javadoc or make such callbacks unsupported.

dougqh and others added 4 commits November 16, 2026 07:35
setAllTags resolved each name to choose the interceptor, then stored the
tag through unsafeSetTag, which resolved it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each hid a KnownTagCodec.keyOf call, which is how setAllTags came to look
a name up twice. Callers now resolve the id themselves, so every lookup is
visible where it happens; setMetric does it before taking the lock. The
comment introducing the route methods moves to where they start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rename turned DB_POOL_NAME_NAME into the id constant, so the test's
by-name map set that tag by id, and still passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Storage section repeated what customTags and tagView say, and the
rest is now the lock's scope, why it is reentrant, and who skips it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh requested a review from PerfectSlayer November 16, 2026 12:57

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bits Code Review was unable to complete this review. View session

Please try again by commenting @datadog review.

@PerfectSlayer

Copy link
Copy Markdown
Collaborator

I received another request for review but I could not find the answer to this question nor feedback about loosing the tag. Did I miss it?

The knownTags Javadoc said post-processors call back into the span's
setters while the lock is held. None does: they write through the view.
If one did, a custom tag written through the view could miss the span,
so tagView now states the rule, and the rest of the comments are trimmed
or dropped where the code says it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh

dougqh commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@PerfectSlayer Yes, there were a few costs to TagMap. The first one being allocation (24B) which does add up.
However, the bigger costs are memory lookup indirection and tag routing. At this point, I'd mostly like to have TagMap go away, but I have to keep it for compatibility for now.

I did another simplification pass on the Javadoc & comments. I tend to err on the side of wanting more Javadoc than we'd historically had, but I can trim it if that's what others prefer.

@dougqh

dougqh commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

On the lost tag your tooling reported: good catch, and you're right that it's latent. No post-processor calls a span setter today (they all write through the view), but the Javadoc said they did, which invited exactly the path where a custom tag written through the view misses the span. Fixed in 78d5fd5: the claim is gone from the lock's Javadoc, and tagView now states that post-processors write through the view, never through the span's setters.

Reply written by Claude (Claude Code) on behalf of dougqh.

…-known-custom

Resolves #12998's package move (datadog.contract.Restricted) and adapts
master's #13452 and SpanKind changes to the split stores: the new
DDSpanContext constructor drops the removed tagsSize parameter, and
seedAbsentSpanKind checks and stores span.kind through knownTags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PerfectSlayer PerfectSlayer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to err on the side of wanting more Javadoc than we'd historically had, but I can trim it if that's what others prefer.

It’s nice to have some. Not sure of what we can call too few or too much, for both humans and agents. They found most of it should be dropped as it tends to stale and mislead them. Anyway, having implementation details, thread & null safety, etc are still useful for the readers!

@dougqh

dougqh commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-17 11:33:12 UTC ℹ️ Start processing command /merge


2026-11-17 11:33:23 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-11-17 11:42:22 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-17 12:51:02 UTC ❌ MergeQueue: The build pipeline failed for this merge request

Build pipeline has failing jobs for 0c9faa9:

⚠️ Do NOT retry failed jobs directly (why?).

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@dougqh

dougqh commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-17 13:05:37 UTC ℹ️ Start processing command /merge


2026-11-17 13:05:42 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-17 14:07:48 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b466780 into master Nov 17, 2026
685 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/tagmap-split-known-custom branch November 17, 2026 14:07
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 17, 2026
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Nov 19, 2026
Add OTel SDK span lifecycle self-monitoring metrics

When trace.otel.sdk.self.monitoring.metrics.enabled is on (with OTel
metrics, the OTLP exporter and experimental metrics), CoreTracer builds
an OTel span lifecycle recorder that reports otel.sdk.span.started, split
by otel.span.parent.origin, and otel.sdk.span.live on the bootstrap
metric registry. Otherwise it keeps a no-op. The span call sites are
wired in a follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Reuse HealthMetrics hooks for OTel span lifecycle metrics

Replace the separate SpanLifecycleMetrics recorder with an OTel
implementation of HealthMetrics, so span creation and completion keep a
single hook each, as suggested in review.

- HealthMetrics.onCreateSpan now takes the span, so the OTel sink can
  read its parent origin; TracerHealthMetrics ignores it.
- OtelSpanLifecycleMetrics becomes OtelHealthMetrics, which extends
  HealthMetrics and overrides only onCreateSpan and onFinishSpan.
- Add CompositeHealthMetrics to fan every callback out to several
  sinks. start() and close() reach every delegate, then rethrow the
  first failure with later ones suppressed.
- OtelSdkSelfMonitoring.healthMetrics(config) returns the OTel sink
  when the gate is on, otherwise null. CoreTracer is not wired here;
  the follow-up selects the sinks.
- Test that every DDSpanContext parent origin maps to a distinct
  adder, that the composite forwards every callback, and that both
  collectors pass the span to onCreateSpan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Test parent origin sync and health metrics forwarding

- Move the parent origin sync check into its own test, which also fails
  when a PARENT_ORIGIN_* constant is added without growing the
  OtelHealthMetrics arrays.
- Call every CompositeHealthMetrics method through a two-delegate
  composite and verify both delegates receive the same call.
- Cover OtelSdkSelfMonitoring.healthMetrics with the gate off and on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Trim CompositeHealthMetrics tests and rename OtelHealthMetricsTest

- Drop the composite tests that the every-method forwarding test
  already covers (declared overrides, delegate order) and the
  zero-delegate case, which CoreTracer never builds.
- Rename OtelHealthMetricsParentOriginTest to OtelHealthMetricsTest,
  the plain unit test for OtelHealthMetrics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Use static imports in OTel health metrics tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Drop tagsSize argument removed from DDSpanContext

Master removed the int tagsSize parameter from the DDSpanContext
constructors (#13003), so StreamingTraceCollectorTest no longer
compiled after rebasing onto it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Pass a stub span to onCreateSpan in HealthMetricsTest

OtelHealthMetrics dereferences the span it is given, so tests should honour
the non-null contract even though TracerHealthMetrics ignores the argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
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.

2 participants