Skip to content

Commit 4a51ece

Browse files
committed
added session replay id to logs
1 parent 3998a95 commit 4a51ece

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/AndroidContinuousProfiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.sentry.ISpan;
1212
import io.sentry.MeasurementUnit;
1313
import io.sentry.Sentry;
14+
import io.sentry.SentryLogLevel;
1415
import io.sentry.instrumentation.file.SentryFileOutputStream;
1516
import io.sentry.protocol.Feedback;
1617
import 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() {

sentry/src/main/java/io/sentry/logger/LoggerApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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(

sentry/src/test/java/io/sentry/ScopesTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)