Skip to content

fix(kafka): [Queue Instrumentation 36] Avoid dropping customer interceptor#5341

Open
adinauer wants to merge 5 commits intofeat/kafka-producer-wrapperfrom
fix/kafka-consumer-interceptor-reflection
Open

fix(kafka): [Queue Instrumentation 36] Avoid dropping customer interceptor#5341
adinauer wants to merge 5 commits intofeat/kafka-producer-wrapperfrom
fix/kafka-consumer-interceptor-reflection

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 28, 2026

PR Stack (Queue Instrumentation)


📜 Description

Avoid installing SentryKafkaRecordInterceptor when the bean post-processor cannot safely read the existing recordInterceptor field from AbstractKafkaListenerContainerFactory.

Before this change, reflection failures fell back to existing = null, and the post-processor still called setRecordInterceptor(sentryInterceptor). That could silently overwrite a customer-configured interceptor.

After this change:

  • getExistingInterceptor throws a dedicated exception when reflection fails
  • postProcessAfterInitialization logs an error and leaves the bean untouched
  • The reflection-failure log now passes the bean name as the format argument and the exception as the throwable
  • Existing customer interceptors are still chained as the delegate when reflection succeeds
  • Tests cover both the chaining path and the deterministic reflection-failure "do not modify the bean" invariant

💡 Motivation and Context

Addresses review finding R10-F003: reflection fallback silently drops the customer's existing RecordInterceptor.

Customers often use RecordInterceptor for DLQ routing, auditing, or other message handling behavior. If Sentry cannot safely discover the existing interceptor, it must disable consumer tracing for that factory instead of overwriting customer behavior.

💚 How did you test it?

  • Ran ./gradlew spotlessApply apiDump
  • Ran ./gradlew :sentry-spring-jakarta:test --tests "io.sentry.spring.jakarta.kafka.SentryKafkaConsumerBeanPostProcessorTest"
  • Added tests covering customer interceptor chaining and deterministic reflection-failure preservation

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • 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

Continue addressing the remaining Queue Instrumentation review findings.

#skip-changelog

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

If reading recordInterceptor via reflection fails, leave the container\nfactory untouched instead of installing Sentry's interceptor with a\nnull delegate. This avoids silently dropping customer-configured\ninterceptors for DLQ routing, auditing, or other message handling\nconcerns.\n\nAdd tests that preserve customer interceptors both when chaining\nsucceeds and when reflection cannot safely determine the existing\ninterceptor.\n\nCo-Authored-By: Claude <noreply@anthropic.com>
This was referenced Apr 28, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 28, 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

@adinauer adinauer marked this pull request as ready for review April 28, 2026 13:21
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7f9aae6. Configure here.

adinauer and others added 2 commits April 29, 2026 10:24
Force the reflection-failure path in the consumer bean post processor test so it proves customer interceptors remain untouched when Sentry skips installation.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants