From 766f14508d208828e5ac90b6344c65200be03b85 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 2 Oct 2026 12:18:12 +0200 Subject: [PATCH] ref(httpx2): Drop `send_default_pii` support --- sentry_sdk/integrations/httpx2.py | 6 +- tests/integrations/httpx2/test_httpx2.py | 655 ++++++----------------- 2 files changed, 169 insertions(+), 492 deletions(-) diff --git a/sentry_sdk/integrations/httpx2.py b/sentry_sdk/integrations/httpx2.py index 34804f7b03..2f382601a3 100644 --- a/sentry_sdk/integrations/httpx2.py +++ b/sentry_sdk/integrations/httpx2.py @@ -7,7 +7,7 @@ from sentry_sdk.tracing_utils import ( add_http_breadcrumb, add_http_request_source, - get_url_attributes_legacy, + get_url_attributes, propagate_trace_headers, ) from sentry_sdk.utils import ( @@ -59,7 +59,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response": with capture_internal_exceptions(): parsed_url = parse_url(str(request.url), sanitize=False) - url_attributes = get_url_attributes_legacy(client, parsed_url) + url_attributes = get_url_attributes(client, parsed_url) if sentry_sdk.get_current_span() is None: span_ctx = nullcontext() @@ -148,7 +148,7 @@ async def send( }, ) - url_attributes = get_url_attributes_legacy(client, parsed_url) + url_attributes = get_url_attributes(client, parsed_url) with span_ctx as span: propagate_trace_headers(client, request) diff --git a/tests/integrations/httpx2/test_httpx2.py b/tests/integrations/httpx2/test_httpx2.py index 2008145bd0..11f3a4a3e7 100644 --- a/tests/integrations/httpx2/test_httpx2.py +++ b/tests/integrations/httpx2/test_httpx2.py @@ -19,10 +19,7 @@ def _get_http_client_span(items): ) -@pytest.mark.parametrize("send_default_pii", [True, False]) -def test_crumb_capture_and_hint_sync( - sentry_init, capture_events, httpx2_mock, send_default_pii -): +def test_crumb_capture_and_hint_sync(sentry_init, capture_events, httpx2_mock): httpx2_mock.add_response() def before_breadcrumb(crumb, hint): @@ -32,7 +29,7 @@ def before_breadcrumb(crumb, hint): sentry_init( integrations=[Httpx2Integration()], before_breadcrumb=before_breadcrumb, - send_default_pii=send_default_pii, + data_collection={}, ) url = "http://example.com/" @@ -51,34 +48,21 @@ def before_breadcrumb(crumb, hint): assert crumb["type"] == "http" assert crumb["category"] == "httplib" - if send_default_pii: - assert crumb["data"] == ApproxDict( - { - "url": url, - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_FRAGMENT: "", - SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: 200, - "reason": "OK", - "extra": "foo", - } - ) - else: - assert crumb["data"] == ApproxDict( - { - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: 200, - "reason": "OK", - "extra": "foo", - } - ) + assert crumb["data"] == ApproxDict( + { + "url": url, + SPANDATA.HTTP_METHOD: "GET", + SPANDATA.HTTP_FRAGMENT: "", + SPANDATA.HTTP_QUERY: "", + SPANDATA.HTTP_STATUS_CODE: 200, + "reason": "OK", + "extra": "foo", + } + ) @pytest.mark.asyncio -@pytest.mark.parametrize("send_default_pii", [True, False]) -async def test_crumb_capture_and_hint_async( - sentry_init, capture_events, httpx2_mock, send_default_pii -): +async def test_crumb_capture_and_hint_async(sentry_init, capture_events, httpx2_mock): httpx2_mock.add_response() def before_breadcrumb(crumb, hint): @@ -88,7 +72,7 @@ def before_breadcrumb(crumb, hint): sentry_init( integrations=[Httpx2Integration()], before_breadcrumb=before_breadcrumb, - send_default_pii=send_default_pii, + data_collection={}, ) url = "http://example.com/" @@ -106,27 +90,17 @@ def before_breadcrumb(crumb, hint): crumb = event["breadcrumbs"]["values"][0] assert crumb["type"] == "http" assert crumb["category"] == "httplib" - if send_default_pii: - assert crumb["data"] == ApproxDict( - { - "url": url, - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_FRAGMENT: "", - SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: 200, - "reason": "OK", - "extra": "foo", - } - ) - else: - assert crumb["data"] == ApproxDict( - { - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: 200, - "reason": "OK", - "extra": "foo", - } - ) + assert crumb["data"] == ApproxDict( + { + "url": url, + SPANDATA.HTTP_METHOD: "GET", + SPANDATA.HTTP_FRAGMENT: "", + SPANDATA.HTTP_QUERY: "", + SPANDATA.HTTP_STATUS_CODE: 200, + "reason": "OK", + "extra": "foo", + } + ) def test_crumb_capture_without_span_sync(sentry_init, capture_events, httpx2_mock): @@ -206,15 +180,14 @@ async def test_crumb_capture_without_span_async( (500, "error"), ], ) -@pytest.mark.parametrize("send_default_pii", [True, False]) def test_crumb_capture_client_error_sync( - sentry_init, capture_events, httpx2_mock, status_code, level, send_default_pii + sentry_init, capture_events, httpx2_mock, status_code, level ): httpx2_mock.add_response(status_code=status_code) sentry_init( integrations=[Httpx2Integration()], - send_default_pii=send_default_pii, + data_collection={}, ) url = "http://example.com/" @@ -238,23 +211,15 @@ def test_crumb_capture_client_error_sync( else: assert crumb["level"] == level - if send_default_pii: - assert crumb["data"] == ApproxDict( - { - "url": url, - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_FRAGMENT: "", - SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: status_code, - } - ) - else: - assert crumb["data"] == ApproxDict( - { - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: status_code, - } - ) + assert crumb["data"] == ApproxDict( + { + "url": url, + SPANDATA.HTTP_METHOD: "GET", + SPANDATA.HTTP_FRAGMENT: "", + SPANDATA.HTTP_QUERY: "", + SPANDATA.HTTP_STATUS_CODE: status_code, + } + ) @pytest.mark.asyncio @@ -268,15 +233,14 @@ def test_crumb_capture_client_error_sync( (500, "error"), ], ) -@pytest.mark.parametrize("send_default_pii", [True, False]) async def test_crumb_capture_client_error_async( - sentry_init, capture_events, httpx2_mock, status_code, level, send_default_pii + sentry_init, capture_events, httpx2_mock, status_code, level ): httpx2_mock.add_response(status_code=status_code) sentry_init( integrations=[Httpx2Integration()], - send_default_pii=send_default_pii, + data_collection={}, ) url = "http://example.com/" @@ -300,23 +264,15 @@ async def test_crumb_capture_client_error_async( else: assert crumb["level"] == level - if send_default_pii: - assert crumb["data"] == ApproxDict( - { - "url": url, - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_FRAGMENT: "", - SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: status_code, - } - ) - else: - assert crumb["data"] == ApproxDict( - { - SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: status_code, - } - ) + assert crumb["data"] == ApproxDict( + { + "url": url, + SPANDATA.HTTP_METHOD: "GET", + SPANDATA.HTTP_FRAGMENT: "", + SPANDATA.HTTP_QUERY: "", + SPANDATA.HTTP_STATUS_CODE: status_code, + } + ) @pytest.mark.parametrize( @@ -1182,13 +1138,37 @@ async def test_span_origin_async(sentry_init, capture_items, httpx2_mock): assert http_span["attributes"]["sentry.origin"] == "auto.http.httpx2" -def test_http_url_attributes_sync(sentry_init, capture_items, httpx2_mock): +@pytest.mark.parametrize( + "data_collection,expected_url_full,expected_query", + [ + pytest.param( + {}, + "http://example.com/?foo=bar#frag", + "foo=bar", + id="data_collection_defaults", + ), + pytest.param( + {"url_query_params": {"mode": "off"}}, + "http://example.com/#frag", + None, + id="data_collection_query_off", + ), + ], +) +def test_http_url_attributes_sync( + sentry_init, + capture_items, + httpx2_mock, + data_collection, + expected_url_full, + expected_query, +): httpx2_mock.add_response() sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - send_default_pii=True, + data_collection=data_collection, ) items = capture_items("span") @@ -1203,20 +1183,47 @@ def test_http_url_attributes_sync(sentry_init, capture_items, httpx2_mock): http_span = _get_http_client_span(items) assert http_span["attributes"]["http.request.method"] == "GET" - assert http_span["attributes"]["url.full"] == "http://example.com/?foo=bar#frag" - assert http_span["attributes"]["url.query"] == "foo=bar" + assert http_span["attributes"]["url.full"] == expected_url_full + if expected_query is not None: + assert http_span["attributes"]["url.query"] == expected_query + else: + assert "url.query" not in http_span["attributes"] assert http_span["attributes"]["url.fragment"] == "frag" assert http_span["attributes"]["http.response.status_code"] == 200 @pytest.mark.asyncio -async def test_http_url_attributes_async(sentry_init, capture_items, httpx2_mock): +@pytest.mark.parametrize( + "data_collection,expected_url_full,expected_query", + [ + pytest.param( + {}, + "http://example.com/?foo=bar#frag", + "foo=bar", + id="data_collection_defaults", + ), + pytest.param( + {"url_query_params": {"mode": "off"}}, + "http://example.com/#frag", + None, + id="data_collection_query_off", + ), + ], +) +async def test_http_url_attributes_async( + sentry_init, + capture_items, + httpx2_mock, + data_collection, + expected_url_full, + expected_query, +): httpx2_mock.add_response() sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - send_default_pii=True, + data_collection=data_collection, ) items = capture_items("span") @@ -1231,8 +1238,11 @@ async def test_http_url_attributes_async(sentry_init, capture_items, httpx2_mock http_span = _get_http_client_span(items) assert http_span["attributes"]["http.request.method"] == "GET" - assert http_span["attributes"]["url.full"] == "http://example.com/?foo=bar#frag" - assert http_span["attributes"]["url.query"] == "foo=bar" + assert http_span["attributes"]["url.full"] == expected_url_full + if expected_query is not None: + assert http_span["attributes"]["url.query"] == expected_query + else: + assert "url.query" not in http_span["attributes"] assert http_span["attributes"]["url.fragment"] == "frag" assert http_span["attributes"]["http.response.status_code"] == 200 @@ -1245,7 +1255,7 @@ def test_http_url_attributes_no_query_or_fragment_sync( sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, ) items = capture_items("span") @@ -1275,7 +1285,7 @@ async def test_http_url_attributes_no_query_or_fragment_async( sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - send_default_pii=True, + data_collection={}, ) items = capture_items("span") @@ -1296,135 +1306,55 @@ async def test_http_url_attributes_no_query_or_fragment_async( assert http_span["attributes"]["http.response.status_code"] == 200 -def test_http_url_attributes_pii_disabled_sync(sentry_init, capture_items, httpx2_mock): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - ) - - items = capture_items("span") - - url = "http://example.com/?foo=bar#frag" - - with sentry_sdk.start_span(name="test"): - httpx2.Client().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - - assert http_span["attributes"]["http.request.method"] == "GET" - assert "url.full" not in http_span["attributes"] - assert "url.query" not in http_span["attributes"] - assert "url.fragment" not in http_span["attributes"] - assert http_span["attributes"]["http.response.status_code"] == 200 - - -@pytest.mark.asyncio -async def test_http_url_attributes_pii_disabled_async( - sentry_init, capture_items, httpx2_mock -): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - ) - - items = capture_items("span") - - url = "http://example.com/?foo=bar#frag" - - with sentry_sdk.start_span(name="test"): - await httpx2.AsyncClient().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - - assert http_span["attributes"]["http.request.method"] == "GET" - assert "url.full" not in http_span["attributes"] - assert "url.query" not in http_span["attributes"] - assert "url.fragment" not in http_span["attributes"] - assert http_span["attributes"]["http.response.status_code"] == 200 - - @pytest.mark.parametrize( - "init_kwargs, expected_query", + "data_collection, expected_query, expected_url_full", [ - pytest.param( - {"send_default_pii": True}, - "toy=tennisball&color=red&auth=secret", - id="send_default_pii_true", - ), - pytest.param( - {"send_default_pii": False}, - None, - id="send_default_pii_false", - ), pytest.param( {}, - None, - id="defaults", - ), - pytest.param( - {"data_collection": {}}, "toy=tennisball&color=red&auth=%5BFiltered%5D", + "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", id="data_collection_denylist_default", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "denylist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "denylist", "terms": ["toy"]}}, "toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D", + "http://example.com/?toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D#frag", id="data_collection_denylist_custom_terms", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["toy"]}}, "toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D", + "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", id="data_collection_allowlist", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["auth"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["auth"]}}, "toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D", + "http://example.com/?toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", id="data_collection_allowlist_sensitive_term", ), pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, + {"url_query_params": {"mode": "off"}}, None, + "http://example.com/#frag", id="data_collection_off", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - None, - id="data_collection_wins_over_send_default_pii", - ), ], ) def test_url_query_data_collection_sync( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_query + sentry_init, + capture_items, + httpx2_mock, + data_collection, + expected_query, + expected_url_full, ): httpx2_mock.add_response() sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -1443,82 +1373,59 @@ def test_url_query_data_collection_sync( else: assert http_span["attributes"]["url.query"] == expected_query + assert http_span["attributes"]["url.full"] == expected_url_full + @pytest.mark.asyncio @pytest.mark.parametrize( - "init_kwargs, expected_query", + "data_collection, expected_query, expected_url_full", [ - pytest.param( - {"send_default_pii": True}, - "toy=tennisball&color=red&auth=secret", - id="send_default_pii_true", - ), - pytest.param( - {"send_default_pii": False}, - None, - id="send_default_pii_false", - ), pytest.param( {}, - None, - id="defaults", - ), - pytest.param( - {"data_collection": {}}, "toy=tennisball&color=red&auth=%5BFiltered%5D", + "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", id="data_collection_denylist_default", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "denylist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "denylist", "terms": ["toy"]}}, "toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D", + "http://example.com/?toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D#frag", id="data_collection_denylist_custom_terms", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["toy"]}}, "toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D", + "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", id="data_collection_allowlist", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["auth"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["auth"]}}, "toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D", + "http://example.com/?toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", id="data_collection_allowlist_sensitive_term", ), pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, + {"url_query_params": {"mode": "off"}}, None, + "http://example.com/#frag", id="data_collection_off", ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - None, - id="data_collection_wins_over_send_default_pii", - ), ], ) async def test_url_query_data_collection_async( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_query + sentry_init, + capture_items, + httpx2_mock, + data_collection, + expected_query, + expected_url_full, ): httpx2_mock.add_response() sentry_init( integrations=[Httpx2Integration()], traces_sample_rate=1.0, - **init_kwargs, + data_collection=data_collection, ) items = capture_items("span") @@ -1537,249 +1444,40 @@ async def test_url_query_data_collection_async( else: assert http_span["attributes"]["url.query"] == expected_query - -@pytest.mark.parametrize( - "init_kwargs, expected_url_full", - [ - pytest.param( - {"data_collection": {}}, - "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", - id="data_collection_denylist_default", - ), - pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, - "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", - id="data_collection_allowlist", - ), - ], -) -def test_url_full_reassembly_sync( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_url_full -): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - **init_kwargs, - ) - - items = capture_items("span") - - url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - - with sentry_sdk.start_span(name="test"): - httpx2.Client().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - - assert http_span["attributes"]["url.full"] == expected_url_full - - -@pytest.mark.asyncio -@pytest.mark.parametrize( - "init_kwargs, expected_url_full", - [ - pytest.param( - {"data_collection": {}}, - "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", - id="data_collection_denylist_default", - ), - pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, - "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", - id="data_collection_allowlist", - ), - ], -) -async def test_url_full_reassembly_async( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_url_full -): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - **init_kwargs, - ) - - items = capture_items("span") - - url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - - with sentry_sdk.start_span(name="test"): - await httpx2.AsyncClient().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - assert http_span["attributes"]["url.full"] == expected_url_full @pytest.mark.parametrize( - "init_kwargs, expected_url_full", + "data_collection, expected_url, expected_query, expected_fragment", [ pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, - "http://example.com/#frag", - id="data_collection_off", - ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - "http://example.com/#frag", - id="data_collection_wins_over_send_default_pii", - ), - pytest.param( - {"send_default_pii": False}, - None, - id="send_default_pii_false", - ), - ], -) -def test_url_query_params_off_keeps_bare_url_sync( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_url_full -): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - **init_kwargs, - ) - - items = capture_items("span") - - url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - - with sentry_sdk.start_span(name="test"): - httpx2.Client().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - - assert "url.query" not in http_span["attributes"] - - if expected_url_full is None: - assert "url.full" not in http_span["attributes"] - assert "url.fragment" not in http_span["attributes"] - else: - assert http_span["attributes"]["url.full"] == expected_url_full - assert http_span["attributes"]["url.fragment"] == "frag" - - -@pytest.mark.asyncio -@pytest.mark.parametrize( - "init_kwargs, expected_url_full", - [ - pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, - "http://example.com/#frag", - id="data_collection_off", - ), - pytest.param( - { - "send_default_pii": True, - "data_collection": {"url_query_params": {"mode": "off"}}, - }, - "http://example.com/#frag", - id="data_collection_wins_over_send_default_pii", - ), - pytest.param( - {"send_default_pii": False}, - None, - id="send_default_pii_false", - ), - ], -) -async def test_url_query_params_off_keeps_bare_url_async( - sentry_init, capture_items, httpx2_mock, init_kwargs, expected_url_full -): - httpx2_mock.add_response() - - sentry_init( - integrations=[Httpx2Integration()], - traces_sample_rate=1.0, - **init_kwargs, - ) - - items = capture_items("span") - - url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" - - with sentry_sdk.start_span(name="test"): - await httpx2.AsyncClient().get(url) - - sentry_sdk.flush() - - http_span = _get_http_client_span(items) - - assert "url.query" not in http_span["attributes"] - - if expected_url_full is None: - assert "url.full" not in http_span["attributes"] - assert "url.fragment" not in http_span["attributes"] - else: - assert http_span["attributes"]["url.full"] == expected_url_full - assert http_span["attributes"]["url.fragment"] == "frag" - - -@pytest.mark.parametrize( - "init_kwargs, expected_url, expected_query, expected_fragment", - [ - pytest.param( - {"data_collection": {}}, + {}, "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", "toy=tennisball&color=red&auth=%5BFiltered%5D", "frag", id="data_collection_denylist_default", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["toy"]}}, "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", "toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D", "frag", id="data_collection_allowlist", ), pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, + {"url_query_params": {"mode": "off"}}, "http://example.com/#frag", "", "frag", id="data_collection_off", ), - pytest.param( - {"send_default_pii": False}, - None, - None, - None, - id="send_default_pii_false", - ), ], ) def test_crumb_url_query_data_collection_sync( sentry_init, capture_events, httpx2_mock, - init_kwargs, + data_collection, expected_url, expected_query, expected_fragment, @@ -1788,7 +1486,7 @@ def test_crumb_url_query_data_collection_sync( sentry_init( integrations=[Httpx2Integration()], - **init_kwargs, + data_collection=data_collection, ) url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" @@ -1803,59 +1501,43 @@ def test_crumb_url_query_data_collection_sync( crumb = event["breadcrumbs"]["values"][0] - if expected_url is None: - assert "url" not in crumb["data"] - assert SPANDATA.HTTP_QUERY not in crumb["data"] - assert SPANDATA.HTTP_FRAGMENT not in crumb["data"] - else: - assert crumb["data"]["url"] == expected_url - assert crumb["data"][SPANDATA.HTTP_QUERY] == expected_query - assert crumb["data"][SPANDATA.HTTP_FRAGMENT] == expected_fragment + assert crumb["data"]["url"] == expected_url + assert crumb["data"][SPANDATA.HTTP_QUERY] == expected_query + assert crumb["data"][SPANDATA.HTTP_FRAGMENT] == expected_fragment @pytest.mark.asyncio @pytest.mark.parametrize( - "init_kwargs, expected_url, expected_query, expected_fragment", + "data_collection, expected_url, expected_query, expected_fragment", [ pytest.param( - {"data_collection": {}}, + {}, "http://example.com/?toy=tennisball&color=red&auth=%5BFiltered%5D#frag", "toy=tennisball&color=red&auth=%5BFiltered%5D", "frag", id="data_collection_denylist_default", ), pytest.param( - { - "data_collection": { - "url_query_params": {"mode": "allowlist", "terms": ["toy"]} - } - }, + {"url_query_params": {"mode": "allowlist", "terms": ["toy"]}}, "http://example.com/?toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D#frag", "toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D", "frag", id="data_collection_allowlist", ), pytest.param( - {"data_collection": {"url_query_params": {"mode": "off"}}}, + {"url_query_params": {"mode": "off"}}, "http://example.com/#frag", "", "frag", id="data_collection_off", ), - pytest.param( - {"send_default_pii": False}, - None, - None, - None, - id="send_default_pii_false", - ), ], ) async def test_crumb_url_query_data_collection_async( sentry_init, capture_events, httpx2_mock, - init_kwargs, + data_collection, expected_url, expected_query, expected_fragment, @@ -1864,7 +1546,7 @@ async def test_crumb_url_query_data_collection_async( sentry_init( integrations=[Httpx2Integration()], - **init_kwargs, + data_collection=data_collection, ) url = "http://example.com/?toy=tennisball&color=red&auth=secret#frag" @@ -1879,14 +1561,9 @@ async def test_crumb_url_query_data_collection_async( crumb = event["breadcrumbs"]["values"][0] - if expected_url is None: - assert "url" not in crumb["data"] - assert SPANDATA.HTTP_QUERY not in crumb["data"] - assert SPANDATA.HTTP_FRAGMENT not in crumb["data"] - else: - assert crumb["data"]["url"] == expected_url - assert crumb["data"][SPANDATA.HTTP_QUERY] == expected_query - assert crumb["data"][SPANDATA.HTTP_FRAGMENT] == expected_fragment + assert crumb["data"]["url"] == expected_url + assert crumb["data"][SPANDATA.HTTP_QUERY] == expected_query + assert crumb["data"][SPANDATA.HTTP_FRAGMENT] == expected_fragment @pytest.mark.tests_internal_exceptions