postiz/libraries/react-shared-libraries/src/sentry/initialize.sentry.next.basi...

57 lines
1.5 KiB
TypeScript

import * as Sentry from '@sentry/nextjs';
export const initializeSentryBasic = (environment: string, dsn: string, extension: any) => {
if (!dsn) {
return;
}
const ignorePatterns = [
/^Failed to fetch$/,
/^Failed to fetch .*/i,
/^Load failed$/i,
/^Load failed .*/i,
/^NetworkError when attempting to fetch resource\.$/i,
/^NetworkError when attempting to fetch resource\. .*/i,
];
try {
Sentry.init({
initialScope: {
tags: {
service: 'frontend',
component: 'nextjs',
replaysEnabled: 'true',
},
contexts: {
app: {
name: 'Postiz Frontend',
version: process.env.NEXT_PUBLIC_APP_VERSION || '0.0.0',
},
},
},
environment: environment || 'development',
dsn,
sendDefaultPii: true,
...extension,
debug: environment === 'development',
tracesSampleRate: environment === 'development' ? 1.0 : 0.3,
beforeSend(event, hint) {
if (event.exception && event.exception.values) {
for (const exception of event.exception.values) {
if (exception.value) {
for (const pattern of ignorePatterns) {
if (pattern.test(exception.value)) {
return null; // Ignore the event
}
}
}
}
}
return event; // Send the event to Sentry
},
});
} catch (err) {}
};