Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/nuxt/src/runtime/plugins/sentry.client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getClient, GLOBAL_OBJ } from '@sentry/core';
import { browserTracingIntegration, vueIntegration } from '@sentry/vue';
import { getClient, GLOBAL_OBJ, setRouteProvider } from '@sentry/core';
import { browserTracingIntegration, createVueRouteProvider, vueIntegration } from '@sentry/vue';
import { defineNuxtPlugin, isNuxtError } from 'nuxt/app';
import type { GlobalObjWithIntegrationOptions } from '../../client/vueIntegration';
import { reportNuxtError } from '../utils';
Expand Down Expand Up @@ -35,6 +35,18 @@ export default defineNuxtPlugin({
name: 'sentry-client-integrations',
dependsOn: ['sentry-client-config'],
async setup(nuxtApp) {
// Registered outside the tracing guard, because route parameterization should not depend on
// tracing: anything that needs a route name (bfcache metrics, web vitals) can resolve one even
// when tracing is tree-shaken away. Nuxt installs the router before its plugins run, so unlike
// `@sentry/vue` this can read it straight off `nuxtApp`.
const client = getClient();
if (client && '$router' in nuxtApp) {
setRouteProvider(
createVueRouteProvider(() => nuxtApp.$router),
client,
);
}

// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
// will get tree-shaken away
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
Expand Down
Loading