Skip to content

Commit 80058bb

Browse files
adinauerclaude
andcommitted
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 <noreply@anthropic.com>
1 parent df91d0c commit 80058bb

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryKafkaAutoConfigurationTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.assertj.core.api.Assertions.assertThat
99
import org.springframework.boot.autoconfigure.AutoConfigurations
1010
import org.springframework.boot.test.context.FilteredClassLoader
1111
import org.springframework.boot.test.context.runner.ApplicationContextRunner
12+
import org.springframework.kafka.core.KafkaTemplate
1213

1314
class SentryKafkaAutoConfigurationTest {
1415

@@ -34,6 +35,8 @@ class SentryKafkaAutoConfigurationTest {
3435
private val noSentryKafkaClassLoader =
3536
FilteredClassLoader(SentryKafkaProducerInterceptor::class.java)
3637

38+
private val noSpringKafkaClassLoader = FilteredClassLoader(KafkaTemplate::class.java)
39+
3740
@Test
3841
fun `registers Kafka BPPs when queue tracing is enabled`() {
3942
contextRunner
@@ -64,6 +67,17 @@ class SentryKafkaAutoConfigurationTest {
6467
}
6568
}
6669

70+
@Test
71+
fun `does not register Kafka BPPs when spring-kafka is not present`() {
72+
contextRunner
73+
.withClassLoader(noSpringKafkaClassLoader)
74+
.withPropertyValues("sentry.enable-queue-tracing=true")
75+
.run { context ->
76+
assertThat(context).doesNotHaveBean(SentryKafkaProducerBeanPostProcessor::class.java)
77+
assertThat(context).doesNotHaveBean(SentryKafkaConsumerBeanPostProcessor::class.java)
78+
}
79+
}
80+
6781
@Test
6882
fun `does not register Kafka BPPs when queue tracing is explicitly false`() {
6983
contextRunner

0 commit comments

Comments
 (0)