Skip to content

fix(spring-jakarta): [Queue Instrumentation 11] Guard entire span lifecycle in Kafka producer interceptor#5281

Draft
adinauer wants to merge 1 commit intofix/queue-instrumentation-root-scopesfrom
fix/queue-instrumentation-producer-guard
Draft

fix(spring-jakarta): [Queue Instrumentation 11] Guard entire span lifecycle in Kafka producer interceptor#5281
adinauer wants to merge 1 commit intofix/queue-instrumentation-root-scopesfrom
fix/queue-instrumentation-producer-guard

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 10, 2026

PR Stack (Queue Instrumentation)


📜 Description

Wrap the entire span lifecycle in SentryProducerInterceptor.onSend() in a single try-catch so instrumentation can never break the customer's Kafka send. The ProducerRecord is always returned regardless of any exception in Sentry code.

Previously, only header injection was guarded. Span creation (startChild), setData(), and finish() were unguarded — any exception from these would propagate and fail the customer's Kafka send per the ProducerInterceptor.onSend() contract.

The inner try-catch around injectHeaders is removed since the outer catch now covers it.

💡 Motivation and Context

Kafka's ProducerInterceptor.onSend() contract requires that interceptors not throw exceptions — any exception propagates and fails the send. Observability code must never cause customer message loss.

💚 How did you test it?

  • All 8 existing SentryProducerInterceptorTest tests pass
  • The change is purely defensive — wraps existing logic in try-catch without changing behavior

📝 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

Nothing.

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

#skip-changelog

…terceptor

Wrap all span operations (startChild, setData, injectHeaders, finish)
in a single try-catch so instrumentation can never break the customer's
Kafka send. The record is always returned regardless of any exception
in Sentry code.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 10, 2026

Sentry Build Distribution

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

Configure sentry-android build distribution settings

@github-actions
Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 347.98 ms 413.21 ms 65.23 ms
Size 0 B 0 B 0 B

Baseline results on branch: fix/queue-instrumentation-root-scopes

Startup times

Revision Plain With Sentry Diff
22ae1be 333.60 ms 393.04 ms 59.44 ms

App size

Revision Plain With Sentry Diff
22ae1be 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