Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7541460
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
5e9f610
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 9, 2026
a590c8e
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
16ed0c8
fix test
ericapisani Jul 9, 2026
486f0bc
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
7d14a81
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
bb98334
add aws lambda test coverage
ericapisani Jul 9, 2026
61d1618
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
951c408
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
a19be39
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
620e222
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
ec6f520
update tornado test
ericapisani Jul 10, 2026
4dd3ba6
ref(integrations): route HTTP header filtering through data collectio…
ericapisani Jul 8, 2026
d0bae90
Make changes to adjust to the data collection option being within the…
ericapisani Jul 9, 2026
a6c4688
fix test
ericapisani Jul 9, 2026
d7b378b
make sure host header is not filtered when being added to the url
ericapisani Jul 9, 2026
52c2da1
add test coverage for edge case around host header being dropped but …
ericapisani Jul 9, 2026
aa645d7
add aws lambda test coverage
ericapisani Jul 9, 2026
8b6e3ad
fix(aws-lambda): Remove vendored deps from new embedded-sdk test fixt…
ericapisani Jul 9, 2026
d717172
add test coverage within the wsgi test file
ericapisani Jul 9, 2026
c7f590f
Merge branch 'py-2584-update-wsgi-filter-headers' of github.com:getse…
ericapisani Jul 14, 2026
293a291
feat(integrations): apply data_collection cookie filtering to wsgi, s…
ericapisani Jul 10, 2026
530e83c
fix(integrations): omit cookies field when data_collection cookies mo…
ericapisani Jul 10, 2026
326d796
update tornado test
ericapisani Jul 10, 2026
e9f0e20
Merge branch 'master' into py-2584-update-wsgi-filter-headers
ericapisani Jul 15, 2026
48f7c7b
Merge branch 'py-2581-cookies' of github.com:getsentry/sentry-python …
ericapisani Jul 15, 2026
621d79b
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
3d7bddb
test(aiohttp): Expect single span in streaming passthrough test
ericapisani Jul 15, 2026
fad2292
Merge branch 'py-2584-update-wsgi-filter-headers' into py-2581-cookies
ericapisani Jul 15, 2026
40d9f38
feat(wsgi): Apply data_collection filtering to URL query strings
ericapisani Jul 15, 2026
e6e7148
Merge branch 'py-2581-cookies' into py-2583-query-parameters
ericapisani Jul 15, 2026
1f9bce7
lint
ericapisani Jul 15, 2026
fad0c9a
Do not encode what is added to event/span attributes in order to conf…
ericapisani Jul 16, 2026
21cf40b
feat(asgi): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
3f0bc2a
lint
ericapisani Jul 16, 2026
eee4ea2
feat(aiohttp): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
3b17dd3
feat(tornado): Apply data_collection filtering to URL query strings
ericapisani Jul 16, 2026
96e0ac0
test(tornado): Use literal [Filtered] in query param expectations
ericapisani Jul 16, 2026
c3baf08
feat(sanic): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
ea22fc5
feat(quart): Apply data_collection filtering to URL query strings
ericapisani Jul 17, 2026
066b45c
Merge branch 'master' into py-2583-query-params-sanic
ericapisani Jul 22, 2026
b4f5f65
.
ericapisani Jul 22, 2026
443b013
Merge branch 'py-2583-query-params-sanic' into py-2583-query-params-q…
ericapisani Jul 22, 2026
d0f22c5
.
ericapisani Jul 22, 2026
be03268
.
ericapisani Jul 22, 2026
c1c6ed6
Merge branch 'master' into py-2583-query-params-quart
ericapisani Jul 22, 2026
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
37 changes: 36 additions & 1 deletion sentry_sdk/integrations/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.data_collection import _apply_data_collection_filtering_to_query_string
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
Expand All @@ -17,6 +18,8 @@
capture_internal_exceptions,
ensure_integration_enabled,
event_from_exception,
has_data_collection_enabled,
parse_url,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -203,7 +206,39 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None:

segment.set_attributes(header_attributes)

if should_send_default_pii():
client_options = sentry_sdk.get_client().options
filtered_query_string = None
if has_data_collection_enabled(client_options):
query_string = request_websocket.query_string.decode(
"utf-8", errors="replace"
)
if query_string:
filtered_query_string = (
_apply_data_collection_filtering_to_query_string(
query_string=query_string,
behaviour=client_options["data_collection"][
"url_query_params"
],
)
)
if filtered_query_string:
segment.set_attribute(
"url.query",
filtered_query_string,
)

parsed_url = parse_url(request_websocket.url)
segment.set_attribute(
"url.full",
f"{parsed_url.url}?{filtered_query_string}"
if filtered_query_string
else parsed_url.url,
)

# TODO: Add the user properties that are seen in the branch below here once
# code is added to respect the `user_info` settings within the data collection
# configuration
elif should_send_default_pii():
Comment thread
ericapisani marked this conversation as resolved.
segment.set_attribute("url.full", request_websocket.url)
segment.set_attribute(
"url.query",
Expand Down
151 changes: 151 additions & 0 deletions tests/integrations/quart/test_quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,154 @@ async def test_span_streaming_sensitive_header_passthrough_with_pii_and_no_data_
segment["attributes"]["http.request.header.authorization"]
== "Bearer secret-token"
)


_QUERY_PARAM_DATA_COLLECTION_CASES = [
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(
{"_experiments": {"data_collection": {}}},
"toy=tennisball&color=red&auth=%5BFiltered%5D",
id="data_collection_denylist_default",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "denylist", "terms": ["toy"]}
}
}
},
"toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D",
id="data_collection_denylist_custom_terms",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "allowlist", "terms": ["toy"]}
}
}
},
"toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D",
id="data_collection_allowlist",
),
pytest.param(
{
"_experiments": {
"data_collection": {
"url_query_params": {"mode": "allowlist", "terms": ["auth"]}
}
}
},
"toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D",
id="data_collection_allowlist_sensitive_term",
),
pytest.param(
{"_experiments": {"data_collection": {"url_query_params": {"mode": "off"}}}},
None,
id="data_collection_off",
),
pytest.param(
{
"send_default_pii": True,
"_experiments": {"data_collection": {"url_query_params": {"mode": "off"}}},
},
None,
id="data_collection_wins_over_send_default_pii",
),
]


@pytest.mark.asyncio
@pytest.mark.parametrize(
"init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
)
async def test_span_streaming_url_query_data_collection(
sentry_init, capture_items, init_kwargs, expected_query
):
init_kwargs = dict(init_kwargs)
experiments = {"trace_lifecycle": "stream"}
experiments.update(init_kwargs.pop("_experiments", {}))
sentry_init(
integrations=[quart_sentry.QuartIntegration()],
traces_sample_rate=1.0,
_experiments=experiments,
**init_kwargs,
)
items = capture_items("span")

app = quart_app_factory()
client = app.test_client()
response = await client.get("/message?toy=tennisball&color=red&auth=secret")
assert response.status_code == 200

sentry_sdk.flush()

spans = [item.payload for item in items]
assert len(spans) == 1

segment = spans[0]

data_collection_enabled = "data_collection" in experiments
url_attrs_expected = data_collection_enabled or init_kwargs.get(
"send_default_pii", False
)

if expected_query is None:
assert "url.query" not in segment["attributes"]
if url_attrs_expected:
# When the filtered query string is empty, url.full carries the
# base URL only (no query).
assert segment["attributes"]["url.full"] == "http://localhost/message"
else:
assert "url.full" not in segment["attributes"]
else:
assert segment["attributes"]["url.query"] == expected_query
assert segment["attributes"]["url.full"] == (
f"http://localhost/message?{expected_query}"
)


@pytest.mark.asyncio
async def test_span_streaming_url_query_multi_and_blank_values(
sentry_init, capture_items
):
sentry_init(
integrations=[quart_sentry.QuartIntegration()],
traces_sample_rate=1.0,
_experiments={"trace_lifecycle": "stream", "data_collection": {}},
)
items = capture_items("span")

app = quart_app_factory()
client = app.test_client()
response = await client.get("/message?foo=1&foo=2&empty=")
assert response.status_code == 200

sentry_sdk.flush()

spans = [item.payload for item in items]
assert len(spans) == 1

segment = spans[0]
query = segment["attributes"]["url.query"]
# Repeated keys are preserved and blank values are kept.
assert "foo=1" in query
assert "foo=2" in query
assert "empty=" in query
# url.full carries the same filtered query string.
assert segment["attributes"]["url.full"] == f"http://localhost/message?{query}"
Loading