A lightweight and flexible Python library for scrubbing sensitive information from Sentry events before they are sent to the server.
✅ Automatically detects and removes sensitive data (e.g., usernames, IP addresses, hashes).
✅ Supports recursive scrubbing of complex event structures.
✅ Customizable rules for scrubbing specific fields.
✅ Seamless integration with Sentry SDK via before_send
hook.
✅ Minimal performance overhead.
Install sentry-scrubber
using pip
:
pip install sentry-scrubber
import sentry_sdk
from sentry_scrubber import SentryScrubber
scrubber = SentryScrubber()
sentry_sdk.init(
dsn="your_sentry_dsn",
before_send=scrubber.scrub_event # Attach scrubbing function
)
event = {
"user": {"username": "john_doe"},
"request": {"ip_address": "192.168.1.1"},
"extra": {"hash": "3030303030303030303030303030303030303030"},
}
scrubbed_event = scrubber.scrub_event(event)
print(scrubbed_event)
text = "A user logged in from 192.168.1.1"
scrubbed_text = scrubber.scrub_text(text)
print(scrubbed_text) # Output: "A user logged in from <IP>"
- Replaces sensitive values with placeholders (e.g.,
<USERNAME>
,<IP>
,<HASH>
). - Uses regex patterns to detect and sanitize usernames, IPs, and hashes.
- Recursively processes dictionaries and lists to ensure deep scrubbing.
- Can be customized to add or exclude certain fields.
You can configure the scrubber by modifying its attributes:
scrubber.dict_keys_for_scrub.append("api_key") # Add a new sensitive key
scrubber.event_fields_to_cut.append("debug_info") # Remove specific event fields
This project is licensed under the MIT License.