fix(scrubber): Remove ip_address instead of replacing with [Filtered]#5783
Conversation
The EventScrubber replaced ip_address with [Filtered], which is not a valid IP address and causes a protocol violation on the server side. Add a remove_list parameter to EventScrubber that controls which keys are deleted entirely rather than substituted. Defaults to DEFAULT_REMOVE_LIST = ['ip_address'], so the fix works out of the box. Users can override this via the remove_list constructor argument. Fixes getsentry#5701
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Langchain
Other
Bug Fixes 🐛Anthropic
Ci
Openai
Other
Documentation 📚
Internal Changes 🔧Langchain
Openai
Other
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| from sentry_sdk import capture_exception, capture_event, start_transaction, start_span | ||
| from sentry_sdk.utils import event_from_exception | ||
| from sentry_sdk.scrubber import EventScrubber | ||
| from sentry_sdk.scrubber import EventScrubber, DEFAULT_REMOVE_LIST |
There was a problem hiding this comment.
|
This PR has been closed. The referenced issue does not show a discussion between you and a maintainer. To avoid wasted effort on both sides, please discuss your proposed approach in the issue first and wait for a maintainer to respond before opening a PR. Please review our contributing guidelines for more details. |


Fixes #5701
Problem
The
EventScrubberreplacesip_addresswith[Filtered], but[Filtered]is not a valid IP address. The Sentry server rejects it as a protocol violation, showing a processing error in the UI even though the server infers the real IP from the HTTP request.Solution
Add a
remove_listparameter toEventScrubberthat controls which denied keys are deleted from the dict instead of being replaced with[Filtered].DEFAULT_REMOVE_LIST = ["ip_address"], so the fix works out of the box.EventScrubber(remove_list=[...]).remove_list=[]restores the previous replace-with-[Filtered]behavior for all fields.This follows the approach suggested by @rodolfoBee in the issue discussion: adding an option that removes the IP address from the event instead of replacing it.
Changes
sentry_sdk/scrubber.py: NewDEFAULT_REMOVE_LISTconstant andremove_listparameter onEventScrubber.__init__. Updatedscrub_dictto delete keys in the remove list instead of substituting them.tests/test_scrubber.py: Updated existing test expectations (ip_address now absent instead of[Filtered]), added four new tests covering the user dict scenario, PII-enabled passthrough, custom remove list, and empty remove list fallback.