Immutable solution version
Sentry beforeSend: scrub PII without silently dropping everything
Complete solution
beforeSend is the last chance to scrub PII or drop an event, but returning nothing drops it silently. Plus the v11 dataCollection categories and the built-in sensitive-key denylist.
Sentry beforeSend: scrub PII without silently dropping everything
The callback
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSend(event) {
if (event.user) {
delete event.user.email; // keep the id, drop the address
}
return event; // ALWAYS return the event, or return null to drop deliberately
},
});The classic bug: a beforeSend that mutates the event but forgets to return it. In JS that returns undefined, which the SDK treats as drop. Events vanish with no error. If volume craters after adding beforeSend, read the function first.
Prefer category control over hand-scrubbing (v11)
sendDefaultPii is replaced by dataCollection, with per-category switches:
dataCollection: {
userInfo: false,
cookies: false,
httpBodies: [],
urlQueryParams: { deny: ["forwarded", "-ip"] },
}Warning from the migration guide: the v11 default collects MORE than v10 did (user info, cookies, request/response bodies, genAI inputs/outputs). If you relied on the v10 restrictive default, set the baseline explicitly or you start shipping data you never approved.
The built-in denylist
The SDK always scrubs values whose keys look sensitive (auth, token, secret, password) and sends [Filtered]. Treat it as best effort: it matches on the key name, so a credential in a field named customer_ref sails through. Name sensitive fields like they are sensitive, or scrub them in beforeSend.
Layer the defenses
dataCollectioncategories: collect only what you need.beforeSend: surgical redaction of the rest.- Server-side scrubbing in project settings: backstop for anything the SDK missed.
Cheaper filters first: ignoreErrors for known noise and denyUrls/allowUrls for third-party script errors cost less than a beforeSend that parses every event.
Evidence
Researched against live Sentry docs 2026-09-26. The JS filtering page (docs.sentry.io/platforms/javascript/configuration/filtering/) documents beforeSend receiving the event and dropping it by returning null, the ignoreErrors/allowUrls/denyUrls options, and the thirdPartyErrorFilterIntegration (needs bundler applicationKey). The v10-to-v11 migration guide (docs.sentry.io/platforms/javascript/migration/v10-to-v11/) documents sendDefaultPii replaced by dataCollection with per-category defaults (v11 default collects more: userInfo, cookies, httpBodies, genAI inputs/outputs now on) and the built-in scrub that sends [Filtered] for values whose keys look like auth, token, secret, or password. The Python filtering page (docs.sentry.io/platforms/python/configuration/filtering/) covers before_send and the hint object.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_XIH54XXSl_LW90lBmQ8V7Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Sentry beforeSend: scrub PII without silently dropping everything <span>— Vectle</span></a>