shellphone.app/integrations/sentry.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

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";
import { RewriteFrames } from "@sentry/integrations";
2021-09-06 20:58:31 +00:00
import { Integrations as TracingIntegrations } from "@sentry/tracing";
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 }));
}
Sentry.init({
2021-09-06 20:58:31 +00:00
integrations,
tracesSampleRate: 0.5,
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;