Skip to content

Commit 08212cd

Browse files
authored
ref(client)!: Remove EventScrubber and the event_scrubber option (#7772)
`data_collection` is now the default way to control what data the SDK collects, so the always-on `EventScrubber` is no longer needed. The expectation is that, if people need to filter out request bodies, etc., that they use the `before_send` callback. Removes `sentry_sdk.scrubber` (`EventScrubber`, `DEFAULT_DENYLIST`, `DEFAULT_PII_DENYLIST`), the scrubbing step in `_prepare_event`, and the `event_scrubber` init option. Passing `event_scrubber=` to `init` now raises a `TypeError`. Refs PY-2798 Refs #7566
1 parent b0fcd98 commit 08212cd

9 files changed

Lines changed: 16 additions & 547 deletions

File tree

‎docs/apidocs.rst‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ API Docs
3535
.. autoclass:: sentry_sdk.attachments.Attachment
3636
:members:
3737

38-
.. autoclass:: sentry_sdk.scrubber.EventScrubber
39-
:members:
40-
4138
.. autoclass:: sentry_sdk.monitor.Monitor
4239
:members:
4340

‎sentry_sdk/client.py‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from sentry_sdk.integrations.dedupe import DedupeIntegration
2828
from sentry_sdk.monitor import Monitor
2929
from sentry_sdk.profiler.continuous_profiler import setup_continuous_profiler
30-
from sentry_sdk.scrubber import EventScrubber
3130
from sentry_sdk.serializer import serialize
3231
from sentry_sdk.sessions import SessionFlusher
3332
from sentry_sdk.traces import Span, trace
@@ -49,7 +48,6 @@
4948
get_sdk_name,
5049
get_type_name,
5150
handle_in_app,
52-
has_data_collection_enabled,
5351
logger,
5452
)
5553

@@ -132,20 +130,6 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
132130

133131
rv["data_collection"] = _resolve_data_collection(rv)
134132

135-
# Do not add the event scrubber if data collection is enabled as it can remove data that's
136-
# collected under data collection config
137-
if not has_data_collection_enabled(rv) and rv["event_scrubber"] is None:
138-
rv["event_scrubber"] = EventScrubber(
139-
send_default_pii=False
140-
if rv["send_default_pii"] is None
141-
else rv["send_default_pii"]
142-
)
143-
elif has_data_collection_enabled(rv) and rv["event_scrubber"]:
144-
logger.warning(
145-
"Event scrubbers are not enabled when data collection configuration is provided. Ignoring event_scrubber...",
146-
)
147-
rv["event_scrubber"] = None
148-
149133
if rv["socket_options"] and not isinstance(rv["socket_options"], list):
150134
logger.warning(
151135
"Ignoring socket_options because of unexpected format. See urllib3.HTTPConnection.socket_options for the expected format."
@@ -571,11 +555,6 @@ def _prepare_event(
571555
self.options["project_root"],
572556
)
573557

574-
if event is not None:
575-
event_scrubber = self.options["event_scrubber"]
576-
if event_scrubber:
577-
event_scrubber.scrub_event(event)
578-
579558
if previous_total_breadcrumbs is not None:
580559
event["breadcrumbs"] = AnnotatedValue(
581560
event.get("breadcrumbs", {"values": []}),

‎sentry_sdk/consts.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,6 @@ def __init__(
13651365
MATCH_ALL
13661366
],
13671367
functions_to_trace: "Sequence[Dict[str, str]]" = [], # noqa: B006
1368-
event_scrubber: "Optional[sentry_sdk.scrubber.EventScrubber]" = None,
13691368
max_value_length: "Optional[int]" = DEFAULT_MAX_VALUE_LENGTH,
13701369
enable_backpressure_handling: bool = True,
13711370
error_sampler: "Optional[Callable[[Event, Hint], Union[float, bool]]]" = None,
@@ -1498,13 +1497,6 @@ def __init__(
14981497
14991498
See https://docs.sentry.io/platforms/python/configuration/options/#data_collection for more details.
15001499
1501-
:param event_scrubber: Scrubs the event payload for sensitive information such as cookies, sessions, and
1502-
passwords from a `denylist`.
1503-
1504-
It can additionally be used to scrub from another `pii_denylist` if `send_default_pii` is disabled.
1505-
1506-
See how to `configure the scrubber here <https://docs.sentry.io/data-management/sensitive-data/#event-scrubber>`_.
1507-
15081500
:param include_source_context: When enabled, source context will be included in events sent to Sentry.
15091501
15101502
This source context includes the five lines of code above and below the line of code where an error

‎sentry_sdk/scrubber.py‎

Lines changed: 0 additions & 178 deletions
This file was deleted.

‎tests/integrations/fastapi/test_fastapi.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ async def test_formdata_request_body(sentry_init, capture_items):
190190
(event,) = (item.payload for item in items if item.type == "event")
191191
assert event["request"]["data"].keys() == PARSED_FORM.keys()
192192
assert event["request"]["data"]["username"] == PARSED_FORM["username"]
193-
assert event["request"]["data"]["password"] == "[Filtered]"
193+
# Expectation in data collection is that the user scrubs this within `before_send`
194+
assert event["request"]["data"]["password"] == "hello123"
194195
assert event["request"]["data"]["photo"] == ""
195196

196197
sentry_sdk.flush()
@@ -491,7 +492,8 @@ async def _error(request: Request):
491492
)
492493

493494
event = events[0]
494-
assert event["request"]["data"] == {"password": "[Filtered]"}
495+
# Expectation in data collection is that the user scrubs this within `before_send`
496+
assert event["request"]["data"] == {"password": "secret"}
495497
assert event["request"]["headers"]["authorization"] == "[Filtered]"
496498
assert event["request"]["headers"]["proxy-authorization"] == "[Filtered]"
497499

‎tests/integrations/flask/test_flask.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,13 +939,17 @@ def index():
939939
assert response.data == b"hi"
940940

941941

942-
def test_request_not_modified_by_reference(sentry_init, capture_events, app):
942+
def test_request_not_modified_by_reference(
943+
sentry_init, capture_events, app, monkeypatch
944+
):
943945
sentry_init(
944946
integrations=[
945947
flask_sentry.FlaskIntegration(),
946948
LoggingIntegration(event_level=logging.ERROR),
947-
]
949+
],
950+
data_collection={},
948951
)
952+
monkeypatch.setattr(flask_sentry, "flask_login", None)
949953

950954
@app.route("/", methods=["POST"])
951955
def index():
@@ -969,7 +973,9 @@ def index():
969973

970974
(event,) = events
971975

972-
assert event["request"]["data"]["password"] == "[Filtered]"
976+
# In data collection, request bodies need to be handled in the before_send
977+
# callback, so it's expected that the event will contain the raw value.
978+
assert event["request"]["data"]["password"] == "ohno"
973979
assert event["request"]["headers"]["Authorization"] == "[Filtered]"
974980
assert event["request"]["headers"]["Proxy-Authorization"] == "[Filtered]"
975981

‎tests/integrations/starlette/test_starlette.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,8 @@ async def _error(request):
14041404
)
14051405

14061406
event = events[0]
1407-
assert event["request"]["data"] == {"password": "[Filtered]"}
1407+
# Expectation in data collection is that the user scrubs this within `before_send`
1408+
assert event["request"]["data"] == {"password": "ohno"}
14081409
assert event["request"]["headers"]["authorization"] == "[Filtered]"
14091410
assert event["request"]["headers"]["proxy-authorization"] == "[Filtered]"
14101411

‎tests/integrations/tornado/test_tornado.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ def get(self):
7777

7878
# Sent by every data-collection cookie test below. Mixes benign cookies
7979
# (``theme``, ``lang``) with ones whose names match the data-collection
80-
# sensitive denylist (``jwt``, ``identity``). Those two names are deliberately
81-
# NOT in the ``EventScrubber`` denylist (which matches keys exactly), so any
82-
# filtering we observe on them comes from the extractor's data-collection
83-
# logic, not the always-on scrubber.
80+
# sensitive denylist (``jwt``, ``identity``).
8481
COOKIE_HEADER = "jwt=tokenval; theme=dark; lang=en; identity=alice"
8582

8683

0 commit comments

Comments
 (0)