Skip to content

Commit f1a44de

Browse files
authored
Merge db18ff8 into c1ccbf7
2 parents c1ccbf7 + db18ff8 commit f1a44de

4 files changed

Lines changed: 54 additions & 40 deletions

File tree

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@ import kotlin.test.Test
55
import kotlin.test.assertEquals
66
import org.junit.Before
77

8-
/**
9-
* System tests for Kafka queue instrumentation on the OTel Jakarta noagent sample.
10-
*
11-
* The Sentry Kafka auto-configuration (`SentryKafkaQueueConfiguration`) is intentionally suppressed
12-
* when `io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider` is on the classpath, so
13-
* the Sentry `SentryKafkaProducer` and `SentryKafkaRecordInterceptor` must not be wired.
14-
*
15-
* These tests produce a Kafka message end-to-end and assert that Sentry-style `queue.publish` /
16-
* `queue.process` spans/transactions are *not* emitted. Any Kafka telemetry in OTel mode must come
17-
* from the OTel Kafka instrumentation, not from the Sentry Kafka integration.
18-
*
19-
* Requires:
20-
* - The sample app running with `--spring.profiles.active=kafka`
21-
* - A Kafka broker at localhost:9092
22-
* - The mock Sentry server at localhost:8000
23-
*/
248
class KafkaOtelCoexistenceSystemTest {
259
lateinit var testHelper: TestHelper
2610

@@ -37,9 +21,21 @@ class KafkaOtelCoexistenceSystemTest {
3721
restClient.produceKafkaMessage("otel-coexistence-test")
3822
assertEquals(200, restClient.lastKnownStatusCode)
3923

40-
testHelper.ensureNoTransactionReceived { transaction, _ ->
41-
transaction.contexts.trace?.operation == "queue.process" ||
42-
transaction.spans.any { span -> span.op == "queue.publish" }
24+
testHelper.ensureTransactionReceived { transaction, _ ->
25+
transaction.transaction == "GET /kafka/produce" &&
26+
transaction.sdk?.integrationSet?.contains("SpringKafka") != true &&
27+
transaction.spans.any { span ->
28+
span.op == "queue.publish" &&
29+
span.origin == "auto.opentelemetry" &&
30+
span.data?.get("messaging.system") == "kafka"
31+
}
32+
}
33+
34+
testHelper.ensureTransactionReceived { transaction, _ ->
35+
transaction.contexts.trace?.operation == "queue.process" &&
36+
transaction.contexts.trace?.origin == "auto.opentelemetry" &&
37+
transaction.contexts.trace?.data?.get("messaging.system") == "kafka" &&
38+
transaction.sdk?.integrationSet?.contains("SpringKafka") != true
4339
}
4440
}
4541
}

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@ import kotlin.test.Test
55
import kotlin.test.assertEquals
66
import org.junit.Before
77

8-
/**
9-
* System tests for Kafka queue instrumentation on the OTel Jakarta sample.
10-
*
11-
* The Sentry Kafka auto-configuration (`SentryKafkaQueueConfiguration`) is intentionally suppressed
12-
* when `io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider` is on the classpath, so
13-
* the Sentry `SentryKafkaProducer` and `SentryKafkaRecordInterceptor` must not be wired.
14-
*
15-
* These tests produce a Kafka message end-to-end and assert that Sentry-style `queue.publish` /
16-
* `queue.process` spans/transactions are *not* emitted. Any Kafka telemetry in OTel mode must come
17-
* from the OTel Kafka instrumentation, not from the Sentry Kafka integration.
18-
*
19-
* Requires:
20-
* - The sample app running with `--spring.profiles.active=kafka`
21-
* - A Kafka broker at localhost:9092
22-
* - The mock Sentry server at localhost:8000
23-
*/
248
class KafkaOtelCoexistenceSystemTest {
259
lateinit var testHelper: TestHelper
2610

@@ -37,9 +21,21 @@ class KafkaOtelCoexistenceSystemTest {
3721
restClient.produceKafkaMessage("otel-coexistence-test")
3822
assertEquals(200, restClient.lastKnownStatusCode)
3923

40-
testHelper.ensureNoTransactionReceived { transaction, _ ->
41-
transaction.contexts.trace?.operation == "queue.process" ||
42-
transaction.spans.any { span -> span.op == "queue.publish" }
24+
testHelper.ensureTransactionReceived { transaction, _ ->
25+
transaction.transaction == "GET /kafka/produce" &&
26+
transaction.sdk?.integrationSet?.contains("SpringKafka") != true &&
27+
transaction.spans.any { span ->
28+
span.op == "queue.publish" &&
29+
span.origin == "auto.opentelemetry" &&
30+
span.data?.get("messaging.system") == "kafka"
31+
}
32+
}
33+
34+
testHelper.ensureTransactionReceived { transaction, _ ->
35+
transaction.contexts.trace?.operation == "queue.process" &&
36+
transaction.contexts.trace?.origin == "auto.opentelemetry" &&
37+
transaction.contexts.trace?.data?.get("messaging.system") == "kafka" &&
38+
transaction.sdk?.integrationSet?.contains("SpringKafka") != true
4339
}
4440
}
4541
}

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ static class SentryCacheConfiguration {
255255
"io.sentry.kafka.SentryKafkaProducer"
256256
})
257257
@ConditionalOnProperty(name = "sentry.enable-queue-tracing", havingValue = "true")
258-
@ConditionalOnMissingClass("io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider")
258+
@ConditionalOnMissingClass({
259+
"io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider",
260+
"io.sentry.opentelemetry.agent.AgentMarker"
261+
})
259262
@Open
260263
static class SentryKafkaQueueConfiguration {
261264

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.sentry.spring.boot.jakarta
22

33
import io.sentry.kafka.SentryKafkaProducer
44
import io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider
5+
import io.sentry.opentelemetry.agent.AgentMarker
56
import io.sentry.spring.jakarta.kafka.SentryKafkaConsumerBeanPostProcessor
67
import io.sentry.spring.jakarta.kafka.SentryKafkaProducerBeanPostProcessor
78
import kotlin.test.Test
@@ -28,20 +29,27 @@ class SentryKafkaAutoConfigurationTest {
2829
"sentry.debug=false",
2930
)
3031

31-
/** Hide the OTel customizer so conditions evaluate as "no OTel present". */
3232
private val noOtelClassLoader =
33+
FilteredClassLoader(
34+
SentryAutoConfigurationCustomizerProvider::class.java,
35+
AgentMarker::class.java,
36+
)
37+
38+
private val noOtelCustomizerClassLoader =
3339
FilteredClassLoader(SentryAutoConfigurationCustomizerProvider::class.java)
3440

3541
private val noSentryKafkaClassLoader =
3642
FilteredClassLoader(
3743
SentryKafkaProducer::class.java,
3844
SentryAutoConfigurationCustomizerProvider::class.java,
45+
AgentMarker::class.java,
3946
)
4047

4148
private val noSpringKafkaClassLoader =
4249
FilteredClassLoader(
4350
KafkaTemplate::class.java,
4451
SentryAutoConfigurationCustomizerProvider::class.java,
52+
AgentMarker::class.java,
4553
)
4654

4755
@Test
@@ -96,6 +104,17 @@ class SentryKafkaAutoConfigurationTest {
96104
}
97105
}
98106

107+
@Test
108+
fun `does not register Kafka BPPs when OpenTelemetry agent is present`() {
109+
contextRunner
110+
.withClassLoader(noOtelCustomizerClassLoader)
111+
.withPropertyValues("sentry.enable-queue-tracing=true")
112+
.run { context ->
113+
assertThat(context).doesNotHaveBean(SentryKafkaProducerBeanPostProcessor::class.java)
114+
assertThat(context).doesNotHaveBean(SentryKafkaConsumerBeanPostProcessor::class.java)
115+
}
116+
}
117+
99118
@Test
100119
fun `does not register Kafka BPPs when OpenTelemetry integration is present`() {
101120
contextRunner.withPropertyValues("sentry.enable-queue-tracing=true").run { context ->

0 commit comments

Comments
 (0)