Skip to content
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

Fix spring kafka context leak when batch listener is retried #10741

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Mar 4, 2024

Resolves #10698
In later versions of spring kafka BatchInterceptor does not work correctly for retries. On retry only the intercept method is called that starts the span, but success and failure that end it are not called. This results in a context leak. This PR implements javaagent instrumentation for batch listeners without using BatchInterceptor and modifies the BatchInterceptor in library instrumentation to ignore retries. Tests are altered to also test retries.
To fix handling of retries in the library instrumentation we'll probably need to implement the tracing in a different way. Perhaps we should try wrapping the message listener instead of using BatchInterceptor and RecordInterceptor?

@laurit laurit requested a review from a team as a code owner March 4, 2024 11:35
@laurit laurit added this to the v2.2.0 milestone Mar 6, 2024
Comment on lines +328 to +329
// in latest dep tests process spans are not created for retries because spring does
// not call the success/failure methods on the BatchInterceptor for reties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this comment relevant for the javaagent instrumentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I left the comment as it is but change the condition so that this branch is only used for library instrumentation. I think ideally we should implement the library instrumentation in a different way to have the library instrumentation create correct traces for retried batches.

@laurit laurit merged commit afa3207 into open-telemetry:main Mar 12, 2024
49 checks passed
@laurit laurit deleted the spring-kafka-batch-context-leak branch March 12, 2024 12:03
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.

Spring Kafla batch listener keeps using the same traceId after exception is thrown.
3 participants