{{ message }}
fix(android): Stop duplicating attachments on native events (JAVA-559)#5548
Merged
runningcode merged 2 commits intoJun 16, 2026
Merged
fix(android): Stop duplicating attachments on native events (JAVA-559)#5548runningcode merged 2 commits into
runningcode merged 2 commits into
Conversation
Scope attachments are synced to the native SDK, so native events already carry them as envelope items in the outbox. When re-ingesting those cached envelopes, SentryClient re-applied the scope attachments on top, sending each attachment twice. Skip re-applying scope attachments for cached envelopes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sorry, something went wrong.
📲 Install BuildsAndroid
|
Sorry, something went wrong.
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 295.53 ms | 373.74 ms | 78.21 ms |
| d15471f | 307.28 ms | 381.85 ms | 74.57 ms |
| 4c04bb8 | 350.71 ms | 413.63 ms | 62.92 ms |
| 9e60aca | 316.18 ms | 345.04 ms | 28.86 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| 46b442b | 321.41 ms | 339.30 ms | 17.89 ms |
| b193867 | 331.08 ms | 397.06 ms | 65.98 ms |
| b6702b0 | 395.86 ms | 409.98 ms | 14.12 ms |
| ed33deb | 312.34 ms | 369.71 ms | 57.37 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 4c04bb8 | 0 B | 0 B | 0 B |
| 9e60aca | 0 B | 0 B | 0 B |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| 46b442b | 0 B | 0 B | 0 B |
| b193867 | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| b6702b0 | 1.58 MiB | 2.12 MiB | 551.79 KiB |
| ed33deb | 1.58 MiB | 2.13 MiB | 559.52 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
Sorry, something went wrong.
romtsn
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.
📜 Description
Native (NDK) events no longer duplicate scope attachments.
When an attachment is added to the scope on the Java side, it is synced down to the native SDK via
NdkScopeObserver. A native event captured throughsentry_capture_eventis then written to the outbox already carrying that attachment as its own envelope item. WhenOutboxSenderre-ingests the cached envelope, it callscaptureEventwith a hint that is bothCachedandApplyScopeData, soSentryClientre-applied the Java scope's attachments on top — sending each attachment twice.The fix skips re-applying scope attachments when the event comes from a cached envelope (
!HintUtils.hasType(hint, Cached.class)). The guard is intentionally narrow: it only gatesaddScopeAttachmentsToHint, leaving the rest of scope-data enrichment (contexts, tags, breadcrumbs, level, user) applied as before, which native crashes rely on.💡 Motivation and Context
Fixes attachment duplication on native/NDK events.
💚 How did you test it?
SentryClientTestasserting that aCached+ApplyScopeDatahint does not add scope attachments to the envelope.sentry-samples-android: tapping "Native Capture" with a scope attachment configured showedsentry.pngtwice before the fix and once after.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None.