Skip to content

Commit b622a9a

Browse files
committed
metrics test
1 parent a11a35d commit b622a9a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/test_metrics.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_metrics_with_attributes(sentry_init, capture_envelopes):
117117

118118

119119
def 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+
138157
def test_metrics_with_span(sentry_init, capture_envelopes):
139158
sentry_init(traces_sample_rate=1.0)
140159
envelopes = capture_envelopes()

0 commit comments

Comments
 (0)