From 80058bb9d3dd569eeb54b342deeb7b0ce3502ef9 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Tue, 21 Apr 2026 18:17:32 +0200 Subject: [PATCH] test(spring-boot-jakarta): [Queue Instrumentation 22] Cover spring-kafka class-absence gate `SentryKafkaQueueConfiguration` in `SentryAutoConfiguration` gates the Kafka BPPs on both `org.springframework.kafka.core.KafkaTemplate` and `io.sentry.kafka.SentryKafkaProducerInterceptor` being present on the classpath. Only the latter was covered by a test. Add a `FilteredClassLoader(KafkaTemplate::class.java)` test that asserts neither `SentryKafkaProducerBeanPostProcessor` nor `SentryKafkaConsumerBeanPostProcessor` is registered when spring-kafka is missing, even with `sentry.enable-queue-tracing=true`. Co-Authored-By: Claude --- .../jakarta/SentryKafkaAutoConfigurationTest.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryKafkaAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryKafkaAutoConfigurationTest.kt index ee4779b8a3..2f035936b5 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryKafkaAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryKafkaAutoConfigurationTest.kt @@ -9,6 +9,7 @@ import org.assertj.core.api.Assertions.assertThat import org.springframework.boot.autoconfigure.AutoConfigurations import org.springframework.boot.test.context.FilteredClassLoader import org.springframework.boot.test.context.runner.ApplicationContextRunner +import org.springframework.kafka.core.KafkaTemplate class SentryKafkaAutoConfigurationTest { @@ -34,6 +35,8 @@ class SentryKafkaAutoConfigurationTest { private val noSentryKafkaClassLoader = FilteredClassLoader(SentryKafkaProducerInterceptor::class.java) + private val noSpringKafkaClassLoader = FilteredClassLoader(KafkaTemplate::class.java) + @Test fun `registers Kafka BPPs when queue tracing is enabled`() { contextRunner @@ -64,6 +67,17 @@ class SentryKafkaAutoConfigurationTest { } } + @Test + fun `does not register Kafka BPPs when spring-kafka is not present`() { + contextRunner + .withClassLoader(noSpringKafkaClassLoader) + .withPropertyValues("sentry.enable-queue-tracing=true") + .run { context -> + assertThat(context).doesNotHaveBean(SentryKafkaProducerBeanPostProcessor::class.java) + assertThat(context).doesNotHaveBean(SentryKafkaConsumerBeanPostProcessor::class.java) + } + } + @Test fun `does not register Kafka BPPs when queue tracing is explicitly false`() { contextRunner