Skip to content

Commit 807883e

Browse files
authored
feat(vue): Deprecate configuring Vue tracing options anywhere else other than through the vueIntegration's tracingOptions option (#14385)
1 parent d8d9324 commit 807883e

File tree

4 files changed

+100
-36
lines changed

4 files changed

+100
-36
lines changed

docs/migration/draft-v9-migration-guide.md

+21
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@
4141

4242
- Deprecated `Request` in favor of `RequestEventData`.
4343

44+
## `@sentry/vue`
45+
46+
- Deprecated `tracingOptions`, `trackComponents`, `timeout`, `hooks` options everywhere other than in the `tracingOptions` option of the `vueIntegration()`.
47+
These options should now be set as follows:
48+
49+
```ts
50+
import * as Sentry from '@sentry/vue';
51+
52+
Sentry.init({
53+
integrations: [
54+
Sentry.vueIntegration({
55+
tracingOptions: {
56+
trackComponents: true,
57+
timeout: 1000,
58+
hooks: ['mount', 'update', 'unmount'],
59+
},
60+
}),
61+
],
62+
});
63+
```
64+
4465
## Server-side SDKs (`@sentry/node` and all dependents)
4566

4667
- Deprecated `processThreadBreadcrumbIntegration` in favor of `childProcessIntegration`. Functionally they are the same.

packages/vue/src/integration.ts

+21-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { defineIntegration, hasTracingEnabled } from '@sentry/core';
2-
import { GLOBAL_OBJ, consoleSandbox } from '@sentry/core';
3-
import type { Client, IntegrationFn } from '@sentry/types';
4-
1+
import { GLOBAL_OBJ, consoleSandbox, defineIntegration, hasTracingEnabled } from '@sentry/core';
52
import { DEFAULT_HOOKS } from './constants';
63
import { DEBUG_BUILD } from './debug-build';
74
import { attachErrorHandler } from './errorhandler';
@@ -22,38 +19,30 @@ const DEFAULT_CONFIG: VueOptions = {
2219

2320
const INTEGRATION_NAME = 'Vue';
2421

25-
const _vueIntegration = ((integrationOptions: Partial<VueOptions> = {}) => {
22+
export const vueIntegration = defineIntegration((integrationOptions: Partial<VueOptions> = {}) => {
2623
return {
2724
name: INTEGRATION_NAME,
2825
setup(client) {
29-
_setupIntegration(client, integrationOptions);
26+
const options: Options = { ...DEFAULT_CONFIG, ...client.getOptions(), ...integrationOptions };
27+
if (!options.Vue && !options.app) {
28+
consoleSandbox(() => {
29+
// eslint-disable-next-line no-console
30+
console.warn(
31+
'[@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).',
32+
);
33+
});
34+
return;
35+
}
36+
37+
if (options.app) {
38+
const apps = Array.isArray(options.app) ? options.app : [options.app];
39+
apps.forEach(app => vueInit(app, options));
40+
} else if (options.Vue) {
41+
vueInit(options.Vue, options);
42+
}
3043
},
3144
};
32-
}) satisfies IntegrationFn;
33-
34-
export const vueIntegration = defineIntegration(_vueIntegration);
35-
36-
function _setupIntegration(client: Client, integrationOptions: Partial<VueOptions>): void {
37-
const options: Options = { ...DEFAULT_CONFIG, ...client.getOptions(), ...integrationOptions };
38-
if (!options.Vue && !options.app) {
39-
consoleSandbox(() => {
40-
// eslint-disable-next-line no-console
41-
console.warn(
42-
`[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured.
43-
Update your \`Sentry.init\` call with an appropriate config option:
44-
\`app\` (Application Instance - Vue 3) or \`Vue\` (Vue Constructor - Vue 2).`,
45-
);
46-
});
47-
return;
48-
}
49-
50-
if (options.app) {
51-
const apps = Array.isArray(options.app) ? options.app : [options.app];
52-
apps.forEach(app => vueInit(app, options));
53-
} else if (options.Vue) {
54-
vueInit(options.Vue, options);
55-
}
56-
}
45+
});
5746

5847
const vueInit = (app: Vue, options: Options): void => {
5948
if (DEBUG_BUILD) {
@@ -85,6 +74,7 @@ const vueInit = (app: Vue, options: Options): void => {
8574
app.mixin(
8675
createTracingMixins({
8776
...options,
77+
// eslint-disable-next-line deprecation/deprecation
8878
...options.tracingOptions,
8979
}),
9080
);

packages/vue/src/types.ts

+57-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type ViewModel = {
2626
};
2727
};
2828

29-
export interface VueOptions extends TracingOptions {
29+
export interface VueOptions {
3030
/** Vue constructor to be used inside the integration (as imported by `import Vue from 'vue'` in Vue2) */
3131
Vue?: Vue;
3232

@@ -60,9 +60,64 @@ export interface VueOptions extends TracingOptions {
6060

6161
/** {@link TracingOptions} */
6262
tracingOptions?: Partial<TracingOptions>;
63+
64+
/**
65+
* Decides whether to track components by hooking into its lifecycle methods.
66+
* Can be either set to `boolean` to enable/disable tracking for all of them.
67+
* Or to an array of specific component names (case-sensitive).
68+
*
69+
* @deprecated Use tracingOptions
70+
*/
71+
trackComponents: boolean | string[];
72+
73+
/**
74+
* How long to wait until the tracked root activity is marked as finished and sent of to Sentry
75+
*
76+
* @deprecated Use tracingOptions
77+
*/
78+
timeout: number;
79+
80+
/**
81+
* List of hooks to keep track of during component lifecycle.
82+
* Available hooks: 'activate' | 'create' | 'destroy' | 'mount' | 'unmount' | 'update'
83+
* Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
84+
*
85+
* @deprecated Use tracingOptions
86+
*/
87+
hooks: Operation[];
6388
}
6489

65-
export interface Options extends BrowserOptions, VueOptions {}
90+
export interface Options extends BrowserOptions, VueOptions {
91+
/**
92+
* @deprecated Use `vueIntegration` tracingOptions
93+
*/
94+
tracingOptions?: Partial<TracingOptions>;
95+
96+
/**
97+
* Decides whether to track components by hooking into its lifecycle methods.
98+
* Can be either set to `boolean` to enable/disable tracking for all of them.
99+
* Or to an array of specific component names (case-sensitive).
100+
*
101+
* @deprecated Use `vueIntegration` tracingOptions
102+
*/
103+
trackComponents: boolean | string[];
104+
105+
/**
106+
* How long to wait until the tracked root activity is marked as finished and sent of to Sentry
107+
*
108+
* @deprecated Use `vueIntegration` tracingOptions
109+
*/
110+
timeout: number;
111+
112+
/**
113+
* List of hooks to keep track of during component lifecycle.
114+
* Available hooks: 'activate' | 'create' | 'destroy' | 'mount' | 'unmount' | 'update'
115+
* Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
116+
*
117+
* @deprecated Use `vueIntegration` tracingOptions
118+
*/
119+
hooks: Operation[];
120+
}
66121

67122
/** Vue specific configuration for Tracing Integration */
68123
export interface TracingOptions {

packages/vue/test/integration/init.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ describe('Sentry.init', () => {
8585
app.mount(el);
8686

8787
expect(warnings).toEqual([
88-
`[@sentry/vue]: Misconfigured SDK. Vue specific errors will not be captured.
89-
Update your \`Sentry.init\` call with an appropriate config option:
90-
\`app\` (Application Instance - Vue 3) or \`Vue\` (Vue Constructor - Vue 2).`,
88+
'[@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).',
9189
]);
9290
});
9391

0 commit comments

Comments
 (0)