Skip to content

Commit f36e6e3

Browse files
runningcodeclaude
andauthored
fix(android): Stop duplicating attachments on native events (JAVA-559) (#5548)
* fix(android): Stop duplicating attachments on native events (JAVA-559) 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> * changelog --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 773a0df commit f36e6e3

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
### Fixes
2222

23+
- Fix attachments being duplicated on native events that carry scope attachments ([#5548](https://github.com/getsentry/sentry-java/pull/5548))
2324
- Fix performance collector scheduling many tasks in a row ([#5524](https://github.com/getsentry/sentry-java/pull/5524))
2425

2526
## 8.43.2

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
112112
hint = new Hint();
113113
}
114114

115-
if (shouldApplyScopeData(event, hint)) {
115+
// Cached envelopes (e.g. native crashes from the outbox) already carry their attachments as
116+
// envelope items. Re-applying scope attachments here would duplicate them.
117+
if (shouldApplyScopeData(event, hint) && !HintUtils.hasType(hint, Cached.class)) {
116118
addScopeAttachmentsToHint(scope, hint);
117119
}
118120

sentry/src/test/java/io/sentry/SentryClientTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,25 @@ class SentryClientTest {
870870
assertEquals(scope.level, event.level)
871871
}
872872

873+
@Test
874+
fun `when hint is Cached, scope attachments are not added to avoid duplication`() {
875+
val sut = fixture.getSut()
876+
877+
val event = createEvent()
878+
val scope = createScopeWithAttachments()
879+
880+
val hints = HintUtils.createWithTypeCheckHint(CustomCachedApplyScopeDataHint())
881+
sut.captureEvent(event, scope, hints)
882+
883+
verify(fixture.transport)
884+
.send(
885+
check { actual ->
886+
assertEquals(0, actual.items.count { it.header.type == SentryItemType.Attachment })
887+
},
888+
anyOrNull(),
889+
)
890+
}
891+
873892
@Test
874893
fun `when transport factory is NoOp, it should initialize it`() {
875894
fixture.sentryOptions.setTransportFactory(NoOpTransportFactory.getInstance())

0 commit comments

Comments
 (0)