import { getClient, GLOBAL_OBJ } from "@sentry/core"; import { browserTracingIntegration, vueIntegration } from "@sentry/vue"; import { defineNuxtPlugin, isNuxtError } from "nuxt/app"; import { reportNuxtError } from "../utils.js"; export default defineNuxtPlugin({ name: "sentry-client-integrations", dependsOn: ["sentry-client-config"], async setup(nuxtApp) { if (typeof __SENTRY_TRACING__ === "undefined" || __SENTRY_TRACING__) { const sentryClient = getClient(); if (sentryClient && "$router" in nuxtApp) { sentryClient.addIntegration( browserTracingIntegration({ router: nuxtApp.$router, routeLabel: "path" }) ); } } nuxtApp.hook("app:created", (vueApp) => { const sentryClient = getClient(); if (sentryClient) { sentryClient.addIntegration( vueIntegration({ // We pick up the options from the "fake" vueIntegration exported by the SDK. ...GLOBAL_OBJ._sentryNuxtVueIntegrationOptions, app: vueApp, attachErrorHandler: false }) ); } }); nuxtApp.hook("app:error", (error) => { if (isNuxtError(error)) { if (error?.statusCode && error.statusCode >= 300 && error.statusCode < 500) { return; } } reportNuxtError({ error }); }); nuxtApp.hook("vue:error", (error, instance, info) => { reportNuxtError({ error, instance, info }); }); } });