2021-09-06 20:49:13 +00:00
|
|
|
import * as Sentry from "@sentry/node";
|
|
|
|
import getConfig from "next/config";
|
2021-09-06 20:58:31 +00:00
|
|
|
import type { Integration } from "@sentry/types";
|
2021-09-06 20:49:13 +00:00
|
|
|
import { RewriteFrames } from "@sentry/integrations";
|
2021-09-06 20:58:31 +00:00
|
|
|
import { Integrations as TracingIntegrations } from "@sentry/tracing";
|
2021-09-06 20:49:13 +00:00
|
|
|
|
|
|
|
if (process.env.SENTRY_DSN) {
|
|
|
|
const config = getConfig();
|
|
|
|
const distDir = `${config.serverRuntimeConfig.rootDir}/.next`;
|
2021-09-06 20:58:31 +00:00
|
|
|
const integrations: Integration[] = [
|
|
|
|
new RewriteFrames({
|
|
|
|
iteratee: (frame) => {
|
|
|
|
frame.filename = frame.filename!.replace(distDir, "app:///_next");
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
integrations.push(new TracingIntegrations.BrowserTracing());
|
|
|
|
} else {
|
|
|
|
integrations.push(new Sentry.Integrations.Http({ tracing: true }));
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:49:13 +00:00
|
|
|
Sentry.init({
|
2021-09-06 20:58:31 +00:00
|
|
|
integrations,
|
|
|
|
tracesSampleRate: 0.5,
|
2021-09-06 20:49:13 +00:00
|
|
|
dsn: process.env.SENTRY_DSN,
|
|
|
|
beforeSend(event, hint) {
|
|
|
|
const error = hint?.originalException;
|
|
|
|
if (error && typeof error !== "string") {
|
|
|
|
switch (error.name) {
|
|
|
|
case "AuthenticationError":
|
|
|
|
case "AuthorizationError":
|
|
|
|
case "NotFoundError":
|
|
|
|
case "ChunkLoadError":
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Sentry;
|