|
1 | 1 | import { getClient } from '@sentry/core';
|
2 |
| -import { browserTracingIntegration, vueIntegration } from '@sentry/vue'; |
| 2 | +import { consoleSandbox } from '@sentry/utils'; |
| 3 | +import { browserTracingIntegration, createSentryPiniaPlugin, vueIntegration } from '@sentry/vue'; |
3 | 4 | import { defineNuxtPlugin } from 'nuxt/app';
|
4 | 5 | import { reportNuxtError } from '../utils';
|
5 | 6 |
|
@@ -34,18 +35,36 @@ export default defineNuxtPlugin({
|
34 | 35 | name: 'sentry-client-integrations',
|
35 | 36 | dependsOn: ['sentry-client-config'],
|
36 | 37 | async setup(nuxtApp) {
|
| 38 | + const sentryClient = getClient(); |
| 39 | + const clientOptions = sentryClient && sentryClient.getOptions(); |
| 40 | + |
37 | 41 | // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
|
38 | 42 | // will get tree-shaken away
|
39 | 43 | if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
|
40 |
| - const sentryClient = getClient(); |
41 |
| - |
42 | 44 | if (sentryClient && '$router' in nuxtApp) {
|
43 | 45 | sentryClient.addIntegration(
|
44 | 46 | browserTracingIntegration({ router: nuxtApp.$router as VueRouter, routeLabel: 'path' }),
|
45 | 47 | );
|
46 | 48 | }
|
47 | 49 | }
|
48 | 50 |
|
| 51 | + if (clientOptions && 'trackPinia' in clientOptions && clientOptions.trackPinia) { |
| 52 | + if ('$pinia' in nuxtApp) { |
| 53 | + (nuxtApp.$pinia as { use: (plugin: unknown) => void }).use( |
| 54 | + // `trackPinia` is an object with custom options or `true` (pass `undefined` to use default options) |
| 55 | + createSentryPiniaPlugin(clientOptions.trackPinia === true ? undefined : clientOptions.trackPinia), |
| 56 | + ); |
| 57 | + } else { |
| 58 | + clientOptions.debug && |
| 59 | + consoleSandbox(() => { |
| 60 | + // eslint-disable-next-line no-console |
| 61 | + console.warn( |
| 62 | + '[Sentry] You set `trackPinia`, but the Pinia module was not found. Make sure to add `"@pinia/nuxt"` to your modules array.', |
| 63 | + ); |
| 64 | + }); |
| 65 | + } |
| 66 | + } |
| 67 | + |
49 | 68 | nuxtApp.hook('app:created', vueApp => {
|
50 | 69 | const sentryClient = getClient();
|
51 | 70 |
|
|
0 commit comments