-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathintegration.ts
79 lines (69 loc) · 2.62 KB
/
integration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { GLOBAL_OBJ, consoleSandbox, defineIntegration, hasTracingEnabled } from '@sentry/core';
import { DEFAULT_HOOKS } from './constants';
import { DEBUG_BUILD } from './debug-build';
import { attachErrorHandler } from './errorhandler';
import { createTracingMixins } from './tracing';
import type { Options, Vue, VueOptions } from './types';
const globalWithVue = GLOBAL_OBJ as typeof GLOBAL_OBJ & { Vue: Vue };
const DEFAULT_CONFIG: VueOptions = {
Vue: globalWithVue.Vue,
attachProps: true,
attachErrorHandler: true,
tracingOptions: {
hooks: DEFAULT_HOOKS,
timeout: 2000,
trackComponents: false,
},
};
const INTEGRATION_NAME = 'Vue';
export type VueIntegrationOptions = Partial<VueOptions>;
export const vueIntegration = defineIntegration((integrationOptions: Partial<VueOptions> = {}) => {
return {
name: INTEGRATION_NAME,
setup(client) {
const options: Options = { ...DEFAULT_CONFIG, ...client.getOptions(), ...integrationOptions };
if (!options.Vue && !options.app) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
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: Vue, options: Options): void => {
if (DEBUG_BUILD) {
// Check app is not mounted yet - should be mounted _after_ init()!
// This is _somewhat_ private, but in the case that this doesn't exist we simply ignore it
// See: https://github.com/vuejs/core/blob/eb2a83283caa9de0a45881d860a3cbd9d0bdd279/packages/runtime-core/src/component.ts#L394
const appWithInstance = app as Vue & {
_instance?: {
isMounted?: boolean;
};
};
const isMounted = appWithInstance._instance?.isMounted;
if (isMounted === true) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
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 (hasTracingEnabled(options)) {
app.mixin(createTracingMixins(options.tracingOptions));
}
};