From e0bb87f35a3f955a9f05457496274617c66ae35a Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 22 Apr 2026 10:44:41 +0200 Subject: [PATCH] test(samples): Cover OTel Jakarta Kafka coexistence end-to-end Enable the Kafka Spring profile (and Kafka broker) for the two OTel Spring Boot 3 Jakarta sample modules in the system-test runner, and add a Kafka system test in each that produces a message and asserts no Sentry-style `queue.publish` / `queue.process` span/transaction is emitted. SentryKafkaQueueConfiguration is guarded by @ConditionalOnMissingClass("io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider"), so the Sentry Kafka bean post-processors must not be wired when the Sentry OTel integration is present. The new assertions lock that suppression into CI for both the agent and noagent OTel Jakarta samples. Addresses review finding F-011. --- .../KafkaOtelCoexistenceSystemTest.kt | 45 +++++++++++++++++++ .../KafkaOtelCoexistenceSystemTest.kt | 45 +++++++++++++++++++ test/system-test-runner.py | 4 ++ 3 files changed, 94 insertions(+) create mode 100644 sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt create mode 100644 sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt new file mode 100644 index 0000000000..61c298f86c --- /dev/null +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt @@ -0,0 +1,45 @@ +package io.sentry.systemtest + +import io.sentry.systemtest.util.TestHelper +import kotlin.test.Test +import kotlin.test.assertEquals +import org.junit.Before + +/** + * System tests for Kafka queue instrumentation on the OTel Jakarta noagent sample. + * + * The Sentry Kafka auto-configuration (`SentryKafkaQueueConfiguration`) is intentionally suppressed + * when `io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider` is on the classpath, so + * the Sentry `SentryKafkaProducerInterceptor` and `SentryKafkaRecordInterceptor` must not be wired. + * + * These tests produce a Kafka message end-to-end and assert that Sentry-style `queue.publish` / + * `queue.process` spans/transactions are *not* emitted. Any Kafka telemetry in OTel mode must come + * from the OTel Kafka instrumentation, not from the Sentry Kafka integration. + * + * Requires: + * - The sample app running with `--spring.profiles.active=kafka` + * - A Kafka broker at localhost:9092 + * - The mock Sentry server at localhost:8000 + */ +class KafkaOtelCoexistenceSystemTest { + lateinit var testHelper: TestHelper + + @Before + fun setup() { + testHelper = TestHelper("http://localhost:8080") + testHelper.reset() + } + + @Test + fun `Sentry Kafka integration is suppressed when OTel is active`() { + val restClient = testHelper.restClient + + restClient.produceKafkaMessage("otel-coexistence-test") + assertEquals(200, restClient.lastKnownStatusCode) + + testHelper.ensureNoTransactionReceived { transaction, _ -> + transaction.contexts.trace?.operation == "queue.process" || + transaction.spans.any { span -> span.op == "queue.publish" } + } + } +} diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt new file mode 100644 index 0000000000..f55303541b --- /dev/null +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/kotlin/io/sentry/systemtest/KafkaOtelCoexistenceSystemTest.kt @@ -0,0 +1,45 @@ +package io.sentry.systemtest + +import io.sentry.systemtest.util.TestHelper +import kotlin.test.Test +import kotlin.test.assertEquals +import org.junit.Before + +/** + * System tests for Kafka queue instrumentation on the OTel Jakarta sample. + * + * The Sentry Kafka auto-configuration (`SentryKafkaQueueConfiguration`) is intentionally suppressed + * when `io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider` is on the classpath, so + * the Sentry `SentryKafkaProducerInterceptor` and `SentryKafkaRecordInterceptor` must not be wired. + * + * These tests produce a Kafka message end-to-end and assert that Sentry-style `queue.publish` / + * `queue.process` spans/transactions are *not* emitted. Any Kafka telemetry in OTel mode must come + * from the OTel Kafka instrumentation, not from the Sentry Kafka integration. + * + * Requires: + * - The sample app running with `--spring.profiles.active=kafka` + * - A Kafka broker at localhost:9092 + * - The mock Sentry server at localhost:8000 + */ +class KafkaOtelCoexistenceSystemTest { + lateinit var testHelper: TestHelper + + @Before + fun setup() { + testHelper = TestHelper("http://localhost:8080") + testHelper.reset() + } + + @Test + fun `Sentry Kafka integration is suppressed when OTel is active`() { + val restClient = testHelper.restClient + + restClient.produceKafkaMessage("otel-coexistence-test") + assertEquals(200, restClient.lastKnownStatusCode) + + testHelper.ensureNoTransactionReceived { transaction, _ -> + transaction.contexts.trace?.operation == "queue.process" || + transaction.spans.any { span -> span.op == "queue.publish" } + } + } +} diff --git a/test/system-test-runner.py b/test/system-test-runner.py index 5102c66d92..d85d894c00 100644 --- a/test/system-test-runner.py +++ b/test/system-test-runner.py @@ -71,9 +71,13 @@ KAFKA_BROKER_REQUIRED_MODULES = { "sentry-samples-console", "sentry-samples-spring-boot-jakarta", + "sentry-samples-spring-boot-jakarta-opentelemetry", + "sentry-samples-spring-boot-jakarta-opentelemetry-noagent", } KAFKA_PROFILE_REQUIRED_MODULES = { "sentry-samples-spring-boot-jakarta", + "sentry-samples-spring-boot-jakarta-opentelemetry", + "sentry-samples-spring-boot-jakarta-opentelemetry-noagent", } class ServerType(Enum):