diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aca5108ab..c367f7d943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Added `io.sentry.ndk.sdk-name` Android manifest option to configure the native SDK's name ([#5027](https://github.com/getsentry/sentry-java/pull/5027)) +### Fixes + +- Only attach user attributes to logs if `sendDefaultPii` is enabled ([#5036](https://github.com/getsentry/sentry-java/pull/5036)) + ### Dependencies - Bump Native SDK from v0.12.2 to v0.12.3 ([#5012](https://github.com/getsentry/sentry-java/pull/5012)) diff --git a/sentry/src/main/java/io/sentry/logger/LoggerApi.java b/sentry/src/main/java/io/sentry/logger/LoggerApi.java index 568bd6ac05..31561e22c7 100644 --- a/sentry/src/main/java/io/sentry/logger/LoggerApi.java +++ b/sentry/src/main/java/io/sentry/logger/LoggerApi.java @@ -247,7 +247,9 @@ private void captureLog( setServerName(attributes); } - setUser(attributes); + if (scopes.getOptions().isSendDefaultPii()) { + 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 81f639e8a1..07a7c15779 100644 --- a/sentry/src/test/java/io/sentry/ScopesTest.kt +++ b/sentry/src/test/java/io/sentry/ScopesTest.kt @@ -2913,11 +2913,12 @@ class ScopesTest { } @Test - fun `adds user fields to log attributes`() { + fun `adds user fields to log attributes if sendDefaultPii is true`() { val (sut, mockClient) = getEnabledScopes { it.logs.isEnabled = true it.distinctId = "distinctId" + it.isSendDefaultPii = true } sut.configureScope { scope -> @@ -2951,6 +2952,37 @@ class ScopesTest { ) } + @Test + fun `does not add user fields to log attributes by default`() { + val (sut, mockClient) = + getEnabledScopes { + it.logs.isEnabled = true + it.distinctId = "distinctId" + } + + sut.configureScope { scope -> + scope.user = + User().also { + it.id = "usrid" + it.username = "usrname" + it.email = "user@sentry.io" + } + } + sut.logger().log(SentryLogLevel.WARN, "log message") + + verify(mockClient) + .captureLog( + check { + assertEquals("log message", it.body) + + assertNull(it.attributes?.get("user.id")) + assertNull(it.attributes?.get("user.name")) + assertNull(it.attributes?.get("user.email")) + }, + anyOrNull(), + ) + } + @Test fun `unset user does provide distinct-id as user-id`() { val (sut, mockClient) =