Skip to content

Commit 8107c75

Browse files
authored
fix(logs): Check sendDefaultPii before attaching user attributes (#5036)
* Check sendDefaultPii before attaching user attributes to logs * changelog * move changelog entry to fixes
1 parent 804bd88 commit 8107c75

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- 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))
88

9+
### Fixes
10+
11+
- Only attach user attributes to logs if `sendDefaultPii` is enabled ([#5036](https://github.com/getsentry/sentry-java/pull/5036))
12+
913
### Dependencies
1014

1115
- Bump Native SDK from v0.12.2 to v0.12.3 ([#5012](https://github.com/getsentry/sentry-java/pull/5012))

sentry/src/main/java/io/sentry/logger/LoggerApi.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ private void captureLog(
247247
setServerName(attributes);
248248
}
249249

250-
setUser(attributes);
250+
if (scopes.getOptions().isSendDefaultPii()) {
251+
setUser(attributes);
252+
}
251253

252254
return attributes;
253255
}

sentry/src/test/java/io/sentry/ScopesTest.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,11 +2913,12 @@ class ScopesTest {
29132913
}
29142914

29152915
@Test
2916-
fun `adds user fields to log attributes`() {
2916+
fun `adds user fields to log attributes if sendDefaultPii is true`() {
29172917
val (sut, mockClient) =
29182918
getEnabledScopes {
29192919
it.logs.isEnabled = true
29202920
it.distinctId = "distinctId"
2921+
it.isSendDefaultPii = true
29212922
}
29222923

29232924
sut.configureScope { scope ->
@@ -2951,6 +2952,37 @@ class ScopesTest {
29512952
)
29522953
}
29532954

2955+
@Test
2956+
fun `does not add user fields to log attributes by default`() {
2957+
val (sut, mockClient) =
2958+
getEnabledScopes {
2959+
it.logs.isEnabled = true
2960+
it.distinctId = "distinctId"
2961+
}
2962+
2963+
sut.configureScope { scope ->
2964+
scope.user =
2965+
User().also {
2966+
it.id = "usrid"
2967+
it.username = "usrname"
2968+
it.email = "[email protected]"
2969+
}
2970+
}
2971+
sut.logger().log(SentryLogLevel.WARN, "log message")
2972+
2973+
verify(mockClient)
2974+
.captureLog(
2975+
check {
2976+
assertEquals("log message", it.body)
2977+
2978+
assertNull(it.attributes?.get("user.id"))
2979+
assertNull(it.attributes?.get("user.name"))
2980+
assertNull(it.attributes?.get("user.email"))
2981+
},
2982+
anyOrNull(),
2983+
)
2984+
}
2985+
29542986
@Test
29552987
fun `unset user does provide distinct-id as user-id`() {
29562988
val (sut, mockClient) =

0 commit comments

Comments
 (0)