Skip to content

feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254

Draft
adinauer wants to merge 2 commits intofeat/queue-instrumentation-samplefrom
feat/queue-instrumentation-producer
Draft

feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254
adinauer wants to merge 2 commits intofeat/queue-instrumentation-samplefrom
feat/queue-instrumentation-producer

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 1, 2026

PR Stack (Queue Instrumentation)


📜 Description

Add Kafka producer instrumentation to sentry-spring-jakarta:

  • SentryKafkaProducerWrapper — extends KafkaTemplate, overrides doSend to create queue.publish spans for all send variants. Injects sentry-trace, baggage, and sentry-task-enqueued-time headers into Kafka record headers for distributed tracing and receive latency calculation. Span finishes asynchronously in the CompletableFuture.whenComplete callback.

  • SentryKafkaProducerBeanPostProcessor — automatically wraps KafkaTemplate beans in SentryKafkaProducerWrapper. Follows the same pattern as SentryCacheBeanPostProcessor.

Key design decisions:

  • Overrides doSend (protected) rather than send(ProducerRecord) because all send variants (send(topic, value), send(topic, key, value), sendDefault(value), etc.) route through observeSenddoSend, not through send(ProducerRecord)
  • Header injection is wrapped in its own try/catch so failures never break the send
  • Gated behind SentryOptions.isEnableQueueTracing() — no spans created when disabled

💡 Motivation and Context

PR 3 in the Queue Instrumentation stack. Adds the producer-side instrumentation that creates queue.publish spans and injects trace headers for distributed tracing to the consumer side (PR 4).

💚 How did you test it?

  • Unit tests for BPP (wrap/skip/no-double-wrap)
  • Unit tests for wrapper (header injection, trace origin, span lifecycle)
  • ./gradlew :sentry-spring-jakarta:test --tests="*SentryKafkaProducer*" — 8 tests pass

📝 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

  • PR 4: Kafka consumer instrumentation (SentryKafkaRecordInterceptor)
  • PR 5: Spring Boot 3 auto-configuration

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

Add SentryKafkaProducerWrapper that overrides doSend to create
queue.publish spans for all KafkaTemplate send operations. Injects
sentry-trace, baggage, and sentry-task-enqueued-time headers for
distributed tracing and receive latency calculation.

Add SentryKafkaProducerBeanPostProcessor to automatically wrap
KafkaTemplate beans.

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

github-actions bot commented Apr 1, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

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


New Features ✨

  • (core) [Queue Instrumentation 1] Add enableQueueTracing option and messaging span data conventions by adinauer in #5250
  • (spring-jakarta) [Queue Instrumentation 3] Add Kafka producer instrumentation by adinauer in #5254
  • Add strict trace continuation support by giortzisg in #5136
  • Sync file attachments to native by bitsandfoxes in #5211

Internal Changes 🔧

Deps

  • Bump requests from 2.32.4 to 2.33.0 in the uv group across 1 directory by dependabot in #5237
  • Bump github/codeql-action from 4.32.6 to 4.35.1 by dependabot in #5243

Other

  • Add THIRD_PARTY_NOTICES.md for vendored third-party code by markushi in #5186

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 5049ffc

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 1, 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 323.43 ms 384.17 ms 60.73 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