Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion sentry/src/main/java/io/sentry/logger/LoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ private void captureLog(
setServerName(attributes);
}

setUser(attributes);
if (scopes.getOptions().isSendDefaultPii()) {
setUser(attributes);
}

return attributes;
}
Expand Down
34 changes: 33 additions & 1 deletion sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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) =
Expand Down
Loading