Skip to content

feat(kafka): [Queue Instrumentation 17] Add manual consumer tracing helper#5312

Draft
adinauer wants to merge 5 commits intofix/queue-instrumentation-kafka-system-test-runnerfrom
feat/queue-instrumentation-kafka-consumer-tracing
Draft

feat(kafka): [Queue Instrumentation 17] Add manual consumer tracing helper#5312
adinauer wants to merge 5 commits intofix/queue-instrumentation-kafka-system-test-runnerfrom
feat/queue-instrumentation-kafka-consumer-tracing

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 20, 2026

PR Stack (Queue Instrumentation)


📜 Description

Add a manual Kafka consumer tracing helper and switch the console sample to use it.

Changes:

  • add SentryKafkaConsumerTracing.withTracing(...) for wrapping raw Kafka consumer record processing
  • preserve the original throwable from the Runnable overload
  • remove the raw Kafka consumer interceptor and its tests
  • update the console sample to process consumed records inside the manual helper
  • update the console system test to assert the manual queue.process transaction origin
  • let ignoredSpanOrigins short-circuit the raw Kafka producer interceptor before it injects tracing headers
  • have the Spring Kafka record interceptor fork root scopes through its injected IScopes dependency instead of the static Sentry API

💡 Motivation and Context

The raw consumer interceptor traced the poll boundary rather than application processing and could overlap with explicit consumer instrumentation. This PR moves Kafka consumer tracing to an explicit helper that wraps the customer callback, which matches the queue.process semantic and makes the sample clearer.

It also lets customers disable the raw producer interceptor quickly through ignoredSpanOrigins, without relying on the later no-op span path, and keeps the Spring Kafka path aligned with the raw Kafka implementation.

💚 How did you test it?

  • Ran ./gradlew :sentry-kafka:test --tests='io.sentry.kafka.SentryKafkaConsumerTracingTest'
  • Ran ./gradlew :sentry-kafka:test --tests='io.sentry.kafka.SentryKafkaProducerInterceptorTest'
  • Ran ./gradlew :sentry-spring-jakarta:test --tests='io.sentry.spring.jakarta.kafka.SentryKafkaRecordInterceptorTest'
  • Ran ./gradlew :sentry-samples:sentry-samples-console:compileJava
  • Ran ./gradlew spotlessApply apiDump
  • Ran .venv/bin/python test/system-test-runner.py test --module sentry-samples-console

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

#skip-changelog

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

adinauer and others added 3 commits April 20, 2026 13:34
…elper

Add an experimental helper for wrapping raw Kafka consumer record
processing in queue.process transactions. This exposes Kafka consumer
tracing outside interceptor-based integrations.

Capture messaging metadata and distributed tracing context in the
helper so future queue instrumentation can reuse the same behavior.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove the raw Kafka consumer interceptor from sentry-kafka and update the console sample to use the manual consumer tracing helper instead. Keep producer tracing on the interceptor path and move consumer tracing to explicit record processing.

Co-Authored-By: Claude <noreply@anthropic.com>
Print the consumed Kafka record inside the manual consumer tracing callback so the sample shows where application processing happens. Update the console system test to assert the manual queue.process transaction and its manual consumer origin.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 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).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

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

Generated by 🚫 dangerJS against 97d82f3

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 20, 2026

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

Short-circuit the raw Kafka producer interceptor when its trace origin is
configured in ignoredSpanOrigins.

This lets customers disable the integration quickly without relying on the
later no-op span path, and keeps the interceptor from injecting tracing
headers when the origin is ignored.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 325.59 ms 387.87 ms 62.29 ms
Size 0 B 0 B 0 B

Baseline results on branch: fix/queue-instrumentation-kafka-system-test-runner

Startup times

Revision Plain With Sentry Diff
466057b 344.28 ms 405.08 ms 60.80 ms

App size

Revision Plain With Sentry Diff
466057b 0 B 0 B 0 B

Previous results on branch: feat/queue-instrumentation-kafka-consumer-tracing

Startup times

Revision Plain With Sentry Diff
14a9178 316.11 ms 341.69 ms 25.59 ms

App size

Revision Plain With Sentry Diff
14a9178 0 B 0 B 0 B

Stop the Spring Kafka record interceptor from reaching through the
static Sentry API when forking root scopes. This keeps the raw Kafka
and Spring Kafka paths aligned and makes the interceptor easier to test.

Co-Authored-By: Claude <noreply@anthropic.com>
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