File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
main/java/io/sentry/logger Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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+ 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) =
You can’t perform that action at this time.
0 commit comments