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

spring-kafka: span is closed before DefaultErrorHandler's recoverer is called #12595

Open
Jasz opened this issue Nov 8, 2024 · 0 comments
Open
Labels
enhancement New feature or request needs triage New issue that requires triage

Comments

@Jasz
Copy link

Jasz commented Nov 8, 2024

Is your feature request related to a problem? Please describe.

Spring Kafka has two levels of error handling: listener error handlers and container error handlers. Unfortunately, by the time the latter is called, the scope is already closed. This is because RecordInterceptor::failure is called earlier in the error processing, and that's where opentelemetry closes the scope.

Describe the solution you'd like

The RecordInterceptor::afterRecord has been added for this reason (see this commit). Indeed, if you close the scope in afterRecord, the handler is still in the scope when it's called. Unfortunately, that method was added in spring-kafka 2.8.0, and I believe opentelemetry still supports 2.7. Additionally, afterRecord has no access to the error, so the error would have to be registered with the span in the failure method if possible.

Describe alternatives you've considered

Disabling spring-kafka instrumentation and using kafka instrumentation instead doesn't solve the issue, as TracingIterator's hasNext method is also called before the error handler.

A workaround is to take the traceparent header from the record in the error handler, and start the span manually.

Additional context

No response

@Jasz Jasz added enhancement New feature or request needs triage New issue that requires triage labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New issue that requires triage
Projects
None yet
Development

No branches or pull requests

1 participant