Repository navigation
Conversation
Propagators declare the carrier keys they read (CarrierKeys: names and prefixes, ASCII case-insensitive). The composite propagator passes their union to a new CarrierVisitor.forEachKeyValue overload, whose default visits every key, so other carriers behave as before. The Kafka 3.8 adapter overrides it: a fetched header's key is matched from its bytes once, a declared name comes back as that name's constant, a prefix match is decoded, and anything else is skipped without decoding the key or copying the value. Core interpreters declare their own headers; ContextInterpreter adds the forwarding, user agent and client IP headers, the configured client IP header, and the trace config's header tags and baggage mapping, rebuilt when the trace config changes. Baggage, DSM and inferred-proxy declare theirs. Anything undeclared stays on all(), which disables filtering. ExtractorKeysForkedTest checks, for every style, that skipping keys outside an extractor's keys extracts the same context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
Kafka / producer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
CarrierKeys.contains(String) compared every key with regionMatches ignoring case. Keys are usually already lower case (the tracer's own constants, or names a carrier decoded), so String.equals, intrinsified and with an identity check, catches them first. Recovers the per-record cost the key filter added on Kafka records with no application headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarrierKeys.nameAscii read every byte through ByteBuffer.get and folded its case, against the union of all propagators' names. For a heap buffer it now compares the backing array's bytes exactly with each name's precomputed lower-case ASCII bytes, and only compares ignoring case if the key has an upper-case byte at all. In KafkaFetchedHeadersBenchmark this more than halves the matcher's cost: fetched headers with the accessor go from -3.6% to -8.3% against #13600 with three application headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Propagators now declare which carrier keys they read, and the Kafka 3.8+ consumer skips every other header before decoding it: an application's own headers cost neither a key decode nor a value copy. A fetched header's key is matched against the declared keys from its bytes, once; a matching name comes back as that name's constant. Extracted contexts are unchanged.
Stacked on #13600.
Motivation
Extraction decoded every header on a record, then let each propagator ignore the ones it doesn't read. Real records usually carry application headers (content type, schema id, correlation ids) next to the trace headers, and each paid a key decode, a value copy and a value decode for nothing. Profiling also showed that #13600's known-name scan cost ~5% of the consumer thread's tracer time; matching once against a length-indexed set replaces it.
Additional Notes
CarrierKeys(components/context): exact names and prefixes, matched ignoring ASCII case, from aStringor from raw key bytes.all()means "any key".Propagator.keys()defaults toall(), so a propagator that doesn't declare its keys turns filtering off rather than losing headers. The composite propagator passes the union of its propagators' keys to a newCarrierVisitor.forEachKeyValue(carrier, keys, visitor)overload, whose default visits every key: every existing carrier behaves exactly as before. Only the Kafka 3.8 adapter overrides it, in this PR.Core declares its keys:
ContextInterpreterdeclares its own headers (Datadog, W3C, B3, Haystack, X-Ray, None);ContextInterpreteradds the ones every style reads: forwarding, user agent and client IP headers (always included, since AppSec / AI Guard activation can change at run time; TODO: let them declare what they need), the configured client IP header, and the current trace config's request header tags and baggage mapping;all().Per-record cost of the caching: confirming the cached union is current walks the propagators'
keys()(reference compares and two trace-config lookups, a few ns), and the adapter's overload wraps the visitor in a lambda (16 B unless scalar-replaced).Tests:
CarrierKeysTest,CompositePropagatorKeysTest(union, caching, rebuild on change, an undeclared propagator disabling filtering);ExtractorKeysForkedTest: for every style, extraction over only the headers in the extractor's keys gives the same context as over all of them (trace headers, every shared header, a mapped header tag, baggage prefixes, application headers); a reflection check that every*_KEYheader constant in the codecs is in the keys; keys following a trace config change. Forked because other propagation tests turn on header-name logging, a JVM-wide static, which makes every extractor keep all keys;all()visits everything, Base64 mode).Numbers (with Read the composite propagator's carrier cache in place #13606, laptop Kafka macrobenchmark): consumer and enricher, 10% sampled upstream traces, 256m, v0.5, 3 reps, the in-review dense-store/TagLookup stack plus Read fetched Kafka headers without copying them first #13600, without and with this PR and Read the composite propagator's carrier cache in place #13606:
Tracer-attributed allocation per profiled consumer run fell from 24.2 to 22.0 GiB (−9%), mostly Read the composite propagator's carrier cache in place #13606's. This benchmark's records carry only trace headers, so it doesn't exercise the filtering itself.
Numbers (
KafkaFetchedHeadersBenchmark, this PR against Read fetched Kafka headers without copying them first #13600, JDK 21): filtering pays off when records carry application headers, and costs a little when they carry only trace headers:appHeaders=0(time)appHeaders=3(time)appHeaders=3(alloc)fetchedfetchedAccessor(with Read fetched Kafka headers without copying them first #13600's accessor)built(producer-built headers)Times are a local single-threaded run (±1–2%) after the two fixes below; allocation is from a multi-fork A/B on a Bits worker (which also measured −5.3% time for
fetchedAccessoratappHeaders=3before the fixes). The first version cost up to +3.9% with no application headers, for two reasons:contains(String)compared ignoring case only, even when the key was the declared name itself. It now checksequals()first (the usual case: header names are lower case).nameAsciilower-cased each byte as it compared. It now compares the key's bytes exactly with each name's precomputed ASCII bytes, and compares ignoring case only if the key has an upper-case byte.What remains (~2–3%) is spread out: about 1% is confirming the cached keys are current, and the rest is the lambda wrapper and the extra call per header. It is a trade-off: records with any application headers come out ahead.
🤖 Generated with Claude Code