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 <noreply@anthropic.com>
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
|
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.What's included:
spring-kafkadependency (version catalog entry + sample app)KafkaController— REST endpoint at/kafka/producethat sends messages viaKafkaTemplateKafkaConsumer—@KafkaListenerthat receives and logs messages fromsentry-topicapplication-kafka.properties— Kafka config activated with--spring.profiles.active=kafka💡 Motivation and Context
PR 3–5 in this stack will add Kafka queue instrumentation (producer spans, consumer spans, auto-configuration). This sample app serves as the test harness to manually verify instrumentation works end-to-end before system tests are added in PR 6.
The Kafka components are gated behind a Spring profile so they don't affect existing sample app usage.
💚 How did you test it?
Sample app code — will be tested manually with a local Kafka broker when instrumentation is added.
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
SentryKafkaTemplateWrapper)SentryKafkaRecordInterceptor)#skip-changelog