@@ -2955,6 +2955,108 @@ class ScopesTest {
29552955 )
29562956 }
29572957
2958+ @Test
2959+ fun `adds session replay id to log attributes` () {
2960+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2961+ val replayId = SentryId ()
2962+ sut.scope.replayId = replayId
2963+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2964+
2965+ verify(mockClient)
2966+ .captureLog(
2967+ check {
2968+ assertEquals(" log message" , it.body)
2969+ val logReplayId = it.attributes?.get(" sentry.replay_id" )!!
2970+ assertEquals(replayId.toString(), logReplayId.value)
2971+ },
2972+ anyOrNull(),
2973+ )
2974+ }
2975+
2976+ @Test
2977+ fun `missing session replay id do not break attributes` () {
2978+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2979+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2980+
2981+ verify(mockClient)
2982+ .captureLog(
2983+ check {
2984+ assertEquals(" log message" , it.body)
2985+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
2986+ assertNull(logReplayId)
2987+ },
2988+ anyOrNull(),
2989+ )
2990+ }
2991+
2992+ @Test
2993+ fun `does not add session replay buffering to log attributes if no replay id in scope and in controller` () {
2994+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2995+
2996+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2997+ assertEquals(SentryId .EMPTY_ID , sut.options.replayController.replayId)
2998+
2999+ verify(mockClient)
3000+ .captureLog(
3001+ check {
3002+ assertEquals(" log message" , it.body)
3003+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
3004+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )
3005+ assertNull(logReplayId)
3006+ assertNull(logReplayType)
3007+ },
3008+ anyOrNull(),
3009+ )
3010+ }
3011+
3012+ @Test
3013+ fun `does not add session replay buffering to log attributes if replay id in scope` () {
3014+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
3015+ val replayId = SentryId ()
3016+ sut.scope.replayId = replayId
3017+
3018+ sut.logger().log(SentryLogLevel .WARN , " log message" )
3019+
3020+ verify(mockClient)
3021+ .captureLog(
3022+ check {
3023+ assertEquals(" log message" , it.body)
3024+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
3025+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )
3026+ assertEquals(replayId.toString(), logReplayId!! .value)
3027+ assertNull(logReplayType)
3028+ },
3029+ anyOrNull(),
3030+ )
3031+ }
3032+
3033+ @Test
3034+ fun `adds session replay buffering to log attributes if replay id in controller and not in scope` () {
3035+ val mockReplayController = mock<ReplayController >()
3036+ val (sut, mockClient) =
3037+ getEnabledScopes {
3038+ it.logs.isEnabled = true
3039+ it.setReplayController(mockReplayController)
3040+ }
3041+ val replayId = SentryId ()
3042+ sut.scope.replayId = SentryId .EMPTY_ID
3043+ whenever(mockReplayController.replayId).thenReturn(replayId)
3044+
3045+ sut.logger().log(SentryLogLevel .WARN , " log message" )
3046+
3047+ verify(mockClient)
3048+ .captureLog(
3049+ check {
3050+ assertEquals(" log message" , it.body)
3051+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
3052+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )!!
3053+ assertEquals(replayId.toString(), logReplayId!! .value)
3054+ assertTrue(logReplayType.value as Boolean )
3055+ },
3056+ anyOrNull(),
3057+ )
3058+ }
3059+
29583060 // endregion
29593061
29603062 @Test
0 commit comments