1- import { init as browserInit , SDK_VERSION } from '@sentry/browser' ;
2- import { hasTracingEnabled } from '@sentry/core' ;
3- import { arrayify , GLOBAL_OBJ } from '@sentry/utils' ;
1+ import { defaultIntegrations , init as browserInit , SDK_VERSION } from '@sentry/browser' ;
42
5- import { DEFAULT_HOOKS } from './constants' ;
6- import { attachErrorHandler } from './errorhandler' ;
7- import { createTracingMixins } from './tracing' ;
8- import type { Options , TracingOptions , Vue } from './types' ;
9-
10- const globalWithVue = GLOBAL_OBJ as typeof GLOBAL_OBJ & { Vue : Vue } ;
11-
12- const DEFAULT_CONFIG : Options = {
13- Vue : globalWithVue . Vue ,
14- attachProps : true ,
15- logErrors : true ,
16- hooks : DEFAULT_HOOKS ,
17- timeout : 2000 ,
18- trackComponents : false ,
19- _metadata : {
20- sdk : {
21- name : 'sentry.javascript.vue' ,
22- packages : [
23- {
24- name : 'npm:@sentry/vue' ,
25- version : SDK_VERSION ,
26- } ,
27- ] ,
28- version : SDK_VERSION ,
29- } ,
30- } ,
31- } ;
3+ import { VueIntegration } from './integration' ;
4+ import type { Options , TracingOptions } from './types' ;
325
336/**
347 * Inits the Vue SDK
@@ -37,56 +10,21 @@ export function init(
3710 config : Partial < Omit < Options , 'tracingOptions' > & { tracingOptions : Partial < TracingOptions > } > = { } ,
3811) : void {
3912 const options = {
40- ...DEFAULT_CONFIG ,
13+ _metadata : {
14+ sdk : {
15+ name : 'sentry.javascript.vue' ,
16+ packages : [
17+ {
18+ name : 'npm:@sentry/vue' ,
19+ version : SDK_VERSION ,
20+ } ,
21+ ] ,
22+ version : SDK_VERSION ,
23+ } ,
24+ } ,
25+ defaultIntegrations : [ ...defaultIntegrations , new VueIntegration ( ) ] ,
4126 ...config ,
4227 } ;
4328
4429 browserInit ( options ) ;
45-
46- if ( ! options . Vue && ! options . app ) {
47- // eslint-disable-next-line no-console
48- console . warn (
49- `[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured.
50- Update your \`Sentry.init\` call with an appropriate config option:
51- \`app\` (Application Instance - Vue 3) or \`Vue\` (Vue Constructor - Vue 2).` ,
52- ) ;
53- return ;
54- }
55-
56- if ( options . app ) {
57- const apps = arrayify ( options . app ) ;
58- apps . forEach ( app => vueInit ( app , options ) ) ;
59- } else if ( options . Vue ) {
60- vueInit ( options . Vue , options ) ;
61- }
6230}
63-
64- const vueInit = ( app : Vue , options : Options ) : void => {
65- // Check app is not mounted yet - should be mounted _after_ init()!
66- // This is _somewhat_ private, but in the case that this doesn't exist we simply ignore it
67- // See: https://github.com/vuejs/core/blob/eb2a83283caa9de0a45881d860a3cbd9d0bdd279/packages/runtime-core/src/component.ts#L394
68- const appWithInstance = app as Vue & {
69- _instance ?: {
70- isMounted ?: boolean ;
71- } ;
72- } ;
73-
74- const isMounted = appWithInstance . _instance && appWithInstance . _instance . isMounted ;
75- if ( isMounted === true ) {
76- // eslint-disable-next-line no-console
77- console . warn (
78- '[@sentry/vue]: Misconfigured SDK. Vue app is already mounted. Make sure to call `app.mount()` after `Sentry.init()`.' ,
79- ) ;
80- }
81-
82- attachErrorHandler ( app , options ) ;
83-
84- if ( hasTracingEnabled ( options ) ) {
85- app . mixin (
86- createTracingMixins ( {
87- ...options ,
88- ...options . tracingOptions ,
89- } ) ,
90- ) ;
91- }
92- } ;
0 commit comments