Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 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