Skip to content

Commit 0582fec

Browse files
romtsncodex
andcommitted
revert: fix(replay): Bypass sampling for manual buffers
This reverts commit 8073208. Reason: Match Sentry JavaScript by applying onErrorSampleRate to all buffered replay captures. Refs JAVA-325 Co-Authored-By: Codex <noreply@openai.com>
1 parent 8073208 commit 0582fec

2 files changed

Lines changed: 8 additions & 36 deletions

File tree

‎sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ public class ReplayIntegration(
159159
override fun isRecording(): Boolean = state.get().isRecording
160160

161161
override fun start() {
162-
enqueueOnMainThread { startInternal(isFullSession = true, shouldSampleOnError = false) }
162+
enqueueOnMainThread { startInternal(isFullSession = true) }
163163
}
164164

165165
override fun startBuffering() {
166-
enqueueOnMainThread { startInternal(isFullSession = false, shouldSampleOnError = false) }
166+
enqueueOnMainThread { startInternal(isFullSession = false) }
167167
}
168168

169169
override fun onAppForegrounded(startNewSession: Boolean) {
@@ -179,7 +179,7 @@ public class ReplayIntegration(
179179
"Session replay is not started, full session was not sampled and onErrorSampleRate is not specified",
180180
)
181181
} else {
182-
startInternal(isFullSession, shouldSampleOnError = !isFullSession)
182+
startInternal(isFullSession)
183183
}
184184
}
185185
resumeInternal()
@@ -190,7 +190,7 @@ public class ReplayIntegration(
190190
enqueueOnMainThread { pauseInternal() }
191191
}
192192

193-
private fun startInternal(isFullSession: Boolean, shouldSampleOnError: Boolean) {
193+
private fun startInternal(isFullSession: Boolean) {
194194
if (!isEnabled.get()) {
195195
return
196196
}
@@ -235,7 +235,6 @@ public class ReplayIntegration(
235235
lifecycleState = STARTED,
236236
replayId = replayId ?: SentryId.EMPTY_ID,
237237
captureStrategy = strategy,
238-
shouldSampleOnError = shouldSampleOnError,
239238
)
240239
)
241240

@@ -280,11 +279,7 @@ public class ReplayIntegration(
280279
return SentryId.EMPTY_ID
281280
}
282281

283-
if (
284-
current.isBuffering &&
285-
current.shouldSampleOnError &&
286-
!sample(options.sessionReplay.onErrorSampleRate)
287-
) {
282+
if (current.isBuffering && !sample(options.sessionReplay.onErrorSampleRate)) {
288283
options.logger.log(
289284
INFO,
290285
"Replay wasn't sampled by onErrorSampleRate, not capturing for event",
@@ -355,7 +350,7 @@ public class ReplayIntegration(
355350
enqueueOnMainThread {
356351
val current = state.get()
357352
if (!current.isRecording) {
358-
startInternal(isFullSession = true, shouldSampleOnError = false)
353+
startInternal(isFullSession = true)
359354
} else {
360355
captureReplayInternal(current.generation, current.replayId, false)
361356
}
@@ -729,7 +724,6 @@ public class ReplayIntegration(
729724
val lifecycleState: ReplayLifecycleState = ReplayLifecycleState.INITIAL,
730725
val replayId: SentryId = SentryId.EMPTY_ID,
731726
val captureStrategy: CaptureStrategy? = null,
732-
val shouldSampleOnError: Boolean = false,
733727
) {
734728
val isBuffering: Boolean
735729
get() = captureStrategy is BufferCaptureStrategy

‎sentry-android-replay/src/test/java/io/sentry/android/replay/ReplayIntegrationTest.kt‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -576,38 +576,16 @@ class ReplayIntegrationTest {
576576
fixture.getSut(
577577
context,
578578
sessionSampleRate = 0.0,
579-
onErrorSampleRate = 1.0,
579+
onErrorSampleRate = 0.0,
580580
replayCaptureStrategyProvider = { captureStrategy },
581581
)
582582
replay.register(fixture.scopes, fixture.options)
583-
replay.onAppForegrounded(true)
584-
fixture.options.sessionReplay.onErrorSampleRate = 0.0
583+
replay.start()
585584

586585
assertThat(replay.captureReplay(false)).isEqualTo(SentryId.EMPTY_ID)
587586
verify(captureStrategy, never()).captureReplay(any(), any())
588587
}
589588

590-
@Test
591-
fun `manual buffer capture bypasses error sampling`() {
592-
val replayId = SentryId()
593-
val captureStrategy = mock<BufferCaptureStrategy>()
594-
whenever(captureStrategy.currentReplayId).thenReturn(replayId)
595-
whenever(captureStrategy.convert()).thenReturn(captureStrategy)
596-
val replay =
597-
fixture.getSut(
598-
context,
599-
sessionSampleRate = 0.0,
600-
onErrorSampleRate = 0.0,
601-
replayCaptureStrategyProvider = { captureStrategy },
602-
)
603-
replay.register(fixture.scopes, fixture.options)
604-
replay.startBuffering()
605-
606-
assertThat(replay.captureReplay(false)).isEqualTo(replayId)
607-
verify(captureStrategy).captureReplay(eq(false), any())
608-
verify(captureStrategy).convert()
609-
}
610-
611589
@Test
612590
fun `capture queued after stop cannot resurrect replay`() {
613591
val replayId = SentryId()

0 commit comments

Comments
 (0)