Skip to content

Commit d30fa1d

Browse files
committed
data_collection tests
1 parent 8080f0c commit d30fa1d

2 files changed

Lines changed: 36 additions & 172 deletions

File tree

‎tests/test_data_collection.py‎

Lines changed: 35 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
import pytest
42

53
import sentry_sdk
@@ -94,42 +92,10 @@ def _get(dc, path):
9492

9593

9694
@pytest.mark.parametrize(
97-
"options,expected",
95+
"data_collection,expected",
9896
[
9997
pytest.param(
10098
{},
101-
{
102-
"user_info": False,
103-
"gen_ai.inputs": False,
104-
"gen_ai.outputs": False,
105-
"cookies.mode": "denylist",
106-
"url_query_params.mode": "denylist",
107-
"http_headers.request.mode": "denylist",
108-
"http_bodies": _ALL_HTTP_BODY_TYPES,
109-
"queues": False,
110-
"frame_context_lines": 5,
111-
},
112-
id="no_options_collects_no_pii",
113-
),
114-
pytest.param(
115-
{"send_default_pii": True},
116-
{
117-
"user_info": True,
118-
"gen_ai.inputs": True,
119-
"gen_ai.outputs": True,
120-
"cookies.mode": "denylist",
121-
"url_query_params.mode": "denylist",
122-
"queues": True,
123-
},
124-
id="send_default_pii_true_collects_pii",
125-
),
126-
pytest.param(
127-
{"send_default_pii": False},
128-
{"user_info": False, "cookies.mode": "denylist", "queues": False},
129-
id="send_default_pii_false_collects_no_pii",
130-
),
131-
pytest.param(
132-
{"data_collection": {}},
13399
{
134100
"user_info": True,
135101
"gen_ai.inputs": True,
@@ -142,7 +108,7 @@ def _get(dc, path):
142108
id="explicit_data_collection_uses_spec_defaults",
143109
),
144110
pytest.param(
145-
{"data_collection": {"user_info": False, "http_bodies": []}},
111+
{"user_info": False, "http_bodies": []},
146112
{
147113
"user_info": False,
148114
"http_bodies": [],
@@ -153,12 +119,10 @@ def _get(dc, path):
153119
),
154120
pytest.param(
155121
{
156-
"data_collection": {
157-
"cookies": {"mode": "off"},
158-
"url_query_params": {"mode": "allowlist", "terms": ["page"]},
159-
"http_headers": {"request": {"mode": "off"}},
160-
"gen_ai": {"inputs": False, "outputs": True},
161-
}
122+
"cookies": {"mode": "off"},
123+
"url_query_params": {"mode": "allowlist", "terms": ["page"]},
124+
"http_headers": {"request": {"mode": "off"}},
125+
"gen_ai": {"inputs": False, "outputs": True},
162126
},
163127
{
164128
"cookies.mode": "off",
@@ -172,13 +136,11 @@ def _get(dc, path):
172136
),
173137
pytest.param(
174138
{
175-
"data_collection": {
176-
"cookies": None,
177-
"http_headers": None,
178-
"url_query_params": None,
179-
"graphql": None,
180-
"gen_ai": None,
181-
}
139+
"cookies": None,
140+
"http_headers": None,
141+
"url_query_params": None,
142+
"graphql": None,
143+
"gen_ai": None,
182144
},
183145
{
184146
"cookies.mode": "denylist",
@@ -192,7 +154,7 @@ def _get(dc, path):
192154
id="none_values_fall_back_to_spec_defaults",
193155
),
194156
pytest.param(
195-
{"data_collection": {}},
157+
{},
196158
{
197159
"graphql.document": True,
198160
"graphql.variables": True,
@@ -201,67 +163,45 @@ def _get(dc, path):
201163
id="explicit_graphql_database_defaults",
202164
),
203165
pytest.param(
204-
{"send_default_pii": False},
205-
{
206-
"graphql.document": False,
207-
"graphql.variables": False,
208-
"database_query_data": False,
209-
"queues": False,
210-
},
211-
id="legacy_pii_off_gates_graphql_database_and_queues",
212-
),
213-
pytest.param(
214-
{"send_default_pii": True},
215-
{
216-
"graphql.document": True,
217-
"graphql.variables": True,
218-
"database_query_data": True,
219-
"queues": True,
220-
},
221-
id="legacy_pii_on_collects_graphql_database_and_queues",
222-
),
223-
pytest.param(
224-
{"data_collection": {"graphql": {"variables": False}}},
166+
{"graphql": {"variables": False}},
225167
{"graphql.document": True, "graphql.variables": False},
226168
id="explicit_partial_graphql_fills_omitted",
227169
),
228170
pytest.param(
229-
{"data_collection": {"frame_context_lines": True}},
171+
{"frame_context_lines": True},
230172
{"frame_context_lines": 5},
231173
id="frame_context_lines_bool_fallback_true",
232174
),
233175
pytest.param(
234-
{"data_collection": {"frame_context_lines": False}},
176+
{"frame_context_lines": False},
235177
{"frame_context_lines": 0},
236178
id="frame_context_lines_bool_fallback_false",
237179
),
238180
pytest.param(
239-
{"data_collection": {"frame_context_lines": 3}},
181+
{"frame_context_lines": 3},
240182
{"frame_context_lines": 3},
241183
id="frame_context_lines_bool_fallback_3",
242184
),
243185
pytest.param(
244-
{"data_collection": {"frame_context_lines": 0}},
186+
{"frame_context_lines": 0},
245187
{"frame_context_lines": 0},
246188
id="frame_context_lines_bool_fallback_0",
247189
),
248190
pytest.param(
249-
{"data_collection": {"stack_frame_variables": True}},
191+
{"stack_frame_variables": True},
250192
{"stack_frame_variables": True},
251193
id="stack_frame_variables_explicit_true",
252194
),
253195
pytest.param(
254-
{"data_collection": {"stack_frame_variables": False}},
196+
{"stack_frame_variables": False},
255197
{"stack_frame_variables": False},
256198
id="stack_frame_variables_explicit_false",
257199
),
258200
pytest.param(
259201
{
260-
"data_collection": {
261-
"stack_frame_variables": {
262-
"mode": "allowlist",
263-
"terms": ["order_id"],
264-
}
202+
"stack_frame_variables": {
203+
"mode": "allowlist",
204+
"terms": ["order_id"],
265205
}
266206
},
267207
{
@@ -273,7 +213,7 @@ def _get(dc, path):
273213
id="stack_frame_variables_allowlist_dict",
274214
),
275215
pytest.param(
276-
{"data_collection": {"stack_frame_variables": {"terms": ["order_id"]}}},
216+
{"stack_frame_variables": {"terms": ["order_id"]}},
277217
{
278218
"stack_frame_variables": {
279219
"mode": "denylist",
@@ -283,64 +223,36 @@ def _get(dc, path):
283223
id="stack_frame_variables_dict_defaults_mode_to_denylist",
284224
),
285225
pytest.param(
286-
{"data_collection": {"stack_frame_variables": {"mode": "off"}}},
226+
{"stack_frame_variables": {"mode": "off"}},
287227
{"stack_frame_variables": {"mode": "off"}},
288228
id="stack_frame_variables_off_dict_omits_terms",
289229
),
290230
pytest.param(
291-
{"data_collection": {"stack_frame_variables": "yes"}},
231+
{"stack_frame_variables": "yes"},
292232
{"stack_frame_variables": True},
293233
id="stack_frame_variables_non_bool_truthy_coerces_to_true",
294234
),
295235
pytest.param(
296-
{"data_collection": {"stack_frame_variables": ""}},
236+
{"stack_frame_variables": ""},
297237
{"stack_frame_variables": False},
298238
id="stack_frame_variables_non_bool_falsy_coerces_to_false",
299239
),
300240
pytest.param(
301-
{"data_collection": {"frame_context_lines": None}},
241+
{"frame_context_lines": None},
302242
{"frame_context_lines": 5},
303243
id="frame_context_lines_none_falls_back_to_spec_default",
304244
),
305245
],
306246
)
307-
def test_initialize_client_data_collection(sentry_init, options, expected):
308-
dc = _initialize_client_with_config(sentry_init, **options)
247+
def test_initialize_client_data_collection(sentry_init, data_collection, expected):
248+
dc = _initialize_client_with_config(sentry_init, data_collection=data_collection)
309249
for path, value in expected.items():
310250
assert _get(dc, path) == value, f"{path} != {value!r}"
311251

312252

313-
def test_initialize_client_data_collection_overrides_send_default_pii_and_warns(
314-
sentry_init,
315-
):
316-
with warnings.catch_warnings(record=True) as caught:
317-
warnings.simplefilter("always")
318-
dc = _initialize_client_with_config(
319-
sentry_init,
320-
send_default_pii=True,
321-
data_collection={"user_info": False},
322-
)
323-
assert dc["user_info"] is False # data_collection wins
324-
assert any(issubclass(w.category, DeprecationWarning) for w in caught)
325-
326-
327253
@pytest.mark.parametrize(
328254
"init_kwargs,expected",
329255
[
330-
pytest.param(
331-
{},
332-
{
333-
"user_info": False,
334-
"provided_by_user": False,
335-
"should_send_default_pii": False,
336-
},
337-
id="defaults_to_no_pii",
338-
),
339-
pytest.param(
340-
{"send_default_pii": True},
341-
{"user_info": True, "provided_by_user": False},
342-
id="send_default_pii_enables_user_info",
343-
),
344256
pytest.param(
345257
{"data_collection": {"user_info": False}},
346258
{"user_info": False, "provided_by_user": True},
@@ -365,10 +277,7 @@ def test_client_data_collection_settings(sentry_init, init_kwargs, expected):
365277
sentry_init(**init_kwargs)
366278
client = sentry_sdk.get_client()
367279
for key, value in expected.items():
368-
if key == "should_send_default_pii":
369-
assert client.should_send_default_pii() is value
370-
else:
371-
assert client.options["data_collection"][key] is value
280+
assert client.options["data_collection"][key] is value
372281

373282

374283
def test_has_data_collection_enabled_gates_on_user_provided_config():
@@ -390,37 +299,23 @@ def test_has_data_collection_enabled_gates_on_user_provided_config():
390299

391300

392301
@pytest.mark.parametrize(
393-
"init_kwargs, expected",
302+
"data_collection, expected",
394303
[
395-
pytest.param({}, False, id="no_config"),
396-
pytest.param({"send_default_pii": True}, False, id="send_default_pii_true"),
397-
pytest.param({"send_default_pii": False}, False, id="send_default_pii_false"),
398-
pytest.param({"data_collection": {}}, True, id="empty_data_collection"),
304+
pytest.param({}, True, id="empty_data_collection"),
399305
pytest.param(
400-
{"data_collection": {"user_info": False}},
306+
{"user_info": False},
401307
True,
402308
id="partial_data_collection",
403309
),
404310
],
405311
)
406312
def test_has_data_collection_enabled_after_resolution(
407-
sentry_init, init_kwargs, expected
313+
sentry_init, data_collection, expected
408314
):
409-
sentry_init(**init_kwargs)
315+
sentry_init(data_collection=data_collection)
410316
assert has_data_collection_enabled(sentry_sdk.get_client().options) is expected
411317

412318

413-
def test_no_data_collection_values_fall_back_to_send_default_pii_configuration(
414-
sentry_init,
415-
):
416-
sentry_init(send_default_pii=True)
417-
client = sentry_sdk.get_client()
418-
dc = client.options["data_collection"]
419-
assert dc["provided_by_user"] is False
420-
assert dc["user_info"] is True
421-
assert has_data_collection_enabled(client.options) is False
422-
423-
424319
def test_data_collection_via_experiments(sentry_init):
425320
sentry_init(
426321
_experiments={"data_collection": {"user_info": True}},

‎tests/test_scope.py‎

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
ScopeType,
1717
register_external_propagation_context,
1818
remove_external_propagation_context,
19-
should_send_default_pii,
2019
use_isolation_scope,
2120
use_scope,
2221
)
@@ -86,7 +85,7 @@ def test_set_user_none_values_are_dropped_when_copying_to_attributes(
8685
):
8786
sentry_init(
8887
traces_sample_rate=1.0,
89-
send_default_pii=True,
88+
data_collection={"user_info": True},
9089
)
9190
items = capture_items("span")
9291

@@ -826,36 +825,6 @@ def test_with_use_scope_data():
826825
}
827826

828827

829-
def test_should_send_default_pii_true(sentry_init):
830-
sentry_init(send_default_pii=True)
831-
832-
assert should_send_default_pii() is True
833-
834-
835-
def test_should_send_default_pii_false(sentry_init):
836-
sentry_init(send_default_pii=False)
837-
838-
assert should_send_default_pii() is False
839-
840-
841-
def test_should_send_default_pii_default_false(sentry_init):
842-
sentry_init()
843-
844-
assert should_send_default_pii() is False
845-
846-
847-
def test_should_send_default_pii_false_with_dsn_and_spotlight(sentry_init):
848-
sentry_init(dsn="http://key@localhost/1", spotlight=True)
849-
850-
assert should_send_default_pii() is False
851-
852-
853-
def test_should_send_default_pii_true_without_dsn_and_spotlight(sentry_init):
854-
sentry_init(spotlight=True)
855-
856-
assert should_send_default_pii() is True
857-
858-
859828
def test_set_tags():
860829
scope = Scope()
861830
scope.set_tags({"tag1": "value1", "tag2": "value2"})

0 commit comments

Comments
 (0)