Skip to content

Freeze per-connection and per-poll span tags instead of rebuilding them (tag api - part 2) - #13141

Draft
dougqh wants to merge 13 commits into
dougqh/settagsfrom-lock-coarseningfrom
dougqh/memoized-tag-contributor
Draft

dougqh wants to merge 13 commits into
dougqh/settagsfrom-lock-coarseningfrom
dougqh/memoized-tag-contributor

Conversation

@dougqh

@dougqh dougqh commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds FrozenTags, a cached form of setTagsFrom: run a TagExtractor / TagContributor once against a source that outlives its spans, freeze the tags it writes, and apply them to each span with span.setTagsFrom(frozen) instead of re-reading the source. Two first users:

  • netty 4.1 client — peer tags (peer.hostname, peer.ipv4/ipv6, peer.port) are frozen once per connection channel (HTTP/2 streams share their parent's). Previously every request rebuilt the IP string (InetAddress.getHostAddress()) and re-resolved the hostname.
  • Kafka 0.11 / 3.8 consumer — destination, group, cluster id and bootstrap servers are frozen once per topic per poll (one-entry cache in the poll's iterator; records come out partition by partition).

Commits, in order:

  1. Move BaseDecorator.onPeerConnection's InetAddress handling into PeerAddress / PeerSocketAddress extractors (no caching yet).
  2. FrozenTags + AgentSpan.setTagsFrom(FrozenTags). On DDSpan it reuses the prototype seed plan: with the dense store, known tags that need no interception are copied in at once.
  3. netty 4.1 client freezes peer tags per connection.
  4. A partial bulk seed: frozen tags often overlap tags the span already has (an HTTP client sets peer.hostname/peer.port from the URL in onURI, then the connection's tags overwrite them). Non-overlapping tags are copied in bulk; the overlapping ones go through the interceptor, as setTag does.
  5. Kafka consumer tags frozen per topic per poll.
  6. Review fixes: replay recorded writes in order (and keep removals); no reverse DNS under the tag lock; key the netty cache on the address object.

Motivation

APMLP-2176: many tag values are constant per framework object but get rebuilt — often as new objects — on every span. Instrumentation stays simple (a plain extractor over the framework object); the core records, freezes and applies.

Behavior

No intended behavior change, including ordering and interception:

  • FrozenTags records each write (same setter, same value, in order). Applying it replays them exactly; the bulk copy of their net result is used only where it's provably the same: no write needs the interceptor (incl. split-by-tags on custom tags), and none removes a tag or sets an empty value. Tags already on the span are overwritten through the interceptor.
  • netty keeps today's double write (URL-derived peer tags, then the connection's) and its final values. The cache is keyed on the remote address object the tags were frozen from, so a channel whose address changes, or a server-accepted child channel, still gets its own address's tags.
  • BaseDecorator.onPeerConnection calls the extractors directly rather than through setTagsFrom, so a reverse DNS lookup never runs under the span's tag lock.
  • The recorder rejects getTag and span-level setters (they can't be replayed against another span).

Additional Notes

Tests

  • FrozenTagsTest, DDSpanFrozenTagsTest + DDSpanFrozenTagsDenseForkedTest (both stores; pins which path each shape takes, incl. the HTTP-client overlap shape, recorded removals, and split-by-tags write order vs. live writes), new partial-seed cases in TagStoresTest, PeerAddressTest, KafkaConsumerTagsTest.
  • netty 4.1 client (V0/V1) and Kafka 0.11/3.8 client suites pass.

Jira ticket: APMLP-2176

🤖 Generated with Claude Code

@dougqh dougqh added comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring inst: kafka Kafka instrumentation inst: netty Netty instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Oct 30, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 71.50%
• Overall Coverage: 60.82% (+0.02%)

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

@dd-octo-sts

dd-octo-sts Bot commented Oct 30, 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.04 s 13.96 s [-0.3%; +1.4%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.98 s [-1.3%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.34 s 17.22 s [-0.1%; +1.6%] (no difference)
startup:petclinic:iast:Agent 17.13 s 17.20 s [-1.3%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 16.69 s 17.04 s [-3.2%; -1.0%] (significantly better)
startup:petclinic:sca:Agent 17.26 s 17.10 s [+0.1%; +1.8%] (maybe worse)
startup:petclinic:tracing:Agent 16.32 s 16.25 s [-0.3%; +1.2%] (no difference)

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

@pr-commenter

pr-commenter Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Kafka / producer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch dougqh/settagsfrom-lock-coarsening dougqh/memoized-tag-contributor
git_commit_date 1795448085 1795448086
git_commit_sha aee925a 2692069
See matching parameters
Baseline Candidate
ci_job_date 1795449192 1795449192
ci_job_id 2289959439 2289959439
ci_pipeline_id 155765637 155765637
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-0-lcypzdb8 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-0-lcypzdb8 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce same

@pr-commenter

pr-commenter Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Kafka / consumer-benchmark

Parameters

Baseline Candidate
baseline_or_candidate baseline candidate
git_branch dougqh/settagsfrom-lock-coarsening dougqh/memoized-tag-contributor
git_commit_date 1796048105 1796048171
git_commit_sha 475ad55 d0f69ea
See matching parameters
Baseline Candidate
ci_job_date 1796049651 1796049651
ci_job_id 2310618003 2310618003
ci_pipeline_id 157000294 157000294
cpu_model Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
jdkVersion 11.0.31 11.0.31
jmhVersion 1.36 1.36
jvm /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
jvmArgs -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost *.localhost
kernel_version Linux runner-zfyrx7zua-project-304-concurrent-1-f6ml79d2 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux Linux runner-zfyrx7zua-project-304-concurrent-1-f6ml79d2 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
vmName OpenJDK 64-Bit Server VM OpenJDK 64-Bit Server VM
vmVersion 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu 11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu

Summary

Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.

See unchanged results
scenario Δ mean throughput
scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume unsure
[+2014.517op/s; +9436.279op/s] or [+0.694%; +3.251%]
scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume same
scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume same

@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from 3ddcf66 to 6377172 Compare November 11, 2026 17:07
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from 6377172 to 3ed9fd0 Compare November 11, 2026 20:09
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch 2 times, most recently from 37d5370 to ac21c6e Compare November 18, 2026 20:42
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from ac21c6e to ea5077f Compare November 18, 2026 21:02
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from ea5077f to 1e87ad8 Compare November 19, 2026 22:46
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from 1e87ad8 to 2ec71e4 Compare November 20, 2026 13:54
@bric3
bric3 added this pull request to stack #13707 November 26, 2026 15:36
dougqh and others added 13 commits November 30, 2026 09:07
When a prototype's known tags need no interception beyond span.kind and the
occupancy masks prove none can already be on the span, the dense store
appends them with two array copies and the span.kind ordinal is set
directly; otherwise tags are seeded one by one as before. The plan is
cached on the prototype. Also adds the single-span builder overload that
takes a prototype, so decorators can use the thread's reusable builder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tag-by-tag seed walked a prototype's tags in store order. In the
dense store that's slot order, so http.url could be intercepted before
span.kind and pick server path mappings for a client span. The kind is
now seeded first, as apply did before the bulk seed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SpanData is what a TagContributor or TagExtractor may read and set on a
span: the setTag overloads (by name and by id) and getTag, with the
span's tag semantics (a null value removes the tag, the interceptor
runs), plus setResourceName, setError and setMeasured. AgentSpan extends
it with covariant returns, and the contributor and extractor now take a
SpanData.

DDSpanContext is a SpanData too: its setTag family returns this. Its
setTagsFrom takes the tag lock once and hands the contributor a
HeldSpanData that lives only for that call: it forwards to new
package-private *HoldingLock variants of setTag, removeTag and getTag
(the same bodies without the synchronized), and asserts the lock is
still held. Contributor call sites are monomorphic by design, so the
wrapper should be scalar-replaced. The public setters are unchanged.

SetTagsFromBenchmark compares a jdbc span's nine tags one by one,
through a contributor and through an extractor, on a reused and a fresh
span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The batch's id-keyed CharSequence setter stored an empty value where
DDSpan.setTag removes the tag, and SpanData had no name-keyed CharSequence
setter, so those writes fell through to the Object one. Add it, and remove
on null or empty in both, as the span does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DDSpanContext implemented SpanData only for fluent returns nothing used, and
gave the interface a third implementation with a different empty-value rule.
Its setters go back to returning void, and the batch calls the context's
existing priority-taking setters. getTag and getTagHoldingLock now share one
read, so the computed tags and observable-type quirks can't drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move BaseDecorator.onPeerConnection's InetAddress / InetSocketAddress
handling into PeerAddress and PeerSocketAddress extractors, applied with
setTagsFrom so the span's tag lock is taken once per call. This is the
first step toward freezing the extracted tags once per long-lived address
instead of rebuilding them, and the new IP string, on every span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FrozenTags.of(source, extractor) records the tags an extractor or
contributor writes, once, into a frozen TagMap. span.setTagsFrom(frozen)
then applies them as if the writes were made again, without reading the
source. On DDSpan this reuses the prototype seed plan: with the dense
store, known tags that need no interception and aren't already on the
span are copied in at once; otherwise they go one at a time through the
interceptor, as setTag does.

The recorder rejects reads of the span and span-level setters, since
neither can be replayed against a different span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The client handler rebuilt peer.hostname / peer.ipv4 / peer.port from the
channel's remote address on every request, allocating a new IP string
each time. The address is fixed for the connection's life, so freeze the
tags on first use, keep them on the connection channel (HTTP/2 streams
share their parent's), and apply them with setTagsFrom(FrozenTags).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Frozen tags often overlap tags the span already has: an HTTP client sets
peer.hostname and peer.port from the URL, then the connection's peer
tags overwrite them. Falling back to tag-by-tag for the whole set made
that common shape lose the bulk copy.

Add a partial IdStore.seedAbsent that appends the source tags whose slot
bits are clear and hands the ones that may be present to the caller,
which sets them through the interceptor as setTag does. The result is
the same as the recorded writes; only the overlapping tags pay for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each consumed record's span got messaging.destination.name, kafka.group,
messaging.kafka.cluster.id and messaging.kafka.bootstrap.servers set one
by one, though all four are the same for every record of a topic in a
poll. The poll's iterator now freezes them per topic (records come out
partition by partition, so one cached topic suffices) and applies them
with setTagsFrom(FrozenTags), at the same point in onConsume as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes, keeping FrozenTags exactly equivalent to the live writes:

- FrozenTags records each write (same setter, same value) and replays
  them in order on every tag-by-tag path. Split-by-tags is last-write-
  wins, so replaying in store order could pick a different service. A
  recorded null or empty value now replays as written instead of being
  dropped, and keeps the set off the bulk path, as does a custom tag that
  split-by-tags routes.
- BaseDecorator.onPeerConnection calls the peer extractors directly:
  through setTagsFrom, the hostname's reverse DNS lookup ran under the
  span's tag lock.
- netty reads the address from the request's channel as before, shares
  the connection's frozen tags only when the parent reports the same
  address object (HTTP/2 streams, not a server channel), and refreezes
  when the address changes.
- Rename the partial seed to IdStore.seedPartial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SpanData gained setTag(String, CharSequence), so the recorder records those
writes too. Also take Restricted from datadog.contract, where master moved it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/memoized-tag-contributor branch from 2692069 to d0f69ea Compare November 30, 2026 14:20

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 inst: kafka Kafka instrumentation inst: netty Netty instrumentation 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