diff --git a/CHANGELOG.md b/CHANGELOG.md index 2334bc7169..c34c5b48c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - When merging tombstones with Native SDK, use the tombstone message if the Native SDK didn't explicitly provide one. ([#5095](https://github.com/getsentry/sentry-java/pull/5095)) - Fix thread leak caused by eager creation of `SentryExecutorService` in `SentryOptions` ([#5093](https://github.com/getsentry/sentry-java/pull/5093)) - There were cases where we created options that ended up unused but we failed to clean those up. +- Attach user attributes to logs and metrics regardless of `sendDefaultPii` ([#5099](https://github.com/getsentry/sentry-java/pull/5099)) - No longer log a warning if a logging integration cannot initialize Sentry due to missing DSN ([#5075](https://github.com/getsentry/sentry-java/pull/5075)) - While this may have been useful to some, it caused lots of confusion. - Session Replay: Add `androidx.camera.view.PreviewView` to default `maskedViewClasses` to mask camera previews by default. ([#5097](https://github.com/getsentry/sentry-java/pull/5097)) diff --git a/sentry/src/main/java/io/sentry/logger/LoggerApi.java b/sentry/src/main/java/io/sentry/logger/LoggerApi.java index 4b047a26e3..37a485df31 100644 --- a/sentry/src/main/java/io/sentry/logger/LoggerApi.java +++ b/sentry/src/main/java/io/sentry/logger/LoggerApi.java @@ -243,9 +243,7 @@ private void captureLog( setServerName(attributes); } - if (scopes.getOptions().isSendDefaultPii()) { - setUser(attributes); - } + setUser(attributes); return attributes; } diff --git a/sentry/src/main/java/io/sentry/metrics/MetricsApi.java b/sentry/src/main/java/io/sentry/metrics/MetricsApi.java index 08a1510049..fc16d60e0e 100644 --- a/sentry/src/main/java/io/sentry/metrics/MetricsApi.java +++ b/sentry/src/main/java/io/sentry/metrics/MetricsApi.java @@ -230,9 +230,7 @@ private void captureMetrics( setServerName(attributes); } - if (scopes.getOptions().isSendDefaultPii()) { - setUser(attributes); - } + setUser(attributes); return attributes; } diff --git a/sentry/src/test/java/io/sentry/ScopesTest.kt b/sentry/src/test/java/io/sentry/ScopesTest.kt index 60ef92e893..73a14b38e7 100644 --- a/sentry/src/test/java/io/sentry/ScopesTest.kt +++ b/sentry/src/test/java/io/sentry/ScopesTest.kt @@ -2953,7 +2953,7 @@ class ScopesTest { } @Test - fun `does not add user fields to log attributes by default`() { + fun `adds user fields to log attributes even if sendDefaultPii is false`() { val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true @@ -2975,9 +2975,17 @@ class ScopesTest { check { assertEquals("log message", it.body) - assertNull(it.attributes?.get("user.id")) - assertNull(it.attributes?.get("user.name")) - assertNull(it.attributes?.get("user.email")) + val userId = it.attributes?.get("user.id")!! + assertEquals("usrid", userId.value) + assertEquals("string", userId.type) + + val userName = it.attributes?.get("user.name")!! + assertEquals("usrname", userName.value) + assertEquals("string", userName.type) + + val userEmail = it.attributes?.get("user.email")!! + assertEquals("user@sentry.io", userEmail.value) + assertEquals("string", userEmail.type) }, anyOrNull(), ) @@ -2988,7 +2996,6 @@ class ScopesTest { val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true - it.isSendDefaultPii = true it.distinctId = "distinctId" } @@ -3012,7 +3019,6 @@ class ScopesTest { val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true - it.isSendDefaultPii = true it.distinctId = null } @@ -3919,7 +3925,7 @@ class ScopesTest { } @Test - fun `does not add user fields to metric attributes by default`() { + fun `adds user fields to metric attributes even if sendDefaultPii is false`() { val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" } sut.configureScope { scope -> @@ -3937,9 +3943,17 @@ class ScopesTest { check { assertEquals("metric name", it.name) - assertNull(it.attributes?.get("user.id")) - assertNull(it.attributes?.get("user.name")) - assertNull(it.attributes?.get("user.email")) + val userId = it.attributes?.get("user.id")!! + assertEquals("usrid", userId.value) + assertEquals("string", userId.type) + + val userName = it.attributes?.get("user.name")!! + assertEquals("usrname", userName.value) + assertEquals("string", userName.type) + + val userEmail = it.attributes?.get("user.email")!! + assertEquals("user@sentry.io", userEmail.value) + assertEquals("string", userEmail.type) }, anyOrNull(), anyOrNull(), @@ -3948,11 +3962,7 @@ class ScopesTest { @Test fun `unset user does provide distinct-id as user-id for metrics`() { - val (sut, mockClient) = - getEnabledScopes { - it.isSendDefaultPii = true - it.distinctId = "distinctId" - } + val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" } sut.metrics().count("metric name") @@ -3972,11 +3982,7 @@ class ScopesTest { @Test fun `unset user does provide null user-id when distinct-id is missing for metrics`() { - val (sut, mockClient) = - getEnabledScopes { - it.isSendDefaultPii = true - it.distinctId = null - } + val (sut, mockClient) = getEnabledScopes { it.distinctId = null } sut.metrics().count("metric name")