Fix W3C baggage header not propagated into Kafka producer record headers#11330
Open
ls-adrian-chong wants to merge 1 commit intoDataDog:masterfrom
Open
Fix W3C baggage header not propagated into Kafka producer record headers#11330ls-adrian-chong wants to merge 1 commit intoDataDog:masterfrom
ls-adrian-chong wants to merge 1 commit intoDataDog:masterfrom
Conversation
Pass Context.current() instead of span to defaultPropagator().inject() in Kafka producer instrumentation so BaggagePropagator can access baggage stored on the thread-local context rather than falling back to Context.root() via AgentSpan.get(). Uses a helper method (Utils.currentContext()) to avoid VerifyError from static interface method calls in inlined ByteBuddy advice. Fixes DataDog#11286 tag: ai generated
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.
Summary
Fixes #11286
The Kafka producer instrumentation passes the active
AgentSpantodefaultPropagator().inject(), butAgentSpan.get()delegates non-span context keys (like baggage) toContext.root()instead of the thread-localContext.current(). This meansBaggagePropagator.inject()never finds baggage on the span and silently skips W3Cbaggageheader injection for Kafka.HTTP client instrumentations work correctly because they pass
Context.current()(which contains both the span and baggage) to the propagator.Changes
KafkaProducerInstrumentation.java(kafka-clients-0.11) — ReplacespanwithUtils.currentContext()indefaultPropagator().inject()calls (lines 223, 245)ProducerContextPropagationAdvice.java(kafka-clients-3.8) — Same fix for Kafka 3.8+ instrumentation (lines 46, 68)Utils.java(kafka-common) — AddcurrentContext()bridge method that callsContext.current()from a concrete helper class, avoidingVerifyErrorfrom static interface method calls in inlined ByteBuddy adviceWhy a helper method?
Context.current()is a static method on theContextinterface. When ByteBuddy inlines advice intoKafkaProducer, theinvokestaticon an interface type creates an invalid constant pool entry, causingVerifyError: Illegal type at constant pool entry. Routing throughUtils.currentContext()(a concrete class method) avoids this.tag: ai generated