feat(samples): [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app#5253
feat(samples): [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app#5253adinauer wants to merge 1 commit intofeat/queue-instrumentation-optionsfrom
Conversation
…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 <[email protected]>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧Deps
Other
🤖 This preview updates automatically when you update the PR. |
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app ([#5253](https://github.com/getsentry/sentry-java/pull/5253))If none of the above apply, you can opt out of this check by adding |
Sentry Build Distribution
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Blanket clearing of all auto-configuration exclusions in kafka profile
- Removed the empty profile override and added a kafka-profile configuration importing KafkaAutoConfiguration so only Kafka is re-enabled without wiping other exclusions.
Or push these changes by commenting:
@cursor push 2a59cecce2
Preview (2a59cecce2)
diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/java/io/sentry/samples/spring/boot/jakarta/KafkaProfileConfiguration.java b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/java/io/sentry/samples/spring/boot/jakarta/KafkaProfileConfiguration.java
new file mode 100644
--- /dev/null
+++ b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/java/io/sentry/samples/spring/boot/jakarta/KafkaProfileConfiguration.java
@@ -1,0 +1,11 @@
+package io.sentry.samples.spring.boot.jakarta;
+
+import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Profile;
+
+@Configuration
+@Profile("kafka")
+@Import(KafkaAutoConfiguration.class)
+public class KafkaProfileConfiguration {}
diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application-kafka.properties b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application-kafka.properties
--- a/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application-kafka.properties
+++ b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application-kafka.properties
@@ -1,5 +1,4 @@
# Kafka — activate with: --spring.profiles.active=kafka
-spring.autoconfigure.exclude=
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=sentry-sample-group
spring.kafka.consumer.auto-offset-reset=earliestThis Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
| @@ -0,0 +1,9 @@ | |||
| # Kafka — activate with: --spring.profiles.active=kafka | |||
| spring.autoconfigure.exclude= | |||
There was a problem hiding this comment.
Blanket clearing of all auto-configuration exclusions in kafka profile
Low Severity
Setting spring.autoconfigure.exclude= (empty) in application-kafka.properties blanket-clears all auto-configuration exclusions, not just the Kafka one. Spring Boot profile-specific properties fully replace (not merge with) base properties. If any other auto-configuration exclusion is later added to application.properties, activating the kafka profile would silently remove that exclusion too. A safer approach would be to use @Import(KafkaAutoConfiguration.class) on a @Profile("kafka") configuration class to surgically re-enable only the Kafka auto-config.



PR Stack (Queue Instrumentation)
📜 Description
Add Kafka producer and consumer to the Spring Boot 3 (Jakarta) sample app behind a
kafkaSpring profile. This provides a manual test harness for upcoming Kafka queue instrumentation.spring-kafkadependency added tolibs.versions.tomlKafkaController— REST endpoint (/kafka/produce) that sends messagesKafkaConsumer—@KafkaListenerthat receives and logs messagesapplication-kafka.properties— Kafka config activated via--spring.profiles.active=kafka💡 Motivation and Context
Need a working Kafka setup in the sample app to manually test queue instrumentation end-to-end.
💚 How did you test it?
Ran the sample app locally with
--spring.profiles.active=kafkaagainst a local Kafka broker.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps