From 79f1c516c01b125fe3813d48b9bf731ea9963750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20J=C3=A4derberg?= Date: Wed, 17 Dec 2025 12:46:07 +0000 Subject: [PATCH] Merged in fix/dont-send-expected-error-types-to-sentry (pull request #3358) fix: don't send expected errors to Sentry * fix: don't send expected errors to Sentry * remove BAD_REQUEST from ignore-list for TRPC errors due to BAD_REQUEST being used improperly Approved-by: Anton Gunnarsson --- apps/partner-sas/instrumentation.ts | 15 +++++++++++++++ apps/scandic-web/instrumentation.ts | 14 ++++++++++++++ 2 files changed, 29 insertions(+) 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 + }, }) }