◐ Shell
reader mode source ↗
Skip to content

fix(android): Stop duplicating attachments on native events (JAVA-559)#5548

Merged
runningcode merged 2 commits into
mainfrom
no/java-559-attachments-duplication
Jun 16, 2026
Merged

fix(android): Stop duplicating attachments on native events (JAVA-559)#5548
runningcode merged 2 commits into
mainfrom
no/java-559-attachments-duplication

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

📜 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 through sentry_capture_event is then written to the outbox already carrying that attachment as its own envelope item. When OutboxSender re-ingests the cached envelope, it calls captureEvent with a hint that is both Cached and ApplyScopeData, so SentryClient re-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 gates addScopeAttachmentsToHint, 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?

  • Added a unit test in SentryClientTest asserting that a Cached + ApplyScopeData hint does not add scope attachments to the envelope.
  • Reproduced manually in sentry-samples-android: tapping "Native Capture" with a scope attachment configured showed sentry.png twice before the fix and once after.

📝 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.

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>
@linear-code

linear-code Bot commented Jun 16, 2026

Copy link
Copy Markdown

@sentry

sentry Bot commented Jun 16, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.43.2 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 287.53 ms 355.40 ms 67.87 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

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

@runningcode runningcode marked this pull request as ready for review June 16, 2026 08:59

@romtsn romtsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

nice! probably a regression introduced with #5211

Hide details View details @runningcode runningcode merged commit f36e6e3 into main Jun 16, 2026
69 checks passed
@runningcode runningcode deleted the no/java-559-attachments-duplication branch June 16, 2026 11:40
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