Filtering events by browser.name

We get a lot of noise from browsers that we would rather ignore.

Based on the JavaScript example here

I tried to filter out by Chrome Mobile WebView and PhantomJS.

Sentry.init({
    dsn: "https://xxxxxx.ingest.sentry.io/xxxx",
    TracesSampleRate: 1.0,
    release: '2021-11-18 (Iteration)',
    beforeSend(event) {
        debugger ;if (event.browser === 'Chrome Mobile WebView' || event.browser === 'PhantomJS') {
            return null;
        }
    },
    denyUrls: [/static\.klaviyo\.com\/onsite\/js\/fender_analytics/i, ],
});

However, the event object doesn’t have a browser property, nor does it have a user property, as the Sentry document’s code example demonstrates.

Am I missing something? How can I filter out browsers by name?

Hi there,

sharing this for any future visitors to this thread as well:

The reason there is no browser property on the event object is because we interpret event.request values and and use the information from “User-Agent” header to set the browser and device contexts when we process the event.

You might want to conditionally initialize the SDK based on the browser. In that case you could consider using the same package we use on our server to parse the User-Agent:

GitHub - ua-parser/uap-python: Python implementation of ua-parser

I believe there is a JavaScript version of this package.

When the page begins loading you can evaluate the browser and only initialize the SDK for browsers you’d like to monitor.

It’s a little cleaner and also works for ensuring transactions are also not created for unwanted browsers.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.