feat(spring): [Queue Instrumentation 41] Add Spring Boot 2 Kafka tracing#5352
Conversation
Port Kafka queue tracing to the Spring and Spring Boot 2 modules. Add Spring Kafka bean post-processors, Boot 2 auto-configuration, and matching sample system-test coverage. Co-Authored-By: Claude <noreply@anthropic.com>
Document when to load queue-specific Cursor rules and summarize how Sentry Queues data is produced by the Java SDK Kafka instrumentation. Co-Authored-By: Claude <noreply@anthropic.com>
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- [Queue Instrumentation 41] Add Spring Boot 2 Kafka tracing ([#5352](https://github.com/getsentry/sentry-java/pull/5352))If none of the above apply, you can opt out of this check by adding |
📲 Install BuildsAndroid
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ce27249 | 350.50 ms | 432.16 ms | 81.66 ms |
| 89b8db0 | 377.17 ms | 429.49 ms | 52.32 ms |
| 1a9b19e | 323.42 ms | 368.73 ms | 45.31 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ce27249 | 0 B | 0 B | 0 B |
| 89b8db0 | 0 B | 0 B | 0 B |
| 1a9b19e | 0 B | 0 B | 0 B |
Previous results on branch: feat/queue-instrumentation-spring-boot-2
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6432a3a | 345.23 ms | 421.67 ms | 76.44 ms |
| ccba042 | 319.40 ms | 359.81 ms | 40.41 ms |
| c1fb851 | 446.80 ms | 553.50 ms | 106.70 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 6432a3a | 0 B | 0 B | 0 B |
| ccba042 | 0 B | 0 B | 0 B |
| c1fb851 | 0 B | 0 B | 0 B |
…ue-instrumentation-spring-boot-2
…ue-instrumentation-spring-boot-2
…ue-instrumentation-spring-boot-2
Simplify Spring Kafka test interceptors and cover intercepting records without a consumer. Co-Authored-By: Claude <noreply@anthropic.com>
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 a4b2016. Configure here.
| } catch (Throwable t) { | ||
| scopes.getOptions().getLogger().log(SentryLevel.ERROR, "Unable to wrap Kafka consumer.", t); | ||
| } | ||
| return delegateIntercept(record, consumer); |
There was a problem hiding this comment.
Filtered records leave tracing open
Medium Severity
The intercept method starts a Sentry transaction. When the delegate filters a record by returning null, Spring Kafka skips success and failure calls. This leaves the Sentry transaction and its scope active in the currentContext (ThreadLocal), causing resource leaks.
Reviewed by Cursor Bugbot for commit a4b2016. Configure here.


PR Stack (Queue Instrumentation)
📜 Description
Ports the Spring Boot 3 Kafka queue tracing stack changes to Spring Boot 2 as one PR.
This adds Spring Kafka support to the Spring 5 module, wires it into the Spring Boot 2 auto-configuration, and adds Boot 2 sample/system-test coverage for the regular, OTel agent, and OTel no-agent samples.
It also adds Cursor rules for queue tracing so future agent work has a high-level reference for how Sentry Queues data is produced by the Java SDK.
💡 Motivation and Context
The queue instrumentation stack added Kafka tracing for newer Spring Boot generations. Spring Boot 2 uses the Spring 5 module, so it needs the same Kafka producer/consumer bean post-processors and auto-configuration in the Boot 2 integration.
The new rules file documents when to load queue-specific guidance and summarizes the relationship between Sentry Queues, queue spans, Kafka instrumentation, and Spring Kafka auto-instrumentation.
💚 How did you test it?
./gradlew spotlessApply apiDump./gradlew :sentry-spring:test --tests '*Kafka*' :sentry-spring-boot:test --tests '*Kafka*'./gradlew :sentry-samples:sentry-samples-spring-boot:compileJava :sentry-samples:sentry-samples-spring-boot:compileTestKotlin :sentry-samples:sentry-samples-spring-boot-opentelemetry:compileJava :sentry-samples:sentry-samples-spring-boot-opentelemetry:compileTestKotlin :sentry-samples:sentry-samples-spring-boot-opentelemetry-noagent:compileJava :sentry-samples:sentry-samples-spring-boot-opentelemetry-noagent:compileTestKotlin📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None.