Skip to content

feat(core): Queue Instrumentation for Kafka#5249

Open
adinauer wants to merge 168 commits intomainfrom
feat/queue-instrumentation
Open

feat(core): Queue Instrumentation for Kafka#5249
adinauer wants to merge 168 commits intomainfrom
feat/queue-instrumentation

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Mar 31, 2026

PR Stack (Queue Instrumentation)


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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (core) Queue Instrumentation by adinauer in #5249

Bug Fixes 🐛

  • (compose) NoSuchMethodError for LayoutCoordinates.localBoundingBoxOf$default on Compose touch dispatch with AGP 8.13 and minSdk < 24 by romtsn in #5302

Internal Changes 🔧

Deps

  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.25.2 to 2.25.4 by dependabot in #5311
  • Bump actions/cache from 5.0.4 to 5.0.5 by dependabot in #5310
  • Bump getsentry/craft from 2.25.2 to 2.25.4 by dependabot in #5309
  • Bump github/codeql-action from 4.35.1 to 4.35.2 by dependabot in #5308
  • Update Native SDK to v0.13.7 by github-actions in #5296

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c825d7e

…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>
@sentry
Copy link
Copy Markdown

sentry Bot commented Mar 31, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.40.0 (1) release

⚙️ sentry-android Build Distribution Settings

adinauer and others added 24 commits March 31, 2026 15:31
…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>
…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>
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>
… 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>
adinauer added 5 commits May 5, 2026 13:09
…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
adinauer and others added 13 commits May 5, 2026 13:43
Simplify Kafka interceptor test delegates and rely on Kotlin type inference in Spring Kafka tests.

Co-Authored-By: Claude <noreply@anthropic.com>
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>
Simplify Spring Kafka test interceptors and cover intercepting records without a consumer.

Co-Authored-By: Claude <noreply@anthropic.com>
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
@adinauer adinauer changed the title feat(core): Queue Instrumentation feat(core): Queue Instrumentation for Kafka May 6, 2026
@adinauer adinauer marked this pull request as ready for review May 6, 2026 05:09
@adinauer adinauer requested review from markushi and romtsn as code owners May 6, 2026 05:09
@adinauer
Copy link
Copy Markdown
Member Author

adinauer commented May 6, 2026

@sentry review

@adinauer
Copy link
Copy Markdown
Member Author

adinauer commented May 6, 2026

cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c825d7e. Configure here.

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.

3 participants