Skip to content

test(spring-boot-jakarta): [Queue Instrumentation 32] Filter OTel in Kafka auto-config negative tests#5330

Open
adinauer wants to merge 1 commit intofix/queue-instrumentation-kafka-enqueued-time-formatfrom
test/queue-instrumentation-kafka-auto-config-filter-otel
Open

test(spring-boot-jakarta): [Queue Instrumentation 32] Filter OTel in Kafka auto-config negative tests#5330
adinauer wants to merge 1 commit intofix/queue-instrumentation-kafka-enqueued-time-formatfrom
test/queue-instrumentation-kafka-auto-config-filter-otel

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 23, 2026

PR Stack (Queue Instrumentation)


📜 Description

Fix the Kafka auto-config negative regression tests so they validate the @ConditionalOnClass gate they claim to guard.

SentryKafkaQueueConfiguration is gated by three annotations:

  1. @ConditionalOnClass({KafkaTemplate, SentryKafkaProducerInterceptor})
  2. @ConditionalOnProperty("sentry.enable-queue-tracing" = "true")
  3. @ConditionalOnMissingClass("io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider")

The regression tests does not register Kafka BPPs when sentry-kafka is not present and ...when spring-kafka is not present used FilteredClassLoader to hide SentryKafkaProducerInterceptor / KafkaTemplate respectively, asserting the BPPs are absent. But sentry-opentelemetry-agentless-spring is on testImplementation, so SentryAutoConfigurationCustomizerProvider is always on the test classpath — gate #3 was already blocking the config independent of gate #1. The tests passed for the wrong reason: if someone removed a class from @ConditionalOnClass, they would still pass.

Extend both FilteredClassLoaders to additionally filter SentryAutoConfigurationCustomizerProvider, so gate #3 is satisfied and only the gate under test can be the blocker. With this change, temporarily removing "io.sentry.kafka.SentryKafkaProducerInterceptor" from @ConditionalOnClass causes the sentry-kafka not present test to correctly fail — confirmed locally before restoring the gate.

Addresses review8.md finding R8-F005.

💡 Motivation and Context

PR #5291 introduced these negative regression tests to guard against the NoClassDefFoundError scenario from review finding R8-F003 (sentry-kafka absent but spring-kafka present with queue tracing enabled → @ConditionalOnClass must skip the configuration). The tests passed, so the gate was presumed covered. The audit in review8 showed the tests could not detect a regression because an unrelated gate was doing the work. Fixing this ensures the regression test is load-bearing, not decorative.

💚 How did you test it?

  • ./gradlew :sentry-spring-boot-jakarta:test --tests SentryKafkaAutoConfigurationTest — all 6 tests pass.
  • Chaos check: temporarily removed "io.sentry.kafka.SentryKafkaProducerInterceptor" from @ConditionalOnClassdoes not register Kafka BPPs when sentry-kafka is not present now fails (as it should). Gate restored.
  • ./gradlew spotlessApply apiDump — clean.

📝 Checklist

  • I added tests to verify the changes. (This PR is a test-quality fix; no production code changes.)
  • I added GH Issue ID & Linear ID
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Remaining open items on the Queue Instrumentation stack after this PR:

  • R8-F004test/system-test-runner.py stop_kafka_broker() guard prevents pre-start stale-container cleanup from running.
  • R7-F004 / R8-C002SentryKafkaProducerBeanPostProcessor does not detect a SentryKafkaProducerInterceptor nested inside a CompositeProducerInterceptor (double-wrapping risk).

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

#skip-changelog

…Kafka auto-config negative tests

The regression tests "does not register Kafka BPPs when sentry-kafka is
not present" and "...when spring-kafka is not present" previously
passed for the wrong reason: OTel's SentryAutoConfigurationCustomizerProvider
is on the test classpath as a testImplementation dependency, so the
@ConditionalOnMissingClass(OTel) gate on SentryKafkaQueueConfiguration
was already blocking the beans independent of the @ConditionalOnClass
check the tests were meant to validate.

Make noSentryKafkaClassLoader and noSpringKafkaClassLoader additionally
filter SentryAutoConfigurationCustomizerProvider so only the gate under
test can be the blocker. Verified by temporarily removing
SentryKafkaProducerInterceptor from the @ConditionalOnClass list: the
test now correctly fails, proving it actually guards against the
regression it is named for.

Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Apr 23, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 23, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.37.1 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 316.17 ms 354.36 ms 38.19 ms
Size 0 B 0 B 0 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant