Skip to content

Commit 7332ada

Browse files
authored
ref(ariadne): Drop support for send_default_pii (#7637)
There's a `data_collection` version of the removed tests. Closes https://linear.app/getsentry/issue/PY-2810/remove-send-default-pii-from-ariadne
1 parent 719a46b commit 7332ada

2 files changed

Lines changed: 52 additions & 220 deletions

File tree

‎sentry_sdk/integrations/ariadne.py‎

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
66
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
77
from sentry_sdk.integrations.logging import ignore_logger_for_events
8-
from sentry_sdk.scope import should_send_default_pii
98
from sentry_sdk.utils import (
109
capture_internal_exceptions,
1110
ensure_integration_enabled,
1211
event_from_exception,
13-
has_data_collection_enabled,
1412
package_version,
1513
)
1614

@@ -138,32 +136,21 @@ def inner(event: "Event", hint: "dict[str, Any]") -> "Event":
138136
return event
139137
client_options = sentry_sdk.get_client().options
140138

141-
if has_data_collection_enabled(client_options):
142-
dc_graphql = client_options["data_collection"]["graphql"]
143-
collect_variables = dc_graphql["variables"]
144-
collect_document = dc_graphql[
145-
"document"
146-
] and request_body_within_bounds(get_client(), content_length)
147-
148-
if collect_document or collect_variables:
149-
request_info = event.setdefault("request", {})
150-
request_info["api_target"] = "graphql"
151-
request_info["data"] = {
152-
key: value
153-
for key, value in data.items()
154-
if (key != "query" or collect_document)
155-
and (key != "variables" or collect_variables)
156-
}
157-
elif event.get("request", {}).get("data"):
158-
del event["request"]["data"]
159-
160-
elif should_send_default_pii() and request_body_within_bounds(
139+
dc_graphql = client_options["data_collection"]["graphql"]
140+
collect_variables = dc_graphql["variables"]
141+
collect_document = dc_graphql["document"] and request_body_within_bounds(
161142
get_client(), content_length
162-
):
143+
)
144+
145+
if collect_document or collect_variables:
163146
request_info = event.setdefault("request", {})
164147
request_info["api_target"] = "graphql"
165-
request_info["data"] = data
166-
148+
request_info["data"] = {
149+
key: value
150+
for key, value in data.items()
151+
if (key != "query" or collect_document)
152+
and (key != "variables" or collect_variables)
153+
}
167154
elif event.get("request", {}).get("data"):
168155
del event["request"]["data"]
169156

@@ -178,13 +165,9 @@ def _make_response_event_processor(response: "Dict[str, Any]") -> "EventProcesso
178165
def inner(event: "Event", hint: "dict[str, Any]") -> "Event":
179166
client_options = sentry_sdk.get_client().options
180167
with capture_internal_exceptions():
181-
if has_data_collection_enabled(client_options):
182-
collect_response = (
183-
"outgoing_response"
184-
in client_options["data_collection"]["http_bodies"]
185-
)
186-
else:
187-
collect_response = should_send_default_pii()
168+
collect_response = (
169+
"outgoing_response" in client_options["data_collection"]["http_bodies"]
170+
)
188171

189172
if collect_response and response.get("errors"):
190173
contexts = event.setdefault("contexts", {})

‎tests/integrations/ariadne/test_ariadne.py‎

Lines changed: 37 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -45,153 +45,9 @@ def resolve_name(obj, *_):
4545
return make_executable_schema(type_defs, query)
4646

4747

48-
def test_capture_request_and_response_if_send_pii_is_on_async(
49-
sentry_init, capture_events
50-
):
51-
sentry_init(
52-
send_default_pii=True,
53-
integrations=[
54-
AriadneIntegration(),
55-
FastApiIntegration(),
56-
StarletteIntegration(),
57-
],
58-
)
59-
events = capture_events()
60-
61-
schema = schema_factory()
62-
63-
async_app = FastAPI()
64-
async_app.mount("/graphql/", GraphQL(schema))
65-
66-
query = {"query": "query ErrorQuery {error}"}
67-
client = TestClient(async_app)
68-
client.post("/graphql", json=query)
69-
70-
assert len(events) == 1
71-
72-
(event,) = events
73-
assert event["exception"]["values"][0]["mechanism"]["type"] == "ariadne"
74-
assert event["contexts"]["response"] == {
75-
"data": {
76-
"data": {"error": None},
77-
"errors": [
78-
{
79-
"locations": [{"column": 19, "line": 1}],
80-
"message": "resolver failed",
81-
"path": ["error"],
82-
}
83-
],
84-
}
85-
}
86-
assert event["request"]["api_target"] == "graphql"
87-
assert event["request"]["data"] == query
88-
89-
90-
def test_capture_request_and_response_if_send_pii_is_on_sync(
91-
sentry_init, capture_events
92-
):
93-
sentry_init(
94-
send_default_pii=True,
95-
integrations=[AriadneIntegration(), FlaskIntegration()],
96-
)
97-
events = capture_events()
98-
99-
schema = schema_factory()
100-
101-
sync_app = Flask(__name__)
102-
103-
@sync_app.route("/graphql", methods=["POST"])
104-
def graphql_server():
105-
data = request.get_json()
106-
success, result = graphql_sync(schema, data)
107-
return jsonify(result), 200
108-
109-
query = {"query": "query ErrorQuery {error}"}
110-
client = sync_app.test_client()
111-
client.post("/graphql", json=query)
112-
113-
assert len(events) == 1
114-
115-
(event,) = events
116-
assert event["exception"]["values"][0]["mechanism"]["type"] == "ariadne"
117-
assert event["contexts"]["response"] == {
118-
"data": {
119-
"data": {"error": None},
120-
"errors": [
121-
{
122-
"locations": [{"column": 19, "line": 1}],
123-
"message": "resolver failed",
124-
"path": ["error"],
125-
}
126-
],
127-
}
128-
}
129-
assert event["request"]["api_target"] == "graphql"
130-
assert event["request"]["data"] == query
131-
132-
133-
def test_do_not_capture_request_and_response_if_send_pii_is_off_async(
134-
sentry_init, capture_events
135-
):
136-
sentry_init(
137-
integrations=[
138-
AriadneIntegration(),
139-
FastApiIntegration(),
140-
StarletteIntegration(),
141-
],
142-
)
143-
events = capture_events()
144-
145-
schema = schema_factory()
146-
147-
async_app = FastAPI()
148-
async_app.mount("/graphql/", GraphQL(schema))
149-
150-
query = {"query": "query ErrorQuery {error}"}
151-
client = TestClient(async_app)
152-
client.post("/graphql", json=query)
153-
154-
assert len(events) == 1
155-
156-
(event,) = events
157-
assert event["exception"]["values"][0]["mechanism"]["type"] == "ariadne"
158-
assert "data" not in event["request"]
159-
assert "response" not in event["contexts"]
160-
161-
162-
def test_do_not_capture_request_and_response_if_send_pii_is_off_sync(
163-
sentry_init, capture_events
164-
):
165-
sentry_init(
166-
integrations=[AriadneIntegration(), FlaskIntegration()],
167-
)
168-
events = capture_events()
169-
170-
schema = schema_factory()
171-
172-
sync_app = Flask(__name__)
173-
174-
@sync_app.route("/graphql", methods=["POST"])
175-
def graphql_server():
176-
data = request.get_json()
177-
success, result = graphql_sync(schema, data)
178-
return jsonify(result), 200
179-
180-
query = {"query": "query ErrorQuery {error}"}
181-
client = sync_app.test_client()
182-
client.post("/graphql", json=query)
183-
184-
assert len(events) == 1
185-
186-
(event,) = events
187-
assert event["exception"]["values"][0]["mechanism"]["type"] == "ariadne"
188-
assert "data" not in event["request"]
189-
assert "response" not in event["contexts"]
190-
191-
19248
def test_capture_validation_error(sentry_init, capture_events):
19349
sentry_init(
194-
send_default_pii=True,
50+
data_collection={},
19551
integrations=[
19652
AriadneIntegration(),
19753
FastApiIntegration(),
@@ -234,6 +90,7 @@ def test_no_event_if_no_errors_async(sentry_init, capture_events):
23490
FastApiIntegration(),
23591
StarletteIntegration(),
23692
],
93+
data_collection={},
23794
)
23895
events = capture_events()
23996

@@ -255,6 +112,7 @@ def test_no_event_if_no_errors_async(sentry_init, capture_events):
255112
def test_no_event_if_no_errors_sync(sentry_init, capture_events):
256113
sentry_init(
257114
integrations=[AriadneIntegration(), FlaskIntegration()],
115+
data_collection={},
258116
)
259117
events = capture_events()
260118

@@ -310,80 +168,58 @@ def graphql_server():
310168
return make_client
311169

312170

313-
def _init_all_integrations(sentry_init, **kwargs):
314-
sentry_init(
315-
integrations=[
316-
AriadneIntegration(),
317-
FlaskIntegration(),
318-
FastApiIntegration(),
319-
StarletteIntegration(),
320-
],
321-
**kwargs,
322-
)
323-
324-
325171
@pytest.mark.parametrize(
326-
"init_kwargs,expect_query,expect_variables",
172+
"data_collection,expect_query,expect_variables",
327173
[
328174
pytest.param(
329-
{"data_collection": {}},
175+
{},
330176
True,
331177
True,
332178
id="data_collection_defaults",
333179
),
334180
pytest.param(
335-
{"data_collection": {"graphql": {"document": True, "variables": True}}},
181+
{"graphql": {"document": True, "variables": True}},
336182
True,
337183
True,
338184
id="document_on_variables_on",
339185
),
340186
pytest.param(
341-
{"data_collection": {"graphql": {"document": False}}},
187+
{"graphql": {"document": False}},
342188
False,
343189
True,
344190
id="document_off_variables_on",
345191
),
346192
pytest.param(
347-
{"data_collection": {"graphql": {"variables": False}}},
193+
{"graphql": {"variables": False}},
348194
True,
349195
False,
350196
id="document_on_variables_off",
351197
),
352198
pytest.param(
353-
{"data_collection": {"graphql": {"document": False, "variables": False}}},
199+
{"graphql": {"document": False, "variables": False}},
354200
None,
355201
None,
356202
id="document_off_variables_off",
357203
),
358-
pytest.param(
359-
{
360-
"send_default_pii": True,
361-
"data_collection": {"graphql": {"document": False}},
362-
},
363-
False,
364-
True,
365-
id="data_collection_takes_precedence_over_send_default_pii_on",
366-
),
367-
pytest.param(
368-
{
369-
"send_default_pii": False,
370-
"data_collection": {"graphql": {"document": True}},
371-
},
372-
True,
373-
True,
374-
id="data_collection_takes_precedence_over_send_default_pii_off",
375-
),
376204
],
377205
)
378206
def test_request_data_collection(
379207
sentry_init,
380208
capture_events,
381209
graphql_client,
382-
init_kwargs,
210+
data_collection,
383211
expect_query,
384212
expect_variables,
385213
):
386-
_init_all_integrations(sentry_init, **init_kwargs)
214+
sentry_init(
215+
integrations=[
216+
AriadneIntegration(),
217+
FlaskIntegration(),
218+
FastApiIntegration(),
219+
StarletteIntegration(),
220+
],
221+
data_collection=data_collection,
222+
)
387223
events = capture_events()
388224

389225
graphql_client().post("/graphql", json=ERROR_QUERY_WITH_VARIABLES)
@@ -411,10 +247,15 @@ def test_request_data_collection_body_out_of_bounds_still_collects_variables(
411247
dropped but variables (which are not subject to the bounds check) are
412248
still collected.
413249
"""
414-
_init_all_integrations(
415-
sentry_init,
416-
max_request_body_size="small",
250+
sentry_init(
251+
integrations=[
252+
AriadneIntegration(),
253+
FlaskIntegration(),
254+
FastApiIntegration(),
255+
StarletteIntegration(),
256+
],
417257
data_collection={},
258+
max_request_body_size="small",
418259
)
419260
events = capture_events()
420261

@@ -443,8 +284,16 @@ def test_request_data_collection_body_out_of_bounds_still_collects_variables(
443284
def test_response_data_collection(
444285
sentry_init, capture_events, graphql_client, http_bodies, expect_response
445286
):
446-
data_collection = {} if http_bodies is None else {"http_bodies": http_bodies}
447-
_init_all_integrations(sentry_init, data_collection=data_collection)
287+
sentry_init(
288+
integrations=[
289+
AriadneIntegration(),
290+
FlaskIntegration(),
291+
FastApiIntegration(),
292+
StarletteIntegration(),
293+
],
294+
data_collection={} if http_bodies is None else {"http_bodies": http_bodies},
295+
)
296+
448297
events = capture_events()
449298

450299
graphql_client().post("/graphql", json={"query": "query ErrorQuery {error}"})

0 commit comments

Comments
 (0)