Files
web/apps/scandic-web/instrumentation.ts
Joakim Jäderberg 79f1c516c0 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
2025-12-17 12:46:07 +00:00

42 lines
1.1 KiB
TypeScript

import * as Sentry from "@sentry/nextjs"
import { TRPCError } from "@trpc/server"
import { env } from "./env/server"
export const denyUrls: (string | RegExp)[] = [
// Ignore preview urls
/\/.{2}\/preview\//,
]
export async function register() {
await configureSentry()
}
export const onRequestError = Sentry.captureRequestError
async function configureSentry() {
Sentry.init({
dsn: "https://fe39c070b4154e2f9cc35f0e5de0aedb@o4508102497206272.ingest.de.sentry.io/4508102500286544",
environment: env.SENTRY_ENVIRONMENT,
enabled: env.SENTRY_ENVIRONMENT !== "development",
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
},
})
}