@@ -2927,6 +2927,108 @@ class ScopesTest {
29272927 )
29282928 }
29292929
2930+ @Test
2931+ fun `adds session replay id to log attributes` () {
2932+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2933+ val replayId = SentryId ()
2934+ sut.scope.replayId = replayId
2935+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2936+
2937+ verify(mockClient)
2938+ .captureLog(
2939+ check {
2940+ assertEquals(" log message" , it.body)
2941+ val logReplayId = it.attributes?.get(" sentry.replay_id" )!!
2942+ assertEquals(replayId.toString(), logReplayId.value)
2943+ },
2944+ anyOrNull(),
2945+ )
2946+ }
2947+
2948+ @Test
2949+ fun `missing session replay id do not break attributes` () {
2950+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2951+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2952+
2953+ verify(mockClient)
2954+ .captureLog(
2955+ check {
2956+ assertEquals(" log message" , it.body)
2957+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
2958+ assertNull(logReplayId)
2959+ },
2960+ anyOrNull(),
2961+ )
2962+ }
2963+
2964+ @Test
2965+ fun `does not add session replay buffering to log attributes if no replay id in scope and in controller` () {
2966+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2967+
2968+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2969+ assertEquals(SentryId .EMPTY_ID , sut.options.replayController.replayId)
2970+
2971+ verify(mockClient)
2972+ .captureLog(
2973+ check {
2974+ assertEquals(" log message" , it.body)
2975+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
2976+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )
2977+ assertNull(logReplayId)
2978+ assertNull(logReplayType)
2979+ },
2980+ anyOrNull(),
2981+ )
2982+ }
2983+
2984+ @Test
2985+ fun `does not add session replay buffering to log attributes if replay id in scope` () {
2986+ val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
2987+ val replayId = SentryId ()
2988+ sut.scope.replayId = replayId
2989+
2990+ sut.logger().log(SentryLogLevel .WARN , " log message" )
2991+
2992+ verify(mockClient)
2993+ .captureLog(
2994+ check {
2995+ assertEquals(" log message" , it.body)
2996+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
2997+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )
2998+ assertEquals(replayId.toString(), logReplayId!! .value)
2999+ assertNull(logReplayType)
3000+ },
3001+ anyOrNull(),
3002+ )
3003+ }
3004+
3005+ @Test
3006+ fun `adds session replay buffering to log attributes if replay id in controller and not in scope` () {
3007+ val mockReplayController = mock<ReplayController >()
3008+ val (sut, mockClient) =
3009+ getEnabledScopes {
3010+ it.logs.isEnabled = true
3011+ it.setReplayController(mockReplayController)
3012+ }
3013+ val replayId = SentryId ()
3014+ sut.scope.replayId = SentryId .EMPTY_ID
3015+ whenever(mockReplayController.replayId).thenReturn(replayId)
3016+
3017+ sut.logger().log(SentryLogLevel .WARN , " log message" )
3018+
3019+ verify(mockClient)
3020+ .captureLog(
3021+ check {
3022+ assertEquals(" log message" , it.body)
3023+ val logReplayId = it.attributes?.get(" sentry.replay_id" )
3024+ val logReplayType = it.attributes?.get(" sentry._internal.replay_is_buffering" )!!
3025+ assertEquals(replayId.toString(), logReplayId!! .value)
3026+ assertTrue(logReplayType.value as Boolean )
3027+ },
3028+ anyOrNull(),
3029+ )
3030+ }
3031+
29303032 // endregion
29313033
29323034 @Test
0 commit comments