opnform-host-nginx/client/plugins/sentry.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

import * as Sentry from "@sentry/vue"
2024-01-17 19:32:17 +01:00
function getSentryIntegrations() {
// don't load on server
if (!import.meta.client) return []
2024-01-17 19:32:17 +01:00
const router = useRouter()
2024-01-17 19:32:17 +01:00
const browserTracing = new Sentry.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router),
})
2024-01-17 19:32:17 +01:00
return [browserTracing]
2024-01-17 19:32:17 +01:00
}
export default defineNuxtPlugin({
name: "sentry",
2024-01-17 19:32:17 +01:00
parallel: true,
async setup(nuxtApp) {
const vueApp = nuxtApp.vueApp
2024-01-17 19:32:17 +01:00
const config = useRuntimeConfig()
2024-01-17 19:32:17 +01:00
Sentry.init({
app: vueApp,
dsn: config.public.SENTRY_DSN_PUBLIC ?? null,
integrations: getSentryIntegrations(),
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: config.public.SENTRY_TRACES_SAMPLE_RATE,
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
// tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
// This sets the sample rate. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: config.public.SENTRY_REPLAY_SAMPLE_RATE,
// If the entire session is not sampled, use the below sample rate to sample
// sessions when an error occurs.
replaysOnErrorSampleRate: config.public.SENTRY_ERROR_REPLAY_SAMPLE_RATE,
beforeSend(event) {
2024-01-18 11:37:04 +01:00
if (event.exception.values.length) {
// Don't send validation exceptions to Sentry
if (
event.exception.values[0].type === "FetchError" &&
(event.exception.values[0].value.includes("422") ||
event.exception.values[0].value.includes("401"))
2024-01-18 11:37:04 +01:00
) {
return null
}
}
return event
2024-01-17 19:32:17 +01:00
},
})
},
})