Skip to content

feat(wsgi,asgi): Introduce substitute values for filtered fields in span-streaming mode#6178

Open
ericapisani wants to merge 5 commits intomasterfrom
ericapisani/py-2396-introduce-a-substitute-value-for
Open

feat(wsgi,asgi): Introduce substitute values for filtered fields in span-streaming mode#6178
ericapisani wants to merge 5 commits intomasterfrom
ericapisani/py-2396-introduce-a-substitute-value-for

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 30, 2026

In the legacy (event-based) pipeline, filtered/removed values in request data are represented as AnnotatedValue objects — wrappers that carry metadata (rem remarks) consumed by Relay during ingestion. In span-streaming mode, request attributes are plain strings sent directly on spans, so AnnotatedValue is not appropriate there.

Previously, _filter_headers had a use_annotated_value: bool parameter that callers set to False when building span attributes. This was fragile — callers had to know the right value, and the logic was split between call sites instead of living in one place.

This PR:

  • Adds two new substitute string constants (OVER_SIZE_LIMIT_SUBSTITUTE, UNPARSABLE_RAW_DATA_SUBSTITUTE) for use in the span-streaming path.
  • Adds two new AnnotatedValue factory methods (substituted_because_raw_data, substituted_because_over_size_limit) that use remark type "s" (substituted) rather than "x" (removed), for future use as the SDK fully transitions to span-first.

Refs GH-6175
Fixes PY-2396

…pan-streaming mode

When span streaming is enabled, sensitive headers are replaced with a
human-readable string ("[Filtered]") rather than an AnnotatedValue wrapper,
which is incompatible with the span-first data model.

Add substitute string constants (OVER_SIZE_LIMIT_SUBSTITUTE,
UNPARSABLE_RAW_DATA_SUBSTITUTE) and new AnnotatedValue factory methods
(substituted_because_raw_data, substituted_because_over_size_limit) that use
remark type "s" (substituted) instead of "x" (removed).

Update _filter_headers to auto-detect span streaming and choose the
appropriate value type, removing the use_annotated_value parameter.

Refs GH-2396
Fixes PY-2396
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 30, 2026

@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run

@ericapisani
Copy link
Copy Markdown
Member Author

@sentry review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 9.03s

All tests are passing successfully.

❌ Patch coverage is 60.00%. Project has 14939 uncovered lines.

Files with missing lines (3)
File Patch % Lines
_wsgi_common.py 31.01% ⚠️ 89 Missing and 1 partials
_asgi_common.py 13.70% ⚠️ 63 Missing
_types.py 66.67% ⚠️ 14 Missing

Generated by Codecov Action

Comment thread sentry_sdk/integrations/_wsgi_common.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f696766. Configure here.

@ericapisani ericapisani marked this pull request as ready for review April 30, 2026 15:37
@ericapisani ericapisani requested a review from a team as a code owner April 30, 2026 15:37
Comment thread sentry_sdk/integrations/_wsgi_common.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 1 potential issue.

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 0ece900. Configure here.

Comment thread sentry_sdk/integrations/_wsgi_common.py
@ericapisani ericapisani marked this pull request as draft April 30, 2026 15:44
@ericapisani ericapisani marked this pull request as ready for review April 30, 2026 15:56
Comment thread sentry_sdk/integrations/_asgi_common.py
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