Skip to content

Fix W3C baggage header not propagated into Kafka producer record headers#11330

Open
ls-adrian-chong wants to merge 1 commit intoDataDog:masterfrom
ls-adrian-chong:fix/kafka-baggage-propagation
Open

Fix W3C baggage header not propagated into Kafka producer record headers#11330
ls-adrian-chong wants to merge 1 commit intoDataDog:masterfrom
ls-adrian-chong:fix/kafka-baggage-propagation

Conversation

@ls-adrian-chong
Copy link
Copy Markdown

Summary

Fixes #11286

The Kafka producer instrumentation passes the active AgentSpan to defaultPropagator().inject(), but AgentSpan.get() delegates non-span context keys (like baggage) to Context.root() instead of the thread-local Context.current(). This means BaggagePropagator.inject() never finds baggage on the span and silently skips W3C baggage header 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) — Replace span with Utils.currentContext() in defaultPropagator().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) — Add currentContext() bridge method that calls Context.current() from a concrete helper class, avoiding VerifyError from static interface method calls in inlined ByteBuddy advice

Why a helper method?

Context.current() is a static method on the Context interface. When ByteBuddy inlines advice into KafkaProducer, the invokestatic on an interface type creates an invalid constant pool entry, causing VerifyError: Illegal type at constant pool entry. Routing through Utils.currentContext() (a concrete class method) avoids this.

tag: ai generated

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

W3C baggage header not propagated into Kafka producer record headers

1 participant