Search code examples
reactjssentry

Is there an include parameter for sentry/browser to include only specific files?


I want to add sentry to my React widget. it's a Hotel Reservation widget and lots of hotels use it.I added @senty/browser to the project and now there is a problem whenever any error happens in their websites i receive an issue from sentry. but i don't want to get errors from their codes.

here's my simple Sentry config code:

import * as Sentry from '@sentry/browser'

Sentry.init({
    dsn: SENTRY_DSN
})

I want a way to tell sentry only send errors from the widget scope ( only from some js files that belongs to the widget). Any help would be appreciated.

I searched and all i found was "beforeSend" function that will be called before sending the issue. but i couldn't figure it out. the data argument of beforeSend does not contain any usefull data for checking whether the error is from my code or not. and I don't know if it's possible to prevent sending issue inside beforeSend.

PS: the way that these hotels add the widget to their website is simple. they just have to add a script tag to the footer of their website (the built main.js of my project) and a div tag in wherever they want the widget to be placed (this div tag must have a specific ID).


Solution

  • Try use this one:

    import * as Sentry from '@sentry/browser';
    
    init({
      beforeSend(event, hint) {
        const error = hint.originalException;
        if (error && error.message && error.message.match(/database unavailable/i)) {
          event.fingerprint = ['database-unavailable'];
        }
        return event;
      }
    });
    

    Gihtub issue