Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ static class SentryCacheConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(KafkaTemplate.class)
@ConditionalOnProperty(name = "sentry.enable-queue-tracing", havingValue = "true")
@ConditionalOnMissingClass("io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider")
@Open
static class SentryKafkaQueueConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.sentry.spring.boot.jakarta

import io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider
import io.sentry.spring.jakarta.kafka.SentryKafkaConsumerBeanPostProcessor
import io.sentry.spring.jakarta.kafka.SentryKafkaProducerBeanPostProcessor
import kotlin.test.Test
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

class SentryKafkaAutoConfigurationTest {
Expand All @@ -24,25 +26,43 @@ class SentryKafkaAutoConfigurationTest {
"sentry.debug=false",
)

/** Hide the OTel customizer so conditions evaluate as "no OTel present". */
private val noOtelClassLoader =
FilteredClassLoader(SentryAutoConfigurationCustomizerProvider::class.java)

@Test
fun `registers Kafka BPPs when queue tracing is enabled`() {
contextRunner.withPropertyValues("sentry.enable-queue-tracing=true").run { context ->
assertThat(context).hasSingleBean(SentryKafkaProducerBeanPostProcessor::class.java)
assertThat(context).hasSingleBean(SentryKafkaConsumerBeanPostProcessor::class.java)
}
contextRunner
.withClassLoader(noOtelClassLoader)
.withPropertyValues("sentry.enable-queue-tracing=true")
.run { context ->
assertThat(context).hasSingleBean(SentryKafkaProducerBeanPostProcessor::class.java)
assertThat(context).hasSingleBean(SentryKafkaConsumerBeanPostProcessor::class.java)
}
}

@Test
fun `does not register Kafka BPPs when queue tracing is disabled`() {
contextRunner.run { context ->
contextRunner.withClassLoader(noOtelClassLoader).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.withPropertyValues("sentry.enable-queue-tracing=false").run { context ->
contextRunner
.withClassLoader(noOtelClassLoader)
.withPropertyValues("sentry.enable-queue-tracing=false")
.run { context ->
assertThat(context).doesNotHaveBean(SentryKafkaProducerBeanPostProcessor::class.java)
assertThat(context).doesNotHaveBean(SentryKafkaConsumerBeanPostProcessor::class.java)
}
}

@Test
fun `does not register Kafka BPPs when OpenTelemetry integration is present`() {
contextRunner.withPropertyValues("sentry.enable-queue-tracing=true").run { context ->
assertThat(context).doesNotHaveBean(SentryKafkaProducerBeanPostProcessor::class.java)
assertThat(context).doesNotHaveBean(SentryKafkaConsumerBeanPostProcessor::class.java)
}
Expand Down
2 changes: 2 additions & 0 deletions sentry/src/main/java/io/sentry/util/SpanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class SpanUtils {
origins.add("auto.http.spring7.resttemplate");
origins.add("auto.http.openfeign");
origins.add("auto.http.ktor-client");
origins.add("auto.queue.spring_jakarta.kafka.producer");
origins.add("auto.queue.spring_jakarta.kafka.consumer");
}

if (SentryOpenTelemetryMode.AGENT == mode) {
Expand Down
Loading