Skip to content

Add singleSpanBuilder(SpanPrototype) (dense store - part 11) - #12926

Open
dougqh wants to merge 1 commit into
dougqh/dense-sizing-hintsfrom
dougqh/prototype-fast-path
Open

dougqh wants to merge 1 commit into
dougqh/dense-sizing-hintsfrom
dougqh/prototype-fast-path

Conversation

@dougqh

@dougqh dougqh commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds singleSpanBuilder(SpanPrototype, CharSequence), so the prototype entry points mirror the plain ones (startSpan, buildSpan, singleSpanBuilder).

  • CoreTracer: with span builder reuse enabled (the default), the thread's reusable builder carries the prototype and drops it when reset for the next span. With reuse disabled, it builds a fresh multi-span builder, as singleSpanBuilder(String, CharSequence) does. Both prototype builder entry points share one seedFrom step that sets the prototype and span type.
  • AgentTracer.TracerAPI: a default method that seeds identity only (instrumentation and operation name), like buildSpan(SpanPrototype, …)'s default.
  • Seeding is unchanged: the prototype's tags are seeded at span start as before, through the interceptor, skipping any tag already set, with a standard span.kind first.

Motivation

Decorators building one span from a prototype should get the same reusable single-span builder that singleSpanBuilder(String, CharSequence) gives name-based callers.

Additional Notes

🤖 Generated with Claude Code

@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core tag: performance Performance related changes tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Oct 18, 2026
@datadog-official

datadog-official Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 0.00%
• Overall Coverage: 60.81% (+0.00%)

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

@dd-octo-sts

dd-octo-sts Bot commented Oct 18, 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.72 s 14.69 s [-0.4%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 13.60 s 13.75 s [-2.0%; -0.2%] (maybe better)
startup:petclinic:appsec:Agent 17.16 s 16.51 s [-0.2%; +8.2%] (no difference)
startup:petclinic:iast:Agent 17.03 s 17.10 s [-1.2%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 16.25 s 17.00 s [-8.7%; -0.1%] (maybe better)
startup:petclinic:sca:Agent 17.07 s 17.04 s [-0.8%; +1.1%] (no difference)
startup:petclinic:tracing:Agent 16.18 s 16.21 s [-1.0%; +0.6%] (no difference)

Commit: 4be8962c · 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/prototype-fast-path branch from 2df973a to 0a4ba91 Compare October 23, 2026 04:24
@dougqh
dougqh changed the base branch from dougqh/tagmap-split-stores to dougqh/tagmap-dense-id-store October 23, 2026 04:24
@dougqh dougqh changed the title Presize dense tag stores and seed span prototypes in bulk Presize dense tag stores and seed span prototypes in bulk (dense store - part 9) Oct 23, 2026
@bric3
bric3 added this pull request to stack #13019 October 23, 2026 16:02
@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch from 0a4ba91 to 1877eec Compare October 23, 2026 16:57
@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch from 1877eec to 162124d Compare October 26, 2026 16:08
@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch from fdc5ce3 to 893723f Compare November 2, 2026 21:56
@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch 2 times, most recently from aab8fc9 to d2ee7e5 Compare November 20, 2026 13:54
@dougqh
dougqh marked this pull request as ready for review November 23, 2026 15:20
@dougqh
dougqh requested review from a team as code owners November 23, 2026 15:20
@dougqh
dougqh requested review from PerfectSlayer, bric3, jordan-wong, sarahchen6 and zacharycmontoya and removed request for a team November 23, 2026 15:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T15:41:37.990810Z b13ce2c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dougqh

dougqh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

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

In DDSpanContext.java at line 827, removing the kind-first prepass causes http.url to be processed while span.kind is unset, so the URL interceptor applies server resource mappings instead of client mappings; the kind-first preseed must be restored before fallback tag iteration to prevent incorrect resource names.

Open Bits AI session

🤖 Bits Code Review · Commit b13ce2c

@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

The PR adds bulk prototype-tag seeding and a prototype-based single-span builder, with no findings remaining open. The update fixes client URL normalization by seeding span.kind before fallback interception, preserves an existing kind, and adds regression coverage for both stores.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b3a099a

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b13ce2c85e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@bric3
bric3 added this pull request to stack #13706 November 26, 2026 14:43
@bric3 bric3 changed the title Seed span prototypes' tags in bulk, and add singleSpanBuilder(prototype) (dense store - part 11) Bulk-seed constant tags from span prototypes (dense store - part 11) Nov 26, 2026

@bric3 bric3 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.

Could we keep the singleSpanBuilder(SpanPrototype, ...) overload here and move bulk seeding to a follow-up? The posted measurements put the bulk path within noise for today's prototypes. When bulk seeding is eligible, the server decorator still falls back on local-root spans because both the span and the prototype carry language. That takes the tag lock twice, and the retrofit benchmark omits this overlap.

For the follow-up, I'd benchmark with the production decorator prototypes and add a test that verifies custom TagInterceptor behavior is preserved.

SeedPlan plan =
new SeedPlan(
tagInterceptor,
tags.knownStore().supportsBulkSeed() && tagInterceptor.canSeedInBulk(tags),

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.

issue: CoreTracerBuilder.tagInterceptor(...) accepts a custom interceptor. Before this PR, both prototype paths called its interceptTag override for component. With dense tags and disjoint masks, the bulk copy now stores that value directly, even if the override would have consumed it. The construction fallback also skips the override for a nonstandard span.kind, including with dense tags off. How about limiting bulk seeding to the stock interceptor and keeping the previous fallback for custom interceptors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. I'll address it there, either by limiting bulk seeding to the stock interceptor or by keeping the previous path for custom ones. It'll come with a test that a custom interceptTag override still sees component and a nonstandard span.kind. In this PR, both go through the interceptor as on master.

ctx.routePut(tagEntry);
}
});
if (!seedKnownInBulk(plan, tags)) {

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.

suggestion: A local-root server span already has language from Config.getLocalRootSpanTags(). ServerDecorator adds it to its prototype too, so an eligible bulk attempt acquires knownTags, rejects the overlap, and setAllTags acquires the monitor again. webServerSpanRetrofit omits language from its prototype, so it misses this fallback. Could we defer bulk seeding until a before/after benchmark covers that path? If we keep it, can the bulk attempt and fallback share the same synchronized block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. The follow-up's benchmark will use the production decorator prototypes, ServerDecorator's language included, so it covers the local-root fallback. If bulk seeding stays, the attempt and the fallback will share one synchronized block.

* and the span kind they carry), built on first use. Racy by design: the plan is immutable, so a
* reader sees null or a complete plan, and two threads building it at once just build it twice.
*/
private Object seedPlan;

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.

suggestion: seedPlan has one slot for the last interceptor. If two tracers alternate spans from a shared decorator prototype, each switch allocates a new plan, even with dense tags disabled. How about keeping tracer-specific state out of SpanPrototype, given that bulk seeding is within noise for the current prototypes? If we retain a cache, could we test one shared prototype with two interceptor configurations? The current getter/setter and repeat-span tests both pass if the tracer builds a plan for every span.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. SpanPrototype gains no tracer-specific state here. If the follow-up keeps a cache, it'll include your test of one shared prototype under two interceptor configurations.


/** This map's known-tag store. */
@Restricted(allowedIn = {"datadog.trace.core"})
public IdStore knownStore() {

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.

suggestion: knownStore() exposes the mutable store behind SpanPrototype.tags(). IdStore.store and remove bypass the frozen TagMap check and can invalidate the cached kind and plan. How about passing the source TagMap to IdStore.seedAbsent, so the store can read it within the package? That also leaves the new IdStore.forEach overloads package-private. The only new traversal caller outside the package uses HashStore.forEach(T, BiConsumer).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. TagMap.knownStore() and the new IdStore.forEach overloads aren't in this PR. Passing the source TagMap to seedAbsent is the shape I'll use there.

}

/** Records the tracer core's seed plan for these tags; see {@link #seedPlan()}. */
@Restricted(allowedIn = {"datadog.trace.core"})

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.

todo: @Restricted requires an entry for each member in gradle/forbiddenApiFilters/instrumentation.txt. Could we add SpanPrototype#seedPlan(), SpanPrototype#seedPlan(java.lang.Object), and TagMap#knownStore() for whichever accessors remain? The two cache methods use Object, so the existing store-type bans do not cover them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. None of seedPlan(), seedPlan(Object) or knownStore() exists here, and the follow-up will add the instrumentation.txt entries for whatever remains.

DenseIdStore tombstoned = new DenseIdStore(parent);
tombstoned.remove(KnownTags.COMPONENT);
assertFalse(new DenseIdStore(null).seedAbsent(tombstoned), "tombstoned source");
}

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.

suggestion: Both sources in this test have a parent, so seedAbsent returns before it can check for a tombstone. DenseIdStore.removeLocal only creates a tombstone for an inherited value, whose bit is already in inheritedMask. How about testing a target with an inherited tag and asserting that a rejected bulk seed leaves the target untouched? That would exercise the target-side check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bulk seeding is out of this PR now (see the review reply), so this moves with it to the follow-up on dougqh/prototype-bulk-seed. The follow-up will test a target with an inherited tag and assert that a rejected bulk seed leaves it untouched.

}

@Test
void aPrototypeCachesTheSizingHintForItsOwnOperationNameOnly() {

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.

chore: SpanPrototypeSizingHintForkedTest already checks the hint for the prototype's own operation, the equivalent UTF8BytesString, a different operation, and separate entry and child lanes. Could we drop this duplicate sizing test from the construction suite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped: SpanPrototypeConstructionDenseForkedTest isn't in this PR any more, and SpanPrototypeSizingHintForkedTest covers the hints.

}

/**
* Like {@link #buildSpan(SpanPrototype, CharSequence)}, for one span only: the thread's reusable

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.

nitpick: singleSpanBuilder(String, CharSequence) reuses a builder when SPAN_BUILDER_REUSE_ENABLED is true. Could we qualify the Javadoc here so it also describes the configuration that creates a fresh builder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4be8962: the Javadoc now covers both reuse enabled (the default) and disabled.

public void webServerSpanRetrofit() {
AgentSpan span = tracer.startSpan(INSTRUMENTATION_NAME, SERVER_OPERATION_NAME);
span.applyOverwriting(webProto);
span.setTag(Tags.HTTP_METHOD, HTTP_METHOD_VALUE);

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.

nitpick: Could we static-import the tag constants repeated in the new benchmark methods? That follows the repository's import convention and keeps the tag sets easier to scan.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4be8962: SpanCreationBenchmark static-imports its Tags constants throughout, not only in the new arm, so the file stays consistent.

@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch from b3a099a to 91d90ce Compare November 30, 2026 14:13

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

Prototype seeding can bypass custom TagInterceptor overrides, changing tag consumption or rewriting. Nonstandard span kinds also bypass custom interception in the construction fallback with dense storage disabled.

Open Bits AI session

🤖 Bits Code Review · Commit 91d90ce

SeedPlan plan =
new SeedPlan(
tagInterceptor,
tags.knownStore().supportsBulkSeed() && tagInterceptor.canSeedInBulk(tags),

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.

P2 Preserve custom interceptor overrides during prototype seeding

A custom interceptor supplied through CoreTracerBuilder.tagInterceptor can override interceptTag(DDSpanContext, EntryReader) to consume or rewrite component. With dense storage and disjoint masks, this eligibility check permits copying component directly, bypassing that override during construction and applyOverwriting. The construction fallback also directly inserts nonstandard span.kind values that previously reached the override, even with dense storage disabled. Restrict bulk seeding to the stock interceptor and preserve interception of nonstandard kinds in the fallback; both paths need correction.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Seeds the thread's reusable builder from a prototype, like
buildSpan(prototype), for a span that's built once. With builder reuse
disabled it builds a fresh multi-span builder. The prototype's tags are
seeded as before, through the interceptor, with a standard span.kind
first.

Bulk seeding moves to a follow-up (branch dougqh/prototype-bulk-seed):
it measured within noise for today's prototypes, and it needs a custom
TagInterceptor test and production decorator prototypes in its
benchmark first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/prototype-fast-path branch from 91d90ce to 4be8962 Compare November 30, 2026 19:13
@dougqh dougqh changed the title Bulk-seed constant tags from span prototypes (dense store - part 11) Add singleSpanBuilder(SpanPrototype) (dense store - part 11) Nov 30, 2026
@dougqh

dougqh commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@bric3 Split as you suggested. This PR now only adds singleSpanBuilder(SpanPrototype, …) and leaves tag seeding exactly as on master (through the interceptor, with a standard span.kind first). Bulk seeding is on branch dougqh/prototype-bulk-seed for a follow-up, which will benchmark with the production decorator prototypes and test that custom TagInterceptor behavior is preserved. I've updated the title and description, and replied on each thread.

@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

The prototype overload uses the existing builder initialization and reset path, which clears prototype state before reuse. Earlier bulk-seeding concerns do not apply to the specified diff.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4be8962

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 tag: performance Performance related changes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants