diff --git a/apps/partner-sas/instrumentation.ts b/apps/partner-sas/instrumentation.ts index 143576eb2..8fc33edfe 100644 --- a/apps/partner-sas/instrumentation.ts +++ b/apps/partner-sas/instrumentation.ts @@ -1,4 +1,5 @@ import * as Sentry from "@sentry/nextjs" +import { TRPCError } from "@trpc/server" import { env } from "./env/server" @@ -21,6 +22,20 @@ async function configureSentry() { tracesSampleRate: env.SENTRY_SERVER_SAMPLERATE, denyUrls: denyUrls, enableLogs: true, + enableMetrics: true, release: env.RELEASE_TAG || undefined, + beforeSend(event, hint) { + const error = hint.originalException + + // Don't send TRPCErrors with client error codes + if (error instanceof TRPCError) { + const clientErrorCodes = ["CONFLICT", "NOT_FOUND", "UNAUTHORIZED"] + if (clientErrorCodes.includes(error.code)) { + return null // Don't send to Sentry + } + } + + return event + }, }) } diff --git a/apps/scandic-web/instrumentation.ts b/apps/scandic-web/instrumentation.ts index fe6b467ac..5506ed116 100644 --- a/apps/scandic-web/instrumentation.ts +++ b/apps/scandic-web/instrumentation.ts @@ -1,4 +1,5 @@ import * as Sentry from "@sentry/nextjs" +import { TRPCError } from "@trpc/server" import { env } from "./env/server" @@ -23,5 +24,18 @@ async function configureSentry() { enableLogs: true, enableMetrics: true, release: env.RELEASE_TAG || undefined, + beforeSend(event, hint) { + const error = hint.originalException + + // Don't send TRPCErrors with client error codes + if (error instanceof TRPCError) { + const clientErrorCodes = ["CONFLICT", "NOT_FOUND", "UNAUTHORIZED"] + if (clientErrorCodes.includes(error.code)) { + return null // Don't send to Sentry + } + } + + return event + }, }) }