Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Add session replay id to Sentry Logs ([#4740](https://github.com/getsentry/sentry-java/pull/4740))
- Move SentryLogs out of experimental ([#4710](https://github.com/getsentry/sentry-java/pull/4710))
- Add support for w3c traceparent header ([#4671](https://github.com/getsentry/sentry-java/pull/4671))
- This feature is disabled by default. If enabled, outgoing requests will include the w3c `traceparent` header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ private void start() {

isRunning = true;

if (profilerId == SentryId.EMPTY_ID) {
if (profilerId.equals(SentryId.EMPTY_ID)) {
profilerId = new SentryId();
}

if (chunkId == SentryId.EMPTY_ID) {
if (chunkId.equals(SentryId.EMPTY_ID)) {
chunkId = new SentryId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.sentry.ISpan;
import io.sentry.MeasurementUnit;
import io.sentry.Sentry;
import io.sentry.SentryLogLevel;
import io.sentry.instrumentation.file.SentryFileOutputStream;
import io.sentry.protocol.Feedback;
import io.sentry.protocol.User;
Expand Down Expand Up @@ -304,7 +305,10 @@ public void run() {
Sentry.replay().enableDebugMaskingOverlay();
});

Sentry.logger().log(SentryLogLevel.INFO, "Creating content view");
setContentView(binding.getRoot());

Sentry.logger().log(SentryLogLevel.INFO, "MainActivity created");
}

private void stackOverflow() {
Expand Down
8 changes: 8 additions & 0 deletions sentry/src/main/java/io/sentry/logger/LoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ private void captureLog(
"sentry.environment",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, environment));
}

final @Nullable SentryId replayId = scopes.getScope().getReplayId();
if (!replayId.equals(SentryId.EMPTY_ID)) {
attributes.put(
"sentry.replay_id",
new SentryLogEventAttributeValue(SentryAttributeType.STRING, replayId.toString()));
}

final @Nullable String release = scopes.getOptions().getRelease();
if (release != null) {
attributes.put(
Expand Down
34 changes: 34 additions & 0 deletions sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2927,6 +2927,40 @@ class ScopesTest {
)
}

@Test
fun `adds session replay id to log attributes`() {
val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
val replayId = SentryId()
sut.scope.replayId = replayId
sut.logger().log(SentryLogLevel.WARN, "log message")

verify(mockClient)
.captureLog(
check {
assertEquals("log message", it.body)
val logReplayId = it.attributes?.get("sentry.replay_id")!!
assertEquals(replayId.toString(), logReplayId.value)
},
anyOrNull(),
)
}

@Test
fun `missing session replay id do not break attributes`() {
val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true }
sut.logger().log(SentryLogLevel.WARN, "log message")

verify(mockClient)
.captureLog(
check {
assertEquals("log message", it.body)
val logReplayId = it.attributes?.get("sentry.replay_id")
assertNull(logReplayId)
},
anyOrNull(),
)
}

// endregion

@Test
Expand Down
Loading