Skip to content

Kafka ProducerRecord may end up with duplicated trace headers #3786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GFriedrich opened this issue Mar 7, 2025 · 1 comment · Fixed by #3789
Closed

Kafka ProducerRecord may end up with duplicated trace headers #3786

GFriedrich opened this issue Mar 7, 2025 · 1 comment · Fixed by #3789

Comments

@GFriedrich
Copy link

GFriedrich commented Mar 7, 2025

In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.2.* up to the latest 3.3.*

Describe the bug
I found a bit of a weird behaviour when enabling the observation on Spring Integrations and the Spring Kafka binder.
In this case the Spring Integration already adds a traceparent header (e.g. when using W3C traces) to the internal Message but later on the Spring Kafka binder will also add another traceparent header.

To Reproduce
Steps to reproduce the behavior:

  • Enable the observation for Spring Integrations via spring.integration.management.observation-patterns
  • Enable Spring Kafka binder observations via spring.cloud.stream.kafka.binder.enable-observation
  • Send a message to a StreamBridge
  • See that the produced record on Kafka has two traceparent headers

Expected behavior
There should be just one traceparent header on a produced record.

Sample
see spring-cloud/spring-cloud-stream#3095 (comment)

Additional info
This issue originates from spring-cloud/spring-cloud-stream#3095 but it was suggested in the issue over there that the underlying problem should be fixed in the Spring Kafka library instead.

@artembilan
Copy link
Member

@sobychacko ,

let me know if you'd like to discuss this.

sobychacko added a commit to sobychacko/spring-kafka that referenced this issue Mar 13, 2025
…header

Fixes: spring-projects#3786
Issue link: spring-projects#3786

When tracing is enabled, the KafkaRecordSenderContext was adding a new
traceparent header without removing existing ones, resulting in multiple
traceparent headers in the same record. This commit fixes the issue by
Updating KafkaRecordSenderContext to remove existing traceparent headers
before adding new ones.

**Auto-cherry-pick to `3.3.x` & `3.2.x`**

Signed-off-by: Soby Chacko <[email protected]>
@sobychacko sobychacko added this to the 4.0.0-M1 milestone Mar 13, 2025
artembilan pushed a commit that referenced this issue Mar 14, 2025
Fixes: #3786
Issue link: #3786

When tracing is enabled, the KafkaRecordSenderContext was adding a new
trace header without removing existing ones, resulting in multiple
headers in the same record. This commit fixes the issue by
Updating KafkaRecordSenderContext to remove existing trace  headers
before adding new ones.

**Auto-cherry-pick to `3.2.x`**

# Conflicts:
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
artembilan pushed a commit that referenced this issue Mar 14, 2025
Fixes: #3786
Issue link: #3786

When tracing is enabled, the KafkaRecordSenderContext was adding a new
trace header without removing existing ones, resulting in multiple
headers in the same record. This commit fixes the issue by
Updating KafkaRecordSenderContext to remove existing trace  headers
before adding new ones.

# Conflicts:
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants