Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions sentry_sdk/integrations/_asgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,14 @@ def _get_request_data(

request_data["headers"] = _filter_headers(headers)

if has_data_collection_enabled(client_options):
qs = _get_query(asgi_scope)
if qs:
filtered_query_string = (
_apply_data_collection_filtering_to_query_string(
query_string=qs,
behaviour=client_options["data_collection"]["url_query_params"],
)
)
if filtered_query_string:
request_data["query_string"] = filtered_query_string
else:
request_data["query_string"] = _get_query(asgi_scope)
qs = _get_query(asgi_scope)
if qs:
filtered_query_string = _apply_data_collection_filtering_to_query_string(
query_string=qs,
behaviour=client_options["data_collection"]["url_query_params"],
)
if filtered_query_string:
request_data["query_string"] = filtered_query_string

request_data["url"] = _get_url(
asgi_scope,
Expand All @@ -149,10 +144,7 @@ def _get_request_data(

client = asgi_scope.get("client")
if client:
if has_data_collection_enabled(client_options):
if client_options["data_collection"]["user_info"]:
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}
elif should_send_default_pii():
if client_options["data_collection"]["user_info"]:
request_data["env"] = {"REMOTE_ADDR": _get_ip(asgi_scope)}

return request_data
Expand Down
79 changes: 6 additions & 73 deletions tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,13 @@ async def app(scope, receive, send):


@pytest.mark.asyncio
@pytest.mark.parametrize(
"should_send_pii",
[True, False],
)
async def test_capture_transaction(
sentry_init,
asgi3_app,
capture_items,
should_send_pii,
):
sentry_init(
send_default_pii=should_send_pii,
data_collection={},
traces_sample_rate=1.0,
)
app = SentryAsgiMiddleware(asgi3_app)
Expand All @@ -219,13 +214,7 @@ async def test_capture_transaction(
assert span["attributes"]["http.request.method"] == "GET"
assert span["attributes"]["http.request.header.host"] == ["localhost"]
assert span["attributes"]["http.request.header.user-agent"] == ["ASGI-Test-Client"]

if should_send_pii:
assert (
span["attributes"]["url.full"] == "http://localhost/some_url?somevalue=123"
)
assert span["attributes"]["url.path"] == "/some_url"
assert span["attributes"]["http.query"] == "somevalue=123"
assert span["attributes"]["url.full"] == "http://localhost/some_url?somevalue=123"


@pytest.mark.asyncio
Expand All @@ -235,7 +224,7 @@ async def test_capture_transaction_with_error(
capture_items,
):
sentry_init(
send_default_pii=True,
data_collection={},
traces_sample_rate=1.0,
)

Expand Down Expand Up @@ -414,7 +403,7 @@ async def test_websocket(
request,
):
sentry_init(
send_default_pii=True,
data_collection={},
traces_sample_rate=1.0,
)

Expand Down Expand Up @@ -455,7 +444,7 @@ async def test_auto_session_tracking_with_aggregates(
sentry_init, asgi3_app, capture_envelopes
):
sentry_init(
send_default_pii=True,
data_collection={},
traces_sample_rate=1.0,
)
app = SentryAsgiMiddleware(asgi3_app)
Expand Down Expand Up @@ -501,7 +490,7 @@ async def test_fallback_segment_name_and_source(
capture_items,
):
sentry_init(
send_default_pii=True,
data_collection={},
traces_sample_rate=1.0,
)
app = SentryAsgiMiddleware(asgi3_app)
Expand Down Expand Up @@ -779,7 +768,6 @@ async def test_get_request_attributes_url_with_filtered_host(
# the host header value, but "url.full" must still resolve rather than embedding
# the substituted value.
sentry_init(
send_default_pii=True,
traces_sample_rate=1.0,
data_collection={
"http_headers": {"request": {"mode": "allowlist", "terms": []}}
Expand Down Expand Up @@ -838,20 +826,6 @@ def _http_scope():
@pytest.mark.parametrize(
"init_kwargs, request_url, expected_query, expected_url_full",
[
pytest.param(
{"send_default_pii": True},
"/foo?" + QUERY_STRING,
QUERY_STRING,
"http://example.com/foo?" + QUERY_STRING,
id="send_default_pii_true",
),
pytest.param(
{"send_default_pii": False},
"/foo?" + QUERY_STRING,
None,
None,
id="send_default_pii_false",
),
pytest.param(
{},
"/foo?" + QUERY_STRING,
Expand Down Expand Up @@ -884,16 +858,6 @@ def _http_scope():
"http://example.com/foo",
id="data_collection_off",
),
pytest.param(
{
"send_default_pii": True,
"data_collection": {"url_query_params": {"mode": "off"}},
},
"/foo?" + QUERY_STRING,
None,
"http://example.com/foo",
id="data_collection_wins_over_send_default_pii",
),
pytest.param(
{"_experiments": {"data_collection": {}}},
"/foo",
Expand Down Expand Up @@ -953,27 +917,6 @@ async def test_get_request_attributes_query_data_collection(
True,
id="dc_default_user_info",
),
pytest.param(
{
"send_default_pii": True,
"data_collection": {"user_info": False},
},
True,
False,
id="dc_wins_over_pii",
),
pytest.param(
{"send_default_pii": True},
True,
True,
id="legacy_pii_true",
),
pytest.param(
{"send_default_pii": False},
True,
False,
id="legacy_pii_false",
),
pytest.param(
{"data_collection": {}},
False,
Expand Down Expand Up @@ -1096,8 +1039,6 @@ async def test_custom_transaction_name(
@pytest.mark.parametrize(
"init_kwargs, expect_ip",
[
pytest.param({"send_default_pii": True}, True, id="legacy_pii_true"),
pytest.param({"send_default_pii": False}, False, id="legacy_pii_false"),
pytest.param(
{"data_collection": {}},
True,
Expand All @@ -1113,14 +1054,6 @@ async def test_custom_transaction_name(
False,
id="dc_user_info_false",
),
pytest.param(
{
"send_default_pii": True,
"data_collection": {"user_info": False},
},
False,
id="dc_wins_over_pii",
),
],
)
async def test_user_ip_address_on_all_spans(
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/django/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def test_basic(
):
sentry_init(
integrations=[DjangoIntegration()],
send_default_pii=True,
data_collection={},
)

import channels # type: ignore[import-not-found]
Expand Down Expand Up @@ -171,7 +171,7 @@ async def test_async_views_concurrent_execution(
settings.MIDDLEWARE = []
sentry_init(
integrations=[DjangoIntegration()],
send_default_pii=True,
data_collection={},
)

application = make_asgi_application()
Expand Down Expand Up @@ -211,7 +211,7 @@ async def test_async_middleware_that_is_function_concurrent_execution(
]
sentry_init(
integrations=[DjangoIntegration()],
send_default_pii=True,
data_collection={},
)

application = make_asgi_application()
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def body_form(
async def test_request_info_json_body(sentry_init, capture_items):
sentry_init(
traces_sample_rate=1.0,
send_default_pii=True,
data_collection={},
integrations=[StarletteIntegration()],
)

Expand Down Expand Up @@ -214,7 +214,7 @@ async def test_formdata_request_body(sentry_init, capture_items):
async def test_request_body_too_big(sentry_init, capture_items):
sentry_init(
traces_sample_rate=1.0,
send_default_pii=True,
data_collection={},
integrations=[StarletteIntegration()],
)

Expand Down Expand Up @@ -343,7 +343,7 @@ async def test_response(sentry_init, capture_events):
sentry_init(
integrations=[StarletteIntegration(), FastApiIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
data_collection={},
)

app = fastapi_app_factory()
Expand Down Expand Up @@ -728,7 +728,7 @@ def test_transaction_http_method_custom(sentry_init, capture_items):
def test_request_url(sentry_init, capture_items):
sentry_init(
traces_sample_rate=1.0,
send_default_pii=True,
data_collection={},
integrations=[
StarletteIntegration(),
],
Expand Down
Loading