I have intergated Sentry to my Node Js application.
Based on filter documentation we can filter exception for Sentry to not send the report.
And my case Sentry will report when an api request responded 404 not_found
that I can see the report detail throw Sentry Breadcrumb. I don’t think filter event throw Sentry.breadcrumb is the best since breadcrumb can be contructed alternatively Breadcrumb interface
Sentry has provided beforeSend
callback to get the exception event.
Here I have implemented a filter logic of beforeSend
I want to know if there is any better way to achieve this ? Since somehow I still see Sentry manage to report issue with my logic even all the pattern is match and conditions are true.
Sentry.init({
dsn: environment.sentry,
environment: environment,
integrations: [
new Sentry.BrowserTracing({
tracePropagationTargets: ...,
routingInstrumentation: Sentry.routingInstrumentation
}),
new Sentry.Replay()
],
tracesSampleRate: .., // Capture 100% of the transactions, reduce in production!
replaysSessionSampleRate: ...,
replaysOnErrorSampleRate: ...,
beforeSend: notReportException <--- filter function
});
And implement of notReportException
function noDevicesException(event: Sentry.Event) {
const exceptURL = ..... <- API url
const exceptAPIEvent = event.breadcrumbs?.find((b) =>
exceptURL.test(b.data?.url) <- check if event caused by calling this API URL
);
if (
exceptAPIEvent?.data?.method === 'GET' && <- specify method and http response code
exceptAPIEvent?.data?.status_code === 404
) {
return null; <--- return no event so Sentry doesn't send report
}
return event;
}