Scoped Sentry Reporter
Why?
In most cases, it is sufficient to initialize Sentry on a project level.
Unfortunately, we needed a solution in which errors from different sources (javascript files) can be reported to different Sentry DSNs. We embed scripts from other projects that can also run on their own, directly into our main platform.
This repo deals with abovementioned errors and makes sure sourcemaps are working.
How?
Install
yarn add @titelmedia/scoped-sentry-reporter
npm install @titelmedia/scoped-sentry-reporter --save
Usage
import ReporterManager from '@titelmedia/scoped-sentry-reporter';
ReporterManager.initSentry('YOUR_DSN@sentry.io/GOES_HERE', [/.*/], {
});
Advanced Usage
The function initSentry
expects an array of regular expressions as the second argument. With these, you can define patterns so that stackTraces
will be picked up and logged into the defined Sentry account.
ReporterManager.initSentry('YOUR_DSN@sentry.io/GOES_HERE', [/.*\/path\/to\/a\/file\.js/]);
The conditional logic is based on the Boolean operator or
and will log the error to the respective DSN if one of the urls in the stackTraces
match one of the conditions.
ReporterManager.initSentry('YOUR_DSN@sentry.io/GOES_HERE', [
/.*\/a\.js/,
/.*\/b\.js/,
/.*\/c\.js/
]);
Use a default reporter when nothing matches your conditions.
ReporterManager.initSentry('YOUR_DSN@sentry.io/GOES_HERE', [/.*\/(a|b|c)\.js/]);
ReporterManager.setDefaultReporter('YOUR_DSN@sentry.io/GOES_HERE', {
});
Infos and Culprits
One big culprit could be that you'd expect the manager to report one error to all instances. This is not intended to work. The error should be logged into the Sentry instance that is closer to the thrown error location - this saves some duplicates on different Sentry projects.
Aditionally, the reporter only works in browsers.