whitelistUrls does not work as expected
- [x] Review the documentation: https://docs.sentry.io/
- [x] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- [x] Use the latest release: https://github.com/getsentry/sentry-javascript/releases
Package + Version
- [x]
@sentry/browser - [x]
raven-js
Version:
4.3.0
Description
I replaced version 3.22.1 with 4.3.0 (tried both cdn and npm) and was faced with the fact that, despite the whitelistUrl parameter, sentry captures errors not only from my application.
After researching, I found differences in the whitelist urls checking:
raven-js
https://github.com/getsentry/sentry-javascript/blob/master/packages/raven-js/src/raven.js#L1738
@sentry/browser
https://github.com/getsentry/sentry-javascript/blob/master/packages/core/src/integrations/inboundfilters.ts#L177
So, raven-js reverses frames and whitelist filtering works correctly.
Sentry 4.3.0 (npm) stacktrace example:
"stacktrace":{
"frames":[
{
"function":"r",
"abs_path":"[my_app_path]/static/js/bundle.c67a93af.js",
"post_context":[
"//# sourceMappingURL=bundle.c67a93af.js.map"
],
"filename":"[my_app_path]/static/js/bundle.c67a93af.js",
"lineno":1,
"colno":304792,
"in_app":false,
"context_line":"{snip} (e,t)});return e.handleEvent?e.handleEvent.apply(this,a):e.apply(this,a)}catch(e){throw De+=1,setTimeout(function(){De-=1}),o.withScope(func {snip}"
},
{
"function":"onPostMessage",
"abs_path":"https://api.odnoklassniki.ru/js/fapi5.js",
"in_app":true,
"lineno":1,
"colno":2028,
"filename":"/js/fapi5.js"
}
]
}
Sentry init config:
Sentry.init({
dsn: '...',
release: '...',
environment: process.env.APP_ENV,
whitelistUrls: [/static\/js\/bundle/],
});
An error occurred in another file ("filename":"/js/fapi5.js"), but @sentry/browser doesn't filter this error, but raven-js do.
I would like to know if this is a planned behavior, or is it a bug?
We do reverse them in @sentry/browser as well, but in a more generic place - https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/parsers.ts#L61-L86
The thing is that we had to decide what to filter on. The origin of the error? Or the place where it was initiated? We chose later, as those are errors that user has control over.
whitelistUrl is in most cases used when someone embeds 3rd-party JS code and it lives it's own life, eg. some widgets, tracking, ads etc. In this cases, the only way to control them is indeed whitelisting/blacklisting (all frames will be coming from the library itself).
If you need to filter it in any other way, you can use beforeSend or addEventProcessor where you can check all frames for it's source.
I got it. Your decision makes sense. Thank you very much!
Cheers! :)
FYI, this was changed in 4.6.0.