Skip to content

fix(kafka): [Queue Instrumentation 25] Finish producer spans on failures#5321

Draft
adinauer wants to merge 1 commit intofix/queue-instrumentation-kafka-baggage-headersfrom
fix/queue-instrumentation-kafka-producer-span-cleanup
Draft

fix(kafka): [Queue Instrumentation 25] Finish producer spans on failures#5321
adinauer wants to merge 1 commit intofix/queue-instrumentation-kafka-baggage-headersfrom
fix/queue-instrumentation-kafka-producer-span-cleanup

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 22, 2026

PR Stack (Queue Instrumentation)


📜 Description

This closes the queue.publish producer span even when Kafka header injection fails.

The producer interceptor now keeps a local span reference, marks the span as INTERNAL_ERROR when instrumentation throws after span creation, and finishes it in finally.

It also adds a regression test covering header injection failures.

💡 Motivation and Context

The current producer path logs and fails open when instrumentation throws, but a failure after startChild(...) can leave the created child span unfinished.

Finishing that span in finally preserves the fail-open send behavior while keeping the span lifecycle consistent.

💚 How did you test it?

  • ./gradlew spotlessApply apiDump :sentry-kafka:test --tests='io.sentry.kafka.SentryKafkaProducerInterceptorTest'

📝 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

None.

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

#skip-changelog

Keep a local producer child span reference and always finish it when
instrumentation fails after span creation. This preserves fail-open send
behavior without leaking unfinished queue.publish spans.

Add a regression test covering header injection failures.

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

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

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