feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254
Draft
adinauer wants to merge 4 commits intofeat/queue-instrumentation-samplefrom
Draft
feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254adinauer wants to merge 4 commits intofeat/queue-instrumentation-samplefrom
adinauer wants to merge 4 commits intofeat/queue-instrumentation-samplefrom
Conversation
Add SentryKafkaProducerWrapper that overrides doSend to create queue.publish spans for all KafkaTemplate send operations. Injects sentry-trace, baggage, and sentry-task-enqueued-time headers for distributed tracing and receive latency calculation. Add SentryKafkaProducerBeanPostProcessor to automatically wrap KafkaTemplate beans. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
|
This was referenced Apr 1, 2026
Sentry Build Distribution
|
8 tasks
Contributor
Performance metrics 🚀
|
This was referenced Apr 1, 2026
Merged
…oducerInterceptor Replace the KafkaTemplate subclass approach with a Kafka-native ProducerInterceptor. The BeanPostProcessor now sets the interceptor on the existing KafkaTemplate instead of replacing the bean, which preserves any custom configuration on the template. Existing customer interceptors are composed using Spring's CompositeProducerInterceptor. If reflection fails to read the existing interceptor, a warning is logged. Co-Authored-By: Claude <noreply@anthropic.com>
TransactionContext constructor requires ScopesAdapter.getOptions() to be non-null for thread checker access. Add initForTest/close to ensure Sentry is properly initialized during tests. Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Apr 10, 2026
lbloder
reviewed
Apr 17, 2026
| try { | ||
| injectHeaders(record.headers(), span); | ||
| } catch (Throwable ignored) { | ||
| // Header injection must not break the send |
Collaborator
There was a problem hiding this comment.
Do we want to have any info on the fact, that header injection failed? A log for example?
lbloder
reviewed
Apr 17, 2026
|
|
||
| final @Nullable BaggageHeader baggageHeader = tracingHeaders.getBaggageHeader(); | ||
| if (baggageHeader != null) { | ||
| headers.remove(baggageHeader.getName()); |
Collaborator
There was a problem hiding this comment.
Do we want to remove the full baggageHeader here? Would that not potentially remove baggage information from other instrumentation libraries? Ok with it if its intentional, just raising the point
Member
Author
There was a problem hiding this comment.
we should take pre-existing baggage header(s) and feed it into the generated one
8 tasks
This was referenced Apr 21, 2026
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Stack (Queue Instrumentation)
📜 Description
Add Kafka producer instrumentation to
sentry-spring-jakarta:SentryKafkaProducerWrapper— overridesdoSendto createqueue.publishspans for allKafkaTemplatesend operations. Injectssentry-trace,baggage, andsentry-task-enqueued-timeheaders for distributed tracing and receive latency calculation.SentryKafkaProducerBeanPostProcessor— automatically wrapsKafkaTemplatebeans.💡 Motivation and Context
Producer-side instrumentation is needed to create publish spans and inject trace propagation headers into Kafka messages.
💚 How did you test it?
Unit tests for
SentryKafkaProducerWrapperandSentryKafkaProducerBeanPostProcessor.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps