We’re attempting to use the beforeSend option to filter a cacophony of bogus errors coming from various scripts (ads, trackers, beacons) injected by our business partners.
However, I am not seeing any effect on our event load; all the matching events end up on the Sentry dashboard.
Unfortunately, while I’ve been able to verify that filtering in general works, I cannot consistently reproduce the errors we want to filter in the filter place. Many of them are AMP errors that I cannot manually trigger.
This is our logic:
import * as Sentry from '@sentry/browser';
Sentry.init({
...,
beforeSend: (event, hint) => {
let ignore = false;
const err = hint && hint.originalException;
if (err) {
ignore = shouldIgnoreException(err.message) || shouldIgnoreException(err.stack);
}
if (!ignore) {
const parsedStack = hint && hint.stack && hint.stack.stack;
if (parsedStack) {
ignore = parsedStack.find(s => shouldIgnoreException(s.url));
}
}
if (ignore) {
return null;
}
return event;
}
});
const IGNORE = [
/\/xsca\.[0-9.]+\.js\b/,
/https:\/\/raw\.githubusercontent\.com\/ampproject\/amphtml\//,
/\/instream\/video\/client\.js/,
/\/ads\/scripts\/iiq_ev1\.js/,
/\/vpaid\/units\/.*cmTagEXPANDABLE\.js/,
/amp4ads-v0\.js/,
/cmTagEXPANDABLE\.js/,
/\/moatvideo\.js/,
/\/load_tags\.js/,
/Bootstrap's JavaScript requires jQuery/,
/\/pageFold\/ftpagefold_/,
/\/gtm\.js\b/,
/\/metrics\.js\b/,
/\/pagead\/expansion_embed\.js\b/,
/\/js\/sdkloader\/ima3\.js\b/,
/\/rq\/iv\/inside\.js\b/,
/\/hearst\/news-3p\//,
/should_do_lastpass_here/,
/\/jquery\.min\.js\b/,
/tags\.crwdcntrl\.net/,
// Innocuous browser errors
/ResizeObserver loop limit exceeded/,
/ResizeObserver loop completed with undelivered notifications/,
/Can't execute code from a freed script/,
/\bmoz-extension:\/\//,
// Caused by reCAPTCHA library
/reCAPTCHA placeholder element must be an element or id/,
// This one happens frequently, unknown source
/UnhandledRejection: "Timeout"/
];
function shouldIgnoreException(s) {
return s && IGNORE.find(pattern => pattern.test(s));
}