Skip to content

Commit dc6152b

Browse files
committed
Still caputre replay for outbox events
1 parent 07191f4 commit dc6152b

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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;
78
import io.sentry.hints.Cached;
89
import io.sentry.hints.DiskFlushNotification;
@@ -211,9 +212,11 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
211212
}
212213

213214
final boolean isBackfillable = HintUtils.hasType(hint, Backfillable.class);
214-
final boolean isCached = HintUtils.hasType(hint, Cached.class);
215+
final boolean isCached =
216+
HintUtils.hasType(hint, Cached.class) && !HintUtils.hasType(hint, ApplyScopeData.class);
215217
// if event is backfillable or cached we don't wanna trigger capture replay, because it's
216-
// an event from the past
218+
// an event from the past. If it's cached, but with ApplyScopeData, it comes from the outbox
219+
// folder and we still want to capture replay (e.g. a native captureException error)
217220
if (event != null && !isBackfillable && !isCached && (event.isErrored() || event.isCrashed())) {
218221
options.getReplayController().captureReplay(event.isCrashed());
219222
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,29 @@ class SentryClientTest {
30143014
assertFalse(called)
30153015
}
30163016

3017+
@Test
3018+
fun `captures replay for cached events with apply scope`() {
3019+
var called = false
3020+
fixture.sentryOptions.setReplayController(object : ReplayController by NoOpReplayController.getInstance() {
3021+
override fun captureReplay(isTerminating: Boolean?) {
3022+
called = true
3023+
}
3024+
})
3025+
val sut = fixture.getSut()
3026+
3027+
sut.captureEvent(
3028+
SentryEvent().apply {
3029+
exceptions = listOf(
3030+
SentryException().apply {
3031+
mechanism = Mechanism().apply { isHandled = false }
3032+
}
3033+
)
3034+
},
3035+
HintUtils.createWithTypeCheckHint(CachedWithApplyScopeHint())
3036+
)
3037+
assertTrue(called)
3038+
}
3039+
30173040
@Test
30183041
fun `when beforeSendReplay is set, callback is invoked`() {
30193042
var invoked = false
@@ -3527,6 +3550,8 @@ class SentryClientTest {
35273550
}
35283551

35293552
private class CachedHint : Cached
3553+
3554+
private class CachedWithApplyScopeHint : Cached, ApplyScopeData
35303555
}
35313556

35323557
class DropEverythingEventProcessor : EventProcessor {

0 commit comments

Comments
 (0)