Skip to content

Commit 0f0be1c

Browse files
runningcodeclaudemarkushi
authored
fix(core): Clear the persisted replay id when resetting the scope cache (#6033)
* fix(core): Clear the persisted replay id when resetting the scope cache resetCache() clears every other persisted scope value on init but leaves replay.json in place, so a replay id written by a previous process can still be attached to events from the current one. The reset already runs after the integrations that consume those values, so deleting it here is safe. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * changelog * Remove comment Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io>
1 parent 93d2004 commit 0f0be1c

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
### Fixes
116116

117117
- Keep dropped tombstone and ANR events dropped, instead of reporting the same app exit again at every app start ([#6002](https://github.com/getsentry/sentry-java/pull/6002))
118+
- Clear the persisted replay id on SDK init, so a replay id from a previous process is no longer attached to ANR events from the current one ([#6033](https://github.com/getsentry/sentry-java/pull/6033))
118119
- Apply `Sentry.withScope` and `Sentry.withIsolationScope` data to events captured inside the callback when `globalHubMode` is enabled ([#6004](https://github.com/getsentry/sentry-java/pull/6004))
119120
- `globalHubMode` is enabled by default on Android, where tags, extras, contexts and level set inside the callback were silently dropped
120121
- Scopes that are explicitly made current, e.g. via `Sentry.setCurrentScopes` or the `SentryContext` coroutine integration, are now also honoured when `globalHubMode` is enabled

‎sentry/src/main/java/io/sentry/cache/PersistingScopeObserver.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,6 @@ public void resetCache() {
378378
delete(TAGS_FILENAME);
379379
delete(TRACE_FILENAME);
380380
delete(TRANSACTION_FILENAME);
381+
delete(REPLAY_FILENAME);
381382
}
382383
}

‎sentry/src/test/java/io/sentry/cache/PersistingScopeObserverBatchingTest.kt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import io.sentry.ISentryExecutorService
66
import io.sentry.ISerializer
77
import io.sentry.SentryOptions
88
import io.sentry.cache.PersistingScopeObserver.BREADCRUMBS_FILENAME
9+
import io.sentry.cache.PersistingScopeObserver.REPLAY_FILENAME
910
import io.sentry.cache.PersistingScopeObserver.TRANSACTION_FILENAME
11+
import io.sentry.protocol.SentryId
1012
import io.sentry.test.DeferredExecutorService
1113
import java.io.Writer
1214
import java.util.concurrent.atomic.AtomicBoolean
@@ -28,6 +30,9 @@ class PersistingScopeObserverBatchingTest {
2830
private fun PersistingScopeObserver.readTransaction(): String? =
2931
read(options, TRANSACTION_FILENAME, String::class.java)
3032

33+
private fun PersistingScopeObserver.readReplayId(): String? =
34+
read(options, REPLAY_FILENAME, String::class.java)
35+
3136
@Suppress("UNCHECKED_CAST")
3237
private fun PersistingScopeObserver.readBreadcrumbs(): List<Breadcrumb> =
3338
read(options, BREADCRUMBS_FILENAME, List::class.java) as List<Breadcrumb>
@@ -118,6 +123,20 @@ class PersistingScopeObserverBatchingTest {
118123
}
119124
}
120125

126+
@Test
127+
fun `resetCache clears the replay id left behind by the previous process`() {
128+
val executor = DeferredExecutorService()
129+
val sut = getSut(executor)
130+
131+
sut.setReplayId(SentryId("afcb46b1140ade5187c4bbb5daa804df"))
132+
executor.runAll()
133+
assertThat(sut.readReplayId()).isEqualTo("afcb46b1140ade5187c4bbb5daa804df")
134+
135+
sut.resetCache()
136+
137+
assertThat(sut.readReplayId()).isNull()
138+
}
139+
121140
@Test
122141
fun `resetCache keeps pending mutations from the current process`() {
123142
val executor = DeferredExecutorService()

0 commit comments

Comments
 (0)