feat(core): Queue Instrumentation for Kafka#5249
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
🤖 This preview updates automatically when you update the PR. |
|
…ventions Add enableQueueTracing boolean to SentryOptions (default false) and ExternalOptions (nullable Boolean) with merge support. Add messaging.* keys to SpanDataConvention for queue instrumentation span data. Co-Authored-By: Claude <noreply@anthropic.com>
📲 Install BuildsAndroid
|
…e app Add spring-kafka dependency and a simple Kafka producer/consumer setup behind a 'kafka' Spring profile. Includes a REST endpoint to produce messages and a KafkaListener that consumes them. Kafka auto-configuration is excluded by default and only activated when the 'kafka' profile is enabled. Co-Authored-By: Claude <noreply@anthropic.com>
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>
Add SentryKafkaRecordInterceptor that creates queue.process transactions for incoming Kafka records. Forks scopes per record, extracts sentry-trace and baggage headers for distributed tracing via continueTrace, and calculates messaging.message.receive.latency from the enqueued-time header. Composes with existing RecordInterceptor via delegation. Span lifecycle is managed through success/failure callbacks. Add SentryKafkaConsumerBeanPostProcessor to register the interceptor on ConcurrentKafkaListenerContainerFactory beans. Co-Authored-By: Claude <noreply@anthropic.com>
Register SentryKafkaProducerBeanPostProcessor and SentryKafkaConsumerBeanPostProcessor when spring-kafka is on the classpath and sentry.enable-queue-tracing=true. Follows the same pattern as SentryCacheConfiguration. Co-Authored-By: Claude <noreply@anthropic.com>
Add KafkaQueueSystemTest with e2e tests for: - Producer endpoint creates queue.publish span - Consumer creates queue.process transaction - Distributed tracing (producer and consumer share same trace) - Messaging attributes on publish span and process transaction Also add produceKafkaMessage to RestTestClient and enable sentry.enable-queue-tracing in the kafka profile properties. Requires a running Kafka broker at localhost:9092 and the sample app started with --spring.profiles.active=kafka. Co-Authored-By: Claude <noreply@anthropic.com>
Force-pushing a stack branch can cause GitHub to auto-merge or auto-close other PRs in the stack. Add explicit guidance to never use --force, --force-with-lease, or amend+push on stack branches.
…sample apps Add Kafka queue tracing support to both the OTel agent and agentless Spring Boot 3 sample applications. Each sample gets a KafkaController for producing messages and a KafkaConsumer listener, activated via the 'kafka' Spring profile. Kafka auto-configuration is excluded by default and only enabled when the kafka profile is active.
…Tel is active Skip registration of SentryKafkaProducerBeanPostProcessor and SentryKafkaConsumerBeanPostProcessor when a Sentry OpenTelemetry integration (agent or agentless) is on the classpath. OpenTelemetry provides its own Kafka instrumentation, so Sentry's would create duplicate spans.
Add auto.queue.spring_jakarta.kafka.producer and auto.queue.spring_jakarta.kafka.consumer to the ignored span origins when running with OTel agent or agentless-spring. Prevents duplicate spans when both Sentry and OTel Kafka instrumentation are active.
…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>
…strumentation-consumer
…rning log Update SentryKafkaRecordInterceptor and its test to reference SentryProducerInterceptor instead of the removed SentryKafkaProducerWrapper. Add a warning log in SentryKafkaConsumerBeanPostProcessor when reflection fails to read the existing RecordInterceptor, so users know their custom interceptor may not be chained. Co-Authored-By: Claude <noreply@anthropic.com>
…strumentation-autoconfig
…instrumentation-e2e
…entation-otel-samples
…-instrumentation-otel-dedup
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>
…strumentation-consumer
… ordering Add initForTest/close to SentryKafkaRecordInterceptorTest to fix NPE from TransactionContext constructor requiring initialized Sentry. Regenerate API file to fix alphabetical ordering of SentryProducerInterceptor entry. Co-Authored-By: Claude <noreply@anthropic.com>
…le-token fix(spring-jakarta): [Queue Instrumentation 38] Close leaked Kafka interceptor scope
…ontainer fix(test): [Queue Instrumentation 39] Remove stale Kafka container before startup
…ue-instrumentation-spring-boot-2
Simplify Kafka interceptor test delegates and rely on Kotlin type inference in Spring Kafka tests. Co-Authored-By: Claude <noreply@anthropic.com>
…ue-instrumentation-spring-boot-2
…e-instrumentation-review-changes
Initialize Sentry before each Kafka bean post-processor test and close it afterwards so logging paths do not depend on test execution order. This prevents failures when earlier tests close the SDK before these tests run. Co-Authored-By: Claude <noreply@anthropic.com>
…ue-instrumentation-spring-boot-2
…e-instrumentation-review-changes
Simplify Spring Kafka test interceptors and cover intercepting records without a consumer. Co-Authored-By: Claude <noreply@anthropic.com>
…e-instrumentation-review-changes
Initialize Sentry before installing the mocked scopes used by the capture exception parameter advice test. Close Sentry after the test so the mocked scopes do not leak into later tests. Co-Authored-By: Claude <noreply@anthropic.com>
…ring-boot-4 feat(spring): [Queue Instrumentation 40] Add Spring Boot 4 Kafka tracing
…ring-boot-2 feat(spring): [Queue Instrumentation 41] Add Spring Boot 2 Kafka tracing
…iew-changes fix(queue): [Queue Instrumentation 42] Review Changes
|
@sentry review |
|
cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c825d7e. Configure here.
| try { | ||
| return method.invoke(delegate, args); | ||
| } catch (InvocationTargetException e) { | ||
| throw e.getCause(); |
There was a problem hiding this comment.
Proxy equality is not reflexive
Low Severity
The proxy delegates equals to the underlying producer, so wrapped.equals(wrapped) evaluates against delegate.equals(proxy) and can return false. This breaks the equals contract for instrumented producers and can misbehave in collections or identity checks.
Reviewed by Cursor Bugbot for commit c825d7e. Configure here.


PR Stack (Queue Instrumentation)
Collection PR for the Queue Instrumentation stack. Squash-merge this once all stack PRs are merged.