Skip to content

feat(wsgi): Apply data_collection filtering to URL query strings#6827

Open
ericapisani wants to merge 4 commits into
py-2581-cookiesfrom
py-2583-query-parameters
Open

feat(wsgi): Apply data_collection filtering to URL query strings#6827
ericapisani wants to merge 4 commits into
py-2581-cookiesfrom
py-2583-query-parameters

Conversation

@ericapisani

@ericapisani ericapisani commented Jul 15, 2026

Copy link
Copy Markdown
Member

Filter WSGI request event and span query strings through the
data_collection.url_query_params behaviour (denylist/allowlist/off)
instead of gating query string capture solely on send_default_pii.
This brings WSGI-based integrations in line with the data collection
spec's handling of cookies and headers.

Rename the data_collection field query_params to url_query_params to
match the updated data collection spec, which distinguishes URL query
params from other key-value data (cookies, headers). Update the
DataCollection/DataCollectionUserOptions TypedDicts, resolution logic
in data_collection.py, and all WSGI/Flask/Django test coverage
accordingly.

Refs PY-2583

Filter WSGI request event and span query strings through the
data_collection.url_query_params behaviour (denylist/allowlist/off)
instead of gating query string capture solely on send_default_pii.
This brings WSGI-based integrations in line with the data collection
spec's handling of cookies and headers.

Rename the data_collection field query_params to url_query_params to
match the updated data collection spec, which distinguishes URL query
params from other key-value data (cookies, headers). Update the
DataCollection/DataCollectionUserOptions TypedDicts, resolution logic
in data_collection.py, and all WSGI/Flask/Django test coverage
accordingly.

Refs PY-2583
@linear-code

linear-code Bot commented Jul 15, 2026

Copy link
Copy Markdown

PY-2583

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

93252 passed | ⏭️ 6302 skipped | Total: 99554 | Pass Rate: 93.67% | Execution Time: 327m 49s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +1398
Passed Tests 📈 +1398
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2479 uncovered lines.
✅ Project coverage is 89.71%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/wsgi.py 100.00% ⚠️ 2 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.67%    89.71%    +0.04%
==========================================
  Files          193       193         —
  Lines        24004     24097       +93
  Branches      8340      8408       +68
==========================================
+ Hits         21526     21618       +92
- Misses        2478      2479        +1
- Partials      1387      1391        +4

Generated by Codecov Action

@ericapisani ericapisani marked this pull request as ready for review July 15, 2026 20:19
@ericapisani ericapisani requested a review from a team as a code owner July 15, 2026 20:19
@ericapisani ericapisani marked this pull request as draft July 16, 2026 15:41
@ericapisani

Copy link
Copy Markdown
Member Author

Moving this back to draft as, on looking at the spec again, the query parameters are not supposed to appear URL encoded in the attributes

…orm with what is shown in the data collection spec
@ericapisani ericapisani marked this pull request as ready for review July 16, 2026 16:01

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fad0c9a. Configure here.


attributes["url.full"] = get_request_url(environ, use_x_forwarded_for)

elif should_send_default_pii():

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Span client address dropped

Medium Severity

_get_request_attributes uses if has_data_collection_enabled / elif should_send_default_pii(). Enabling _experiments.data_collection always takes the first branch, so client.address is never set even when send_default_pii is true.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fad0c9a. Configure here.

parts.append(f"{key}={item}")
return "&".join(parts)

return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query rebuild splits values

Medium Severity

_apply_data_collection_filtering_to_query_string parses with parse_qs (URL-decoding values) then rebuilds with f"{key}={item}" joined by &. Decoded values that contain & or = are not escaped, so one parameter can be misread as several and filtering can misrepresent the original query.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fad0c9a. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant