@@ -3195,6 +3195,100 @@ class SentryClientTest {
31953195 assertFalse(called)
31963196 }
31973197
3198+ @Test
3199+ fun `beforeErrorSampling returning false skips captureReplay` () {
3200+ var called = false
3201+ fixture.sentryOptions.setReplayController(
3202+ object : ReplayController by NoOpReplayController .getInstance() {
3203+ override fun captureReplay (isTerminating : Boolean? ) {
3204+ called = true
3205+ }
3206+ }
3207+ )
3208+ fixture.sentryOptions.sessionReplay.beforeErrorSampling =
3209+ SentryReplayOptions .BeforeErrorSamplingCallback { _, _ -> false }
3210+ val sut = fixture.getSut()
3211+
3212+ sut.captureEvent(SentryEvent ().apply { exceptions = listOf (SentryException ()) })
3213+ assertFalse(called)
3214+ }
3215+
3216+ @Test
3217+ fun `beforeErrorSampling returning true proceeds with captureReplay` () {
3218+ var called = false
3219+ fixture.sentryOptions.setReplayController(
3220+ object : ReplayController by NoOpReplayController .getInstance() {
3221+ override fun captureReplay (isTerminating : Boolean? ) {
3222+ called = true
3223+ }
3224+ }
3225+ )
3226+ fixture.sentryOptions.sessionReplay.beforeErrorSampling =
3227+ SentryReplayOptions .BeforeErrorSamplingCallback { _, _ -> true }
3228+ val sut = fixture.getSut()
3229+
3230+ sut.captureEvent(SentryEvent ().apply { exceptions = listOf (SentryException ()) })
3231+ assertTrue(called)
3232+ }
3233+
3234+ @Test
3235+ fun `beforeErrorSampling not set proceeds with captureReplay` () {
3236+ var called = false
3237+ fixture.sentryOptions.setReplayController(
3238+ object : ReplayController by NoOpReplayController .getInstance() {
3239+ override fun captureReplay (isTerminating : Boolean? ) {
3240+ called = true
3241+ }
3242+ }
3243+ )
3244+ val sut = fixture.getSut()
3245+
3246+ sut.captureEvent(SentryEvent ().apply { exceptions = listOf (SentryException ()) })
3247+ assertTrue(called)
3248+ }
3249+
3250+ @Test
3251+ fun `beforeErrorSampling throwing exception proceeds with captureReplay` () {
3252+ var called = false
3253+ fixture.sentryOptions.setReplayController(
3254+ object : ReplayController by NoOpReplayController .getInstance() {
3255+ override fun captureReplay (isTerminating : Boolean? ) {
3256+ called = true
3257+ }
3258+ }
3259+ )
3260+ fixture.sentryOptions.sessionReplay.beforeErrorSampling =
3261+ SentryReplayOptions .BeforeErrorSamplingCallback { _, _ -> throw RuntimeException (" test" ) }
3262+ val sut = fixture.getSut()
3263+
3264+ sut.captureEvent(SentryEvent ().apply { exceptions = listOf (SentryException ()) })
3265+ assertTrue(called)
3266+ }
3267+
3268+ @Test
3269+ fun `beforeErrorSampling receives correct event and hint` () {
3270+ var receivedEvent: SentryEvent ? = null
3271+ var receivedHint: Hint ? = null
3272+ fixture.sentryOptions.setReplayController(
3273+ object : ReplayController by NoOpReplayController .getInstance() {
3274+ override fun captureReplay (isTerminating : Boolean? ) {}
3275+ }
3276+ )
3277+ fixture.sentryOptions.sessionReplay.beforeErrorSampling =
3278+ SentryReplayOptions .BeforeErrorSamplingCallback { event, hint ->
3279+ receivedEvent = event
3280+ receivedHint = hint
3281+ true
3282+ }
3283+ val sut = fixture.getSut()
3284+
3285+ val event = SentryEvent ().apply { exceptions = listOf (SentryException ()) }
3286+ val hint = Hint ()
3287+ sut.captureEvent(event, hint)
3288+ assertSame(event, receivedEvent)
3289+ assertSame(hint, receivedHint)
3290+ }
3291+
31983292 @Test
31993293 fun `captures replay for cached events with apply scope` () {
32003294 var called = false
0 commit comments