@@ -2,25 +2,52 @@ import { EventProcessor, Hub, Integration } from '@sentry/types';
2
2
import { basename , getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
3
3
import { Integrations as APMIntegrations , Span as SpanClass } from '@sentry/apm' ;
4
4
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
+
5
15
interface IntegrationOptions {
6
- Vue : any ;
16
+ /** Vue instance to be used inside the integration */
17
+ Vue : VueInstance ;
18
+
7
19
/**
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
9
21
* from your Vue components for privacy concerns.
10
22
*/
11
23
attachProps : boolean ;
12
24
/**
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.
14
26
* https://github.com/vuejs/vue/blob/c2b1cfe9ccd08835f2d99f6ce60f67b4de55187f/src/core/util/error.js#L38-L48
15
27
*/
16
28
logErrors : boolean ;
29
+
30
+ /** When set to `true`, enables tracking of components lifecycle performance. */
17
31
tracing : boolean ;
32
+
33
+ /** {@link TracingOptions } */
18
34
tracingOptions : TracingOptions ;
19
35
}
20
36
37
+ /** Vue specific configuration for Tracing Integration */
21
38
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 */
23
46
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
+ */
24
51
hooks : Array < Hook > ;
25
52
}
26
53
@@ -38,7 +65,6 @@ interface ViewModel {
38
65
$once : ( hook : string , cb : ( ) => void ) => void ;
39
66
}
40
67
41
- /** JSDoc */
42
68
interface Metadata {
43
69
[ key : string ] : any ;
44
70
componentName ?: string ;
@@ -59,9 +85,11 @@ type Hook =
59
85
| 'beforeDestroy'
60
86
| 'destroyed' ;
61
87
88
+ type Operation = 'create' | 'mount' | 'update' | 'activate' | 'destroy' ;
89
+
62
90
// Mappings from lifecycle hook to corresponding operation,
63
91
// used to track already started measurements.
64
- const OPERATIONS = {
92
+ const OPERATIONS : { [ key in Hook ] : Operation } = {
65
93
beforeCreate : 'create' ,
66
94
created : 'create' ,
67
95
beforeMount : 'mount' ,
@@ -111,7 +139,7 @@ export class Vue implements Integration {
111
139
tracing : false ,
112
140
...options ,
113
141
tracingOptions : {
114
- track : false ,
142
+ trackComponents : false ,
115
143
hooks : [ 'beforeMount' , 'mounted' , 'beforeUpdate' , 'updated' ] ,
116
144
timeout : 2000 ,
117
145
...options . tracingOptions ,
@@ -190,9 +218,9 @@ export class Vue implements Integration {
190
218
191
219
const childHandler = ( hook : Hook ) => {
192
220
// 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 ;
196
224
197
225
if ( ! this . rootSpan || ! shouldTrack ) {
198
226
return ;
@@ -272,7 +300,7 @@ export class Vue implements Integration {
272
300
273
301
const currentErrorHandler = this . _options . Vue . config . errorHandler ;
274
302
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 => {
276
304
const metadata : Metadata = { } ;
277
305
278
306
if ( vm ) {
0 commit comments