Ramūnas
Ramūnas

Reputation: 1634

Exclude nextjs api url from sentry events

I have nextjs app with sentry. I want to add new api route, for example api/status, but I want to exclude it from being sent to sentry as it will clutter logs really fast and use my qouta.

I did a small research and it seems that there is an array of urls you can exclude from being tracked. It's called denyUrls. Read more. I have tried to add my url to this array, but it still tracks this url as part of events:

Sentry.init({
  ...
  denyUrls: [
    /api\/status/i,
  ],
  ...
});

Am I configuring something wrong or this array is not for the purpose of filtering everts.

If so, what's the best way to filter those? Other option I found which I will try next is beforeSend but it feels a bit overkill to simply exclude url. denyUrls feels like much better fit for what I am trying to achieve

Upvotes: 2

Views: 1466

Answers (1)

Julien Bonte
Julien Bonte

Reputation: 21

I had the same issue and contacted the support for it. I am directly quoting the support here.

The BeforeSend and DenyUrl are options to filter error events, not transactions. For transaction events, please use the tracesSampler function as described on the page: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/sampling/#setting-a-sampling-function. Here is an example to drop all transactions that match a certain name:

tracesSampler: samplingContext => {
   if(samplingContext.transactionContext.name == "GET /api/health"){
    return 0.0 // never send transactions with name GET /api/health
   }
   return 0.2 // sampling for all other transactions
   }

Note that you might need to customise the function above to better match your scenario.

I hope it will help you ;) Have a nice day.

Upvotes: 2

Related Questions