Ignore certain User agents?
One feature I'm missing from raven-js is the ability to filter out user agents that have ill-behaving or just really old javascript engines. For example I get non-reproducible errors from CloudFlare-AlwaysOnline. And I don't really want to bother if the microscopic number of IE8-9 users have some problems with the JS that I serve. Would it make sense to add an option for this?
I'm imagining something like this, using regex to allow full flexibility:
Raven.config('https://[email protected]/12345', {
ignoreUserAgents: ['^.*CloudFlare-AlwaysOnline.*$', '^.+MSIE 8.0;.+$']
}).install()
Perhaps it would make sense to add an additional option that just ignores all browsers that don't support column numbers and stack traces, as you've listed here.
So, you can do this today with shouldSendCallback:
Raven.config('https://[email protected]/12345', {
shouldSendCallback(data) {
return !/^(.*CloudFlare-AlwaysOnline.*|.+MSIE 8\.0;.+)$/.test(window.navigator.userAgent);
}
}).install();
I'm hesitant to add a bunch of convenience methods for stuff like this since it will add overhead to Raven.js, and it is frequently communicated to me how keeping Raven.js small is really important to users.
Ah I totally missed shouldSendCallback. Thanks for that. Might not look exactly as clean but it solves my problem!
I think it's a really common use case for sites to have specific browser targets (in essence, not oldIE). Surely there's a way to implement this as an ignoreUserAgent config opt without too much weight?
What is the data object that is passed to shouldSendCallback? I want to target specific error messages and suppress them from being sent.
@benkermode use ignoreErrors config - https://docs.sentry.io/clients/javascript/config/
@kamilogorek
Should this work with new @sentry/browser? I'd like to block this specific event
Sentry.init({
dsn: 'this_is_almost_secret',
maxValueLength: 2048,
environment: getEnv(),
ignoreErrors: [
/Blocked a frame with origin/,
/CloudFlare-AlwaysOnline\//, // <----- Is it going to check also user-agent?
],
});
I don't want creating new issue because I need to block CloudFlare-AlwaysOnline as @jmagnusson
@hinok
Is it going to check also user-agent?
Not in this case, user agent is extracted from the request itself. You have to check it yourself.
Sentry.init({
beforeSend(event) {
// Ignore CloudFlare crawlers
if (window.navigator.userAgent.indexOf('CloudFlare-AlwaysOnline') !== -1) return null;
return event;
}
});