Skip to content

Commit ac71155

Browse files
committed
fix(replay): Do not capture replay for cached events
1 parent e53e3d1 commit ac71155

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import io.sentry.clientreport.DiscardReason;
44
import io.sentry.exception.SentryEnvelopeException;
55
import io.sentry.hints.AbnormalExit;
6+
import io.sentry.hints.ApplyScopeData;
67
import io.sentry.hints.Backfillable;
8+
import io.sentry.hints.Cached;
79
import io.sentry.hints.DiskFlushNotification;
810
import io.sentry.hints.TransactionEnd;
911
import io.sentry.logger.ILoggerBatchProcessor;
@@ -210,9 +212,10 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
210212
}
211213

212214
final boolean isBackfillable = HintUtils.hasType(hint, Backfillable.class);
213-
// if event is backfillable we don't wanna trigger capture replay, because it's an event from
214-
// the past
215-
if (event != null && !isBackfillable && (event.isErrored() || event.isCrashed())) {
215+
final boolean isCached = HintUtils.hasType(hint, Cached.class);
216+
// if event is backfillable or cached we don't wanna trigger capture replay, because it's
217+
// an event from the past
218+
if (event != null && !isBackfillable && !isCached && (event.isErrored() || event.isCrashed())) {
216219
options.getReplayController().captureReplay(event.isCrashed());
217220
}
218221

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,29 @@ class SentryClientTest {
29912991
assertFalse(called)
29922992
}
29932993

2994+
@Test
2995+
fun `does not captureReplay for cached events`() {
2996+
var called = false
2997+
fixture.sentryOptions.setReplayController(object : ReplayController by NoOpReplayController.getInstance() {
2998+
override fun captureReplay(isTerminating: Boolean?) {
2999+
called = true
3000+
}
3001+
})
3002+
val sut = fixture.getSut()
3003+
3004+
sut.captureEvent(
3005+
SentryEvent().apply {
3006+
exceptions = listOf(
3007+
SentryException().apply {
3008+
mechanism = Mechanism().apply { isHandled = false }
3009+
}
3010+
)
3011+
},
3012+
HintUtils.createWithTypeCheckHint(CachedHint())
3013+
)
3014+
assertFalse(called)
3015+
}
3016+
29943017
@Test
29953018
fun `when beforeSendReplay is set, callback is invoked`() {
29963019
var invoked = false
@@ -3502,6 +3525,8 @@ class SentryClientTest {
35023525
private class BackfillableHint : Backfillable {
35033526
override fun shouldEnrich(): Boolean = false
35043527
}
3528+
3529+
private class CachedHint : Cached {}
35053530
}
35063531

35073532
class DropEverythingEventProcessor : EventProcessor {

0 commit comments

Comments
 (0)