Skip to content

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

Open
adinauer wants to merge 1 commit intofeat/queue-instrumentation-optionsfrom
feat/queue-instrumentation-sample
Open

feat(samples): [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app#5253
adinauer wants to merge 1 commit intofeat/queue-instrumentation-optionsfrom
feat/queue-instrumentation-sample

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 1, 2026

PR Stack (Queue Instrumentation)


📜 Description

Add Kafka producer and consumer to the Spring Boot 3 (Jakarta) sample app behind a kafka Spring profile. This provides a manual test harness for upcoming Kafka queue instrumentation.

What's included:

  • spring-kafka dependency (version catalog entry + sample app)
  • KafkaController — REST endpoint at /kafka/produce that sends messages via KafkaTemplate
  • KafkaConsumer@KafkaListener that receives and logs messages from sentry-topic
  • application-kafka.properties — Kafka config activated with --spring.profiles.active=kafka
  • Kafka auto-configuration excluded by default so the sample app works without a Kafka broker

💡 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

  • 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

  • PR 3: Kafka producer instrumentation (SentryKafkaTemplateWrapper)
  • PR 4: Kafka consumer instrumentation (SentryKafkaRecordInterceptor)
  • PR 5: Spring Boot 3 auto-configuration

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

#skip-changelog

…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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 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 1, 2026

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

Generated by 🚫 dangerJS against f44c735

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 1, 2026

Sentry Build Distribution

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

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

Create PR

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=earliest

This 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=
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Additional Locations (1)
Fix in Cursor Fix in Web

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