sentry-javascript: "Crash free rates alert on sessions" dont take into account filtering on beforeSend

Environment

SaaS (https://sentry.io/)

What are you trying to accomplish?

I am using sentry for my Nextjs app, in production for an e-commerce website.

There I am making use of the very useful alert sentry offers, “Crash free rates on sessions”.

This is my issue: I observed that most of the time that a crash happens is not because of a user, instead is caused by a bot or a crawler. What I did then was to filter out these User-Agents with the beforeSend function that Sentry.init takes as an option.

Click to view the code for filtering
export const beforeSend = (event: Event) => {
  if (
    event.request &&
    event.request.headers &&
    event.request.headers['User-Agent']
  ) {
    const userAgent = event.request.headers['User-Agent'].toLowerCase();

    const isFilteredUserAgent = filteredUserAgents.some(ua =>
      userAgent.includes(ua)
    );

    if (isFilteredUserAgent) {
      return null;
    }
  }

  return event;
};

What I try to accomplish is to have the “Crash Rates” alert ignore all the issues that are caused by bots or crawlers and focus only on the users.

How are you getting stuck?

I am stuck in the following:

After filtering out the issues caused by the bots and crawlers, these issues arent showing on the issues tab anymore, which is what I wanted. However, the crash alert will still take them into account and trigger. Screenshot attached.

image

Where in the product are you?

Alerts

Link

https://ever-cars-co.sentry.io/alerts/rules/details/211230/?end=2024-01-26T16%3A13%3A34&start=2024-01-26T13%3A43%3A31

DSN

https://b38edcab14880edffac187b70aa3483a@o4506453406908416.ingest.sentry.io/4506453430435840

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Looks good until now. No, dives of crash rates anymore 🙇

Thank you for your help on this! I will close it now

You were right 🙇 I will monitor this now a bit and let you know how it goes, soon!

Thank you for your time @lforst & @malwilley.

EDIT: What is see in first glance is that we still collect data from actual users, which is great. I will keep an eye for the crawlers the next days, and post an update here.

It’s for some reason calling that code in the server bundle. Are you sure you are not calling that function server-side (i.e. in sentry.server.config.ts)?

You could guard for this with if (typeof window !== 'undefined')