Skip to content

Commit a72bc6a

Browse files
committed
Code review updates
1 parent c5ec5db commit a72bc6a

File tree

1 file changed

+39
-11
lines changed
  • packages/integrations/src

1 file changed

+39
-11
lines changed

packages/integrations/src/vue.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,52 @@ import { EventProcessor, Hub, Integration } from '@sentry/types';
22
import { basename, getGlobalObject, logger, timestampWithMs } from '@sentry/utils';
33
import { Integrations as APMIntegrations, Span as SpanClass } from '@sentry/apm';
44

5+
interface VueInstance {
6+
config?: {
7+
errorHandler(error: Error, vm?: ViewModel, info?: string): void;
8+
};
9+
mixin(opts: { [key: string]: () => void }): void;
10+
util: {
11+
warn(...input: any): void;
12+
};
13+
}
14+
515
interface IntegrationOptions {
6-
Vue: any;
16+
/** Vue instance to be used inside the integration */
17+
Vue: VueInstance;
18+
719
/**
8-
* When set to false, Sentry will suppress reporting of all props data
20+
* When set to `false`, Sentry will suppress reporting of all props data
921
* from your Vue components for privacy concerns.
1022
*/
1123
attachProps: boolean;
1224
/**
13-
* When set to true, original Vue's `logError` will be called as well.
25+
* When set to `true`, original Vue's `logError` will be called as well.
1426
* https://github.com/vuejs/vue/blob/c2b1cfe9ccd08835f2d99f6ce60f67b4de55187f/src/core/util/error.js#L38-L48
1527
*/
1628
logErrors: boolean;
29+
30+
/** When set to `true`, enables tracking of components lifecycle performance. */
1731
tracing: boolean;
32+
33+
/** {@link TracingOptions} */
1834
tracingOptions: TracingOptions;
1935
}
2036

37+
/** Vue specific configuration for Tracing Integration */
2138
interface TracingOptions {
22-
track: boolean | Array<string>;
39+
/**
40+
* Decides whether to track components by hooking into its lifecycle methods.
41+
* Can be either set to `boolean` to enable/disable tracking for all of them.
42+
* Or to an array of specific component names (case-sensitive).
43+
*/
44+
trackComponents: boolean | Array<string>;
45+
/** How long to wait until the tracked root activity is marked as finished and sent of to Sentry */
2346
timeout: number;
47+
/**
48+
* List of hooks to keep track of during component lifecycle.
49+
* Available hooks: https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
50+
*/
2451
hooks: Array<Hook>;
2552
}
2653

@@ -38,7 +65,6 @@ interface ViewModel {
3865
$once: (hook: string, cb: () => void) => void;
3966
}
4067

41-
/** JSDoc */
4268
interface Metadata {
4369
[key: string]: any;
4470
componentName?: string;
@@ -59,9 +85,11 @@ type Hook =
5985
| 'beforeDestroy'
6086
| 'destroyed';
6187

88+
type Operation = 'create' | 'mount' | 'update' | 'activate' | 'destroy';
89+
6290
// Mappings from lifecycle hook to corresponding operation,
6391
// used to track already started measurements.
64-
const OPERATIONS = {
92+
const OPERATIONS: { [key in Hook]: Operation } = {
6593
beforeCreate: 'create',
6694
created: 'create',
6795
beforeMount: 'mount',
@@ -111,7 +139,7 @@ export class Vue implements Integration {
111139
tracing: false,
112140
...options,
113141
tracingOptions: {
114-
track: false,
142+
trackComponents: false,
115143
hooks: ['beforeMount', 'mounted', 'beforeUpdate', 'updated'],
116144
timeout: 2000,
117145
...options.tracingOptions,
@@ -190,9 +218,9 @@ export class Vue implements Integration {
190218

191219
const childHandler = (hook: Hook) => {
192220
// Skip components that we don't want to track to minimize the noise and give a more granular control to the user
193-
const shouldTrack = Array.isArray(this._options.tracingOptions.track)
194-
? this._options.tracingOptions.track.includes(name)
195-
: this._options.tracingOptions.track;
221+
const shouldTrack = Array.isArray(this._options.tracingOptions.trackComponents)
222+
? this._options.tracingOptions.trackComponents.includes(name)
223+
: this._options.tracingOptions.trackComponents;
196224

197225
if (!this.rootSpan || !shouldTrack) {
198226
return;
@@ -272,7 +300,7 @@ export class Vue implements Integration {
272300

273301
const currentErrorHandler = this._options.Vue.config.errorHandler;
274302

275-
this._options.Vue.config.errorHandler = (error: Error, vm: ViewModel, info: string): void => {
303+
this._options.Vue.config.errorHandler = (error: Error, vm?: ViewModel, info?: string): void => {
276304
const metadata: Metadata = {};
277305

278306
if (vm) {

0 commit comments

Comments
 (0)