-
Notifications
You must be signed in to change notification settings - Fork 1.6k
propagate scope in async failures #3950
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
base: main
Are you sure you want to change the base?
propagate scope in async failures #3950
Conversation
...rc/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see the fix issued against main
.
And please, follow a DCO requirements.
bfb8f6d
to
b4be8a3
Compare
b4be8a3
to
73aeaaf
Compare
done! |
...ng-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java
Outdated
Show resolved
Hide resolved
spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
Outdated
Show resolved
Hide resolved
spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/ObservationTests.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java
Show resolved
Hide resolved
...ng-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
Outdated
Show resolved
Hide resolved
2fea4fd
to
e604802
Compare
...ng-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
Outdated
Show resolved
Hide resolved
OK. The logic is like this:
Not sure if that is a goal of your solution. |
e604802
to
03ad634
Compare
@artembilan , does it make sense what i did?
@artembilan thank you a lot for the feedback. this is exactly what i was trying to achieve! made the changes accordingly! |
...ng-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
Outdated
Show resolved
Hide resolved
...ng-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
Outdated
Show resolved
Hide resolved
addcdae
to
583a1e7
Compare
Signed-off-by: Igor Macedo Quintanilha <[email protected]>
583a1e7
to
3e9fed6
Compare
Fix trace context loss in async Kafka error handling
This PR addresses an issue where the trace context is lost when handling Kafka message failures asynchronously.
Problem
When async returns are enabled and a consumer failure occurs, the trace context from the original message is not propagated. This leads to each step of the retry/DLT flow starting a new trace instead of continuing the original one.
Example (current behavior):
• Producer → trace 1
• Consumer → trace 1, fails → message goes to retry topic
• Retry listener → trace 2, fails → message goes to DLT topic
• DLT listener → trace 3
This breaks end-to-end traceability, as each listener receives a new trace ID.
Root cause
The issue stems from the handleAsyncFailure method, which runs in a different thread but does not propagate the original Observation (trace) context associated with the failed record.
Fix
Ensure that the observation context is correctly propagated when handling async failures. This preserves the trace ID across retry and DLT flows.
🔧 Tested using version 3.3.6 so I could build and validate the JAR in a real-world project.