Skip to content

Commit bd5a52f

Browse files
committed
Revert change to the behaviour of _filter_headers but retain the new AnnotatedValue methods
1 parent 0ece900 commit bd5a52f

5 files changed

Lines changed: 6 additions & 100 deletions

File tree

sentry_sdk/integrations/_asgi_common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def _get_request_data(asgi_scope: "Any") -> "Dict[str, Any]":
9393
if ty in ("http", "websocket"):
9494
request_data["method"] = asgi_scope.get("method")
9595

96-
request_data["headers"] = headers = _filter_headers(_get_headers(asgi_scope))
96+
request_data["headers"] = headers = _filter_headers(
97+
_get_headers(asgi_scope), use_annotated_value=False
98+
)
9799
request_data["query_string"] = _get_query(asgi_scope)
98100

99101
request_data["url"] = _get_url(

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE
77
from sentry_sdk.scope import should_send_default_pii
88
from sentry_sdk.utils import AnnotatedValue, logger
9-
from sentry_sdk.tracing_utils import has_span_streaming_enabled
109

1110
try:
1211
from django.http.request import RawPostDataException
@@ -213,17 +212,14 @@ def _is_json_content_type(ct: "Optional[str]") -> bool:
213212

214213

215214
def _filter_headers(
216-
headers: "Mapping[str, str]",
215+
headers: "Mapping[str, str]", use_annotated_value: True
217216
) -> "Mapping[str, Union[AnnotatedValue, str]]":
218217
if should_send_default_pii():
219218
return headers
220219

221-
client_options = sentry_sdk.get_client().options
222-
is_span_streaming_enabled = has_span_streaming_enabled(client_options)
223-
224220
substitute: "Union[AnnotatedValue, str]" = (
225221
SENSITIVE_DATA_SUBSTITUTE
226-
if is_span_streaming_enabled
222+
if not use_annotated_value
227223
else AnnotatedValue.removed_because_over_size_limit()
228224
)
229225

sentry_sdk/integrations/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def _get_request_attributes(
400400
if method:
401401
attributes["http.request.method"] = method.upper()
402402

403-
headers = _filter_headers(dict(_get_headers(environ)))
403+
headers = _filter_headers(dict(_get_headers(environ)), use_annotated_value=False)
404404
for header, value in headers.items():
405405
attributes[f"http.request.header.{header.lower()}"] = value
406406

tests/integrations/asgi/test_asgi.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,48 +1002,3 @@ async def test_custom_transaction_name(
10021002
assert transaction_event["type"] == "transaction"
10031003
assert transaction_event["transaction"] == "foobar"
10041004
assert transaction_event["transaction_info"] == {"source": "custom"}
1005-
1006-
1007-
@pytest.mark.asyncio
1008-
@pytest.mark.parametrize("span_streaming", [True, False])
1009-
async def test_filter_sensitive_headers_without_pii(
1010-
sentry_init,
1011-
asgi3_app,
1012-
capture_events,
1013-
capture_items,
1014-
span_streaming,
1015-
):
1016-
sentry_init(
1017-
send_default_pii=False,
1018-
traces_sample_rate=1.0,
1019-
_experiments={
1020-
"trace_lifecycle": "stream" if span_streaming else "static",
1021-
},
1022-
)
1023-
app = SentryAsgiMiddleware(asgi3_app)
1024-
1025-
if span_streaming:
1026-
items = capture_items("span")
1027-
else:
1028-
events = capture_events()
1029-
1030-
async with TestClient(app) as client:
1031-
await client.get(
1032-
"/",
1033-
headers={"Authorization": "Bearer secret", "X-Custom": "ok"},
1034-
)
1035-
1036-
sentry_sdk.flush()
1037-
1038-
if span_streaming:
1039-
assert len(items) == 1
1040-
attributes = items[0].payload["attributes"]
1041-
assert attributes["http.request.header.authorization"] == "[Filtered]"
1042-
assert attributes["http.request.header.x-custom"] == "ok"
1043-
else:
1044-
(transaction_event,) = events
1045-
headers = transaction_event["request"]["headers"]
1046-
assert (
1047-
headers["authorization"] != "Bearer secret"
1048-
) # In the legacy approach, the expectation is that the event scrubber would remove this
1049-
assert headers["x-custom"] == "ok"

tests/integrations/wsgi/test_wsgi.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -841,50 +841,3 @@ def app(environ, start_response):
841841
)
842842
def test_get_request_url_x_forwarded_proto(environ, use_x_forwarded_for, expected_url):
843843
assert get_request_url(environ, use_x_forwarded_for) == expected_url
844-
845-
846-
@pytest.mark.parametrize("span_streaming", [True, False])
847-
def test_filter_sensitive_headers_without_pii(
848-
sentry_init,
849-
capture_events,
850-
capture_items,
851-
span_streaming,
852-
):
853-
def app(environ, start_response):
854-
start_response("200 OK", [])
855-
return [b"ok"]
856-
857-
sentry_init(
858-
send_default_pii=False,
859-
traces_sample_rate=1.0,
860-
_experiments={
861-
"trace_lifecycle": "stream" if span_streaming else "static",
862-
},
863-
)
864-
middleware = SentryWsgiMiddleware(app)
865-
client = Client(middleware)
866-
867-
if span_streaming:
868-
items = capture_items("span")
869-
else:
870-
events = capture_events()
871-
872-
client.get(
873-
"/",
874-
headers={"Authorization": "Bearer secret", "X-Custom": "ok"},
875-
)
876-
877-
sentry_sdk.flush()
878-
879-
if span_streaming:
880-
assert len(items) == 1
881-
attributes = items[0].payload["attributes"]
882-
assert attributes["http.request.header.authorization"] == "[Filtered]"
883-
assert attributes["http.request.header.x-custom"] == "ok"
884-
else:
885-
envelope = events[0]
886-
headers = envelope["request"]["headers"]
887-
assert (
888-
headers["Authorization"] != "Bearer secret"
889-
) # In the legacy approach, the expectation is that the event scrubber would remove this
890-
assert headers["X-Custom"] == "ok"

0 commit comments

Comments
 (0)