fix(scrubber): Remove ip_address instead of replacing with [Filtered]#5783
Open
joaquinhuigomez wants to merge 1 commit intogetsentry:masterfrom
Open
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
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Anthropic
Other
Documentation 📚
Internal Changes 🔧
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.