W3C baggage header not propagated into Kafka producer record headers
@mcculls đang làm issue này rồi.
Từ ngày 29/6/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Tracer Version(s)
1.62.0 (latest as of 2026-05-05), and all versions since baggage support was introduced (v1.33.0 / 2025-03-03)
Java Version(s)
17 (Amazon Corretto), also reproduced on Temurin 17
JVM Vendor
Amazon Corretto / Eclipse Temurin
Bug Report
The W3C baggage header is not injected into Kafka producer record headers, despite DD_TRACE_PROPAGATION_STYLE=datadog,tracecontext,baggage being configured. The BaggagePropagator is registered and works correctly for HTTP client instrumentations, but fails silently for Kafka.
What works:
ot-baggage-*headers (Datadog propagation style) — propagated correctly into Kafka- W3C
baggageheader for HTTP-to-HTTP propagation — works correctly - Baggage extraction from incoming HTTP requests — works correctly (visible as span tags)
What doesn't work:
- W3C
baggageheader injection into Kafka producer record headers
Root Cause
In KafkaProducerInstrumentation.java (ContextPropagationAdvice), the inject call passes the span as the context:
defaultPropagator().inject(span, record.headers(), setter);
BaggagePropagator.inject() calls Baggage.fromContext(context) which does context.get(BAGGAGE_KEY). But AgentSpan.get() (in AgentSpan.java:227-229) delegates non-span keys to Context.root():
default <T> T get(@Nonnull ContextKey<T> key) {
return SPAN_KEY == key ? (T) this : Context.root().get(key);
}
The Baggage object lives on Context.current() (the thread-local context), not on the span. So Baggage.fromContext(span) always returns null.
HTTP client instrumentations work because they pass Context.current() to the propagator, which includes both the span and the baggage.
The Fix
Replace span with Context.current() in the Kafka producer instrumentation:
+ import static datadog.context.Context.current;
// In ContextPropagationAdvice (both kafka-clients-0.11 and kafka-clients-3.8):
- defaultPropagator().inject(span, record.headers(), setter);
+ defaultPropagator().inject(current(), record.headers(), setter);
Proof
We built a patched agent with this fix and confirmed it works. Kafka consumer output with the patched agent:
baggage:sd-routing-key=test123,e2e-run-id=run456,
x-datadog-trace-id:11803532876627986230,
x-datadog-parent-id:5176844657287312305,
traceparent:00-4bf92f3577b34da6a3ce929d0e0e4736-47d7d8c9a6fd33b1-01,
tracestate:dd=s:1;p:47d7d8c9a6fd33b1;t.dm:-0;t.tid:4bf92f3577b34da6
Expected Behavior
When baggage is included in DD_TRACE_PROPAGATION_STYLE, the W3C baggage header should be injected into Kafka producer record headers, just as it is for HTTP client requests.
Reproduction Code
Minimal Spring Boot app with a Kafka producer:
@PostMapping("/send")
public ResponseEntity<String> send(@RequestBody String body) {
kafkaTemplate.send("test-topic", "key", body);
return ResponseEntity.ok("sent");
}
Configuration:
DD_TRACE_PROPAGATION_STYLE=datadog,tracecontext,baggage
DD_KAFKA_CLIENT_PROPAGATION_ENABLED=true
Send a request with baggage: sd-routing-key=test123 header → consume from test-topic and inspect headers → no baggage header present.
Affected Files
dd-java-agent/instrumentation/kafka/kafka-clients-0.11/src/main/java/datadog/trace/instrumentation/kafka_clients/KafkaProducerInstrumentation.java(lines 221, 243)dd-java-agent/instrumentation/kafka/kafka-clients-3.8/src/main/java17/datadog/trace/instrumentation/kafka_clients38/ProducerContextPropagationAdvice.java(lines 46, 68)
Related Issues
- #6772 — Baggage not being propagated in zio (same root cause)
- #10031 — Baggage injected via DD_TRACE_HEADER_BAGGAGE not retrievable via OTEL Baggage API (related context disconnect)
Impact
This blocks use cases where W3C baggage needs to flow through Kafka (e.g., routing keys for ephemeral environments, correlation IDs for end-to-end testing). Python's ddtrace handles this correctly with DD_KAFKA_PROPAGATION_ENABLED=true.
- Ngôn ngữ chính
- Java
- Star
- 737
- Fork
- 361
- Merge trung bình
- 3 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 173
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DataDog/dd-trace-java
-
type: feature request
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 70/100
DataDog/dd-trace-java#10245 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
DataDog/dd-trace-java#12608 ·
-
type: bug report
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
DataDog/dd-trace-java#12597 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
DataDog/dd-trace-java#12540 · 4 bình luận · 1 người được giao ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
DataDog/dd-trace-java#12480 ·
Tất cả issue của DataDog/dd-trace-java
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
inu-appcenter/memorIN-backend#288 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
frontend maui-pilot pilot-ask question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Đang mởarea/plugin
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
kestra-io/plugin-kestra#190 ·