Skip to content

feat(core): Queue Instrumentation#5249

Draft
adinauer wants to merge 51 commits intomainfrom
feat/queue-instrumentation
Draft

feat(core): Queue Instrumentation#5249
adinauer wants to merge 51 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

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Queue Instrumentation ([#5249](https://github.com/getsentry/sentry-java/pull/5249))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 46225de

…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>
…tions

feat(core): [Queue Instrumentation 1] Add enableQueueTracing option and messaging span data conventions
…mple

feat(samples): [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app
…oducer

feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation
…nsumer

feat(spring-jakarta): [Queue Instrumentation 4] Add Kafka consumer instrumentation
…toconfig

feat(spring-boot-jakarta): [Queue Instrumentation 5] Add Kafka queue auto-configuration
test(samples): [Queue Instrumentation 6] Add Kafka queue system tests
…el-samples

feat(samples): [Queue Instrumentation 7] Add Kafka to Spring Boot 3 OTel sample apps
…l-dedup

fix(spring-boot-jakarta): [Queue Instrumentation 8] Disable Sentry Kafka spans when OTel is active
@github-actions
Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 303.16 ms 350.26 ms 47.10 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
5865051 319.74 ms 365.60 ms 45.86 ms
cf708bd 408.35 ms 458.98 ms 50.63 ms
b750b96 408.98 ms 480.32 ms 71.34 ms
1df7eb6 397.04 ms 429.64 ms 32.60 ms
9ea89e8 308.06 ms 358.16 ms 50.10 ms
319f256 315.96 ms 372.96 ms 57.00 ms
c8125f3 383.82 ms 441.66 ms 57.84 ms
f064536 327.04 ms 405.35 ms 78.31 ms
b3d8889 420.46 ms 453.71 ms 33.26 ms
f064536 335.52 ms 408.79 ms 73.27 ms

App size

Revision Plain With Sentry Diff
5865051 0 B 0 B 0 B
cf708bd 1.58 MiB 2.11 MiB 539.71 KiB
b750b96 1.58 MiB 2.10 MiB 533.19 KiB
1df7eb6 1.58 MiB 2.10 MiB 532.97 KiB
9ea89e8 1.58 MiB 2.28 MiB 716.23 KiB
319f256 1.58 MiB 2.19 MiB 619.79 KiB
c8125f3 1.58 MiB 2.10 MiB 532.32 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB

…eadlocal-cleanup

fix(spring-jakarta): [Queue Instrumentation 9] Clean up stale ThreadLocal context in Kafka consumer interceptor
…t-scopes

fix(spring-jakarta): [Queue Instrumentation 10] Fork root scopes and skip when OTel is active in Kafka consumer
…ducer-guard

fix(spring-jakarta): [Queue Instrumentation 11] Guard entire span lifecycle in Kafka producer interceptor
…ry-count

fix(spring-jakarta): [Queue Instrumentation 12] Add Kafka retry count attribute
…ueued-time-seconds

fix(spring-jakarta): [Queue Instrumentation 13] Align enqueue time with Python
…fka-module

ref(kafka): [Queue Instrumentation 14] Extract sentry-kafka module
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.

1 participant