sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Ignore certain User agents?

Open jacobsvante opened this issue 10 years ago • 7 comments

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.

jacobsvante avatar Jun 21 '16 13:06 jacobsvante

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.

benvinegar avatar Jun 21 '16 20:06 benvinegar

Ah I totally missed shouldSendCallback. Thanks for that. Might not look exactly as clean but it solves my problem!

jacobsvante avatar Jun 23 '16 09:06 jacobsvante

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?

nateberkopec avatar Jul 03 '17 23:07 nateberkopec

What is the data object that is passed to shouldSendCallback? I want to target specific error messages and suppress them from being sent.

benkermode avatar Mar 08 '18 20:03 benkermode

@benkermode use ignoreErrors config - https://docs.sentry.io/clients/javascript/config/

kamilogorek avatar Mar 08 '18 20:03 kamilogorek

@kamilogorek

Should this work with new @sentry/browser? I'd like to block this specific event

Zrzut ekranu 2019-07-31 o 22 34 30
  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 avatar Aug 14 '19 13:08 hinok

@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;
  }
});

kamilogorek avatar Aug 14 '19 17:08 kamilogorek