import { GLOBAL_OBJ, defineIntegration, consoleSandbox, hasSpansEnabled } from '@sentry/core'; import { DEFAULT_ROOT_SPAN_TIMEOUT, DEFAULT_HOOKS } from './constants.js'; import { DEBUG_BUILD } from './debug-build.js'; import { attachErrorHandler } from './errorhandler.js'; import { instrumentAppMountWithoutMixin } from './rootInstrumentation.js'; import { createTracingMixins } from './tracing.js'; const globalWithVue = GLOBAL_OBJ; const DEFAULT_CONFIG = { Vue: globalWithVue.Vue, attachProps: true, attachErrorHandler: true, tracingOptions: { hooks: DEFAULT_HOOKS, timeout: DEFAULT_ROOT_SPAN_TIMEOUT, trackComponents: false } }; const INTEGRATION_NAME = "Vue"; const vueIntegration = defineIntegration((integrationOptions = {}) => { return { name: INTEGRATION_NAME, setup(client) { const options = { ...DEFAULT_CONFIG, ...client.getOptions(), ...integrationOptions }; if (!options.Vue && !options.app) { consoleSandbox(() => { console.warn( "[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured. Update your `Sentry.init` call with an appropriate config option: `app` (Application Instance - Vue 3) or `Vue` (Vue Constructor - Vue 2)." ); }); return; } if (options.app) { const apps = Array.isArray(options.app) ? options.app : [options.app]; apps.forEach((app) => vueInit(app, options)); } else if (options.Vue) { vueInit(options.Vue, options); } } }; }); const vueInit = (app, options) => { if (DEBUG_BUILD) { const appWithInstance = app; const isMounted = appWithInstance._instance?.isMounted; if (isMounted === true) { consoleSandbox(() => { console.warn( "[@sentry/vue]: Misconfigured SDK. Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`." ); }); } } if (options.attachErrorHandler) { attachErrorHandler(app, options); } if (hasSpansEnabled(options)) { const mixins = createTracingMixins(options.tracingOptions); app.mixin(mixins); if (!mixinWasApplied(app, mixins)) { instrumentAppMountWithoutMixin(app, mixins); warnAboutLostComponentTracking(app, options.tracingOptions); } } }; function mixinWasApplied(app, mixin) { const mixins = app._context?.mixins; return !mixins || mixins.includes(mixin); } function warnAboutLostComponentTracking(app, tracingOptions) { const trackComponents = tracingOptions?.trackComponents; const losesComponentSpans = trackComponents === true || Array.isArray(trackComponents) && trackComponents.length > 0; if (!losesComponentSpans) { return; } const fix = "$nuxt" in app ? "Set `vue: { optionsApi: true }` in your `nuxt.config.ts`." : "Set `__VUE_OPTIONS_API__` to `true` in the `define` config of your bundler."; consoleSandbox(() => { console.warn( `[@sentry/vue]: The Vue Options API is disabled (\`__VUE_OPTIONS_API__: false\`). Sentry still records the \`Application Render\` and root component mount spans, but component tracking (\`trackComponents\`) needs the Options API. ${fix}` ); }); } export { vueIntegration }; //# sourceMappingURL=integration.js.map