File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ def test_metrics_with_attributes(sentry_init, capture_envelopes):
117117
118118
119119def test_metrics_with_user (sentry_init , capture_envelopes ):
120- sentry_init ()
120+ sentry_init (send_default_pii = True )
121121 envelopes = capture_envelopes ()
122122
123123 sentry_sdk .set_user (
@@ -135,6 +135,25 @@ def test_metrics_with_user(sentry_init, capture_envelopes):
135135 assert metrics [0 ]["attributes" ]["user.name" ] == "testuser"
136136
137137
138+ def test_metrics_no_user_if_pii_off (sentry_init , capture_envelopes ):
139+ sentry_init (send_default_pii = False )
140+ envelopes = capture_envelopes ()
141+
142+ sentry_sdk .set_user (
143+ {"id" : "user-123" , "email" : "test@example.com" , "username" : "testuser" }
144+ )
145+ sentry_sdk .metrics .count ("test.user.counter" , 1 )
146+
147+ get_client ().flush ()
148+
149+ metrics = envelopes_to_metrics (envelopes )
150+ assert len (metrics ) == 1
151+
152+ assert "user.id" not in metrics [0 ]["attributes" ]
153+ assert "user.email" not in metrics [0 ]["attributes" ]
154+ assert "user.name" not in metrics [0 ]["attributes" ]
155+
156+
138157def test_metrics_with_span (sentry_init , capture_envelopes ):
139158 sentry_init (traces_sample_rate = 1.0 )
140159 envelopes = capture_envelopes ()
You can’t perform that action at this time.
0 commit comments