chore(instrumentation): update error filtering and Prisma configuration

This commit is contained in:
Fatih Kadir Akın
2026-01-12 13:45:09 +03:00
parent 95ff2e2c9a
commit ff65df2f03
2 changed files with 55 additions and 10 deletions
+47
View File
@@ -4,6 +4,24 @@
import * as Sentry from "@sentry/nextjs";
// Patterns to ignore - typically from browser extensions or third-party scripts
const ignoreErrors = [
// Browser extension errors
/MetaMask/i,
/ethereum/i,
/tronlink/i,
/tron/i,
/webkit\.messageHandlers/i,
/disconnected port/i,
/__firefox__/i,
// DOM manipulation errors often caused by extensions
/removeChild.*not a child/i,
/parentNode.*null/i,
// Third-party/extension scripts
/CONFIG.*not defined/i,
/Can't find variable: CONFIG/i,
];
Sentry.init({
dsn: "https://9c2eb3b4441745efad28a908001c30bf@o4510673866063872.ingest.de.sentry.io/4510673871306832",
@@ -29,6 +47,35 @@ Sentry.init({
// Enable sending user PII (Personally Identifiable Information)
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/options/#sendDefaultPii
sendDefaultPii: true,
// Filter out browser extension and third-party script errors
beforeSend(event) {
const message = event.exception?.values?.[0]?.value || "";
const type = event.exception?.values?.[0]?.type || "";
const fullMessage = `${type}: ${message}`;
// Check if error matches any ignore pattern
if (ignoreErrors.some((pattern) => pattern.test(fullMessage))) {
return null;
}
// Filter out errors from browser extension scripts
const frames = event.exception?.values?.[0]?.stacktrace?.frames || [];
const hasExtensionFrame = frames.some((frame) => {
const filename = frame.filename || "";
return (
filename.includes("extension://") ||
filename.includes("moz-extension://") ||
filename.includes("chrome-extension://")
);
});
if (hasExtensionFrame) {
return null;
}
return event;
},
});
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
+8 -10
View File
@@ -4,20 +4,18 @@ const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
export const db =
globalForPrisma.prisma ??
new PrismaClient({
// Configure Prisma for serverless environments with connection pooling
const prismaClientSingleton = () => {
return new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
datasourceUrl: process.env.DATABASE_URL,
});
};
// Prevent connection pool exhaustion in serverless environments
if (process.env.NODE_ENV !== "production") {
globalForPrisma.prisma = db;
} else {
// In production, always use the same instance to avoid connection issues
globalForPrisma.prisma = db;
}
export const db = globalForPrisma.prisma ?? prismaClientSingleton();
// Always reuse the same instance to prevent connection pool exhaustion
globalForPrisma.prisma = db;