File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed
sentry-android-core/src/main/java/io/sentry/android/core
sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android
main/java/io/sentry/logger Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -208,11 +208,11 @@ private void start() {
208208
209209 isRunning = true ;
210210
211- if (profilerId == SentryId .EMPTY_ID ) {
211+ if (profilerId . equals ( SentryId .EMPTY_ID ) ) {
212212 profilerId = new SentryId ();
213213 }
214214
215- if (chunkId == SentryId .EMPTY_ID ) {
215+ if (chunkId . equals ( SentryId .EMPTY_ID ) ) {
216216 chunkId = new SentryId ();
217217 }
218218
Original file line number Diff line number Diff line change 1111import io .sentry .ISpan ;
1212import io .sentry .MeasurementUnit ;
1313import io .sentry .Sentry ;
14+ import io .sentry .SentryLogLevel ;
1415import io .sentry .instrumentation .file .SentryFileOutputStream ;
1516import io .sentry .protocol .Feedback ;
1617import io .sentry .protocol .User ;
@@ -304,7 +305,10 @@ public void run() {
304305 Sentry .replay ().enableDebugMaskingOverlay ();
305306 });
306307
308+ Sentry .logger ().log (SentryLogLevel .INFO , "Creating content view" );
307309 setContentView (binding .getRoot ());
310+
311+ Sentry .logger ().log (SentryLogLevel .INFO , "MainActivity created" );
308312 }
309313
310314 private void stackOverflow () {
Original file line number Diff line number Diff line change @@ -211,6 +211,14 @@ private void captureLog(
211211 "sentry.environment" ,
212212 new SentryLogEventAttributeValue (SentryAttributeType .STRING , environment ));
213213 }
214+
215+ final @ Nullable SentryId replayId = scopes .getScope ().getReplayId ();
216+ if (!replayId .equals (SentryId .EMPTY_ID )) {
217+ attributes .put (
218+ "sentry.replay_id" ,
219+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , replayId .toString ()));
220+ }
221+
214222 final @ Nullable String release = scopes .getOptions ().getRelease ();
215223 if (release != null ) {
216224 attributes .put (
Original file line number Diff line number Diff line change @@ -2927,6 +2927,40 @@ 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+
29302964 // endregion
29312965
29322966 @Test
You can’t perform that action at this time.
0 commit comments