-
Notifications
You must be signed in to change notification settings - Fork 1.6k
KafkaMessageListenerContainer Observation Scope seems to be setup incorrectly #3686
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
Comments
Hold on. Thanks |
We see exact the same issue in our project, after updating to SpringBoot 3.4.0 (which uses Spring Kafka 3.3.0). According to the try-with-resource spec, the doInvokeRecordListener is using an "Extended try-with-resources" https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3.2 which states the following:
|
The previous logic was:
Current one is:
Which is semantically the same. What part of our new logic is losing the scope?
What do I miss, please? |
@cyberflohr The following means that when the
So, we are not sure what the issue is. It would be great if we could reproduce the issue via a simple application. |
@sobychacko @artembilan To summarize my case, but now, spring-kafka (3.3.0) I think that difference thing between before and after came from changing observation scope code. |
I debugged the KafkaMessageListenerContainer code and marked the differences in the code (see image below) |
If you need a simple application to reproduce the problem, just let me know :-) |
I don't think that this is an accurate interpretation of the spec. The resource is closed after the try block, which means that it is already closed by the time the finally block is executed or the catch block for that matter. At least that is how I read it. I had a superficial look at the micrometer codebase and saw this comment on the Scope interface here:
|
Thank you for the sample! Apparently we have to manage Will fix it shortly and test with your sample again. |
So, now it is better:
The |
…ssageListenerContainer` Fixes: spring-projects#3686 According to our investigation around the `try-with-resource`, it looks like the resource is already closed when we reach the `catch` block. * Rework `KafkaMessageListenerContainer.ListenerConsumer.doInvokeRecordListener()` to `observation.openScope()` before the `try` and close it manually in the `finally` block
…Container` Fixes: spring-projects#3686 According to our investigation around the `try-with-resource`, it looks like the resource is already closed when we reach the `catch` block. * Rework `KafkaMessageListenerContainer.ListenerConsumer.doInvokeRecordListener()` to `observation.openScope()` before the `try` and close it manually in the `finally` block * Verify `RecordInterceptor.failure()` has a scope in the `ObservationTests`
In what version(s) of Spring for Apache Kafka are you seeing this issue?
For example:
3.3.0
Describe the bug
Recently In applicaiton, Spring Kafka Version upgraded to spring-kafka 3.3.0 from spring-kafka 3.2.4
In
doInvokeRecordListener
method, when message failed and scope is closed, logging data (For example, MDC) is disappered.but In spring-kafka 3.2.4
Observaiton scope is not closed when message failed, and Logging Information is maintained
In conclusion, is it possible to roll back to the original code?
Expected behavior
i expect that logging data is maintained when message failed for logging in RecordInterceptor
The text was updated successfully, but these errors were encountered: