@@ -31,8 +31,8 @@ const HOOKS: { [key in Operation]: Hook[] } = {
31
31
update : [ 'beforeUpdate' , 'updated' ] ,
32
32
} ;
33
33
34
- /** Finish top-level component span and activity with a debounce configured using `timeout` option */
35
- function finishRootComponentSpan ( vm : VueSentry , timestamp : number , timeout : number ) : void {
34
+ /** End the top-level component span and activity with a debounce configured using `timeout` option */
35
+ function maybeEndRootComponentSpan ( vm : VueSentry , timestamp : number , timeout : number ) : void {
36
36
if ( vm . $_sentryRootComponentSpanTimer ) {
37
37
clearTimeout ( vm . $_sentryRootComponentSpanTimer ) ;
38
38
}
@@ -66,6 +66,8 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
66
66
67
67
const mixins : Mixins = { } ;
68
68
69
+ const rootComponentSpanFinalTimeout = options . timeout || 2000 ;
70
+
69
71
for ( const operation of hooks ) {
70
72
// Retrieve corresponding hooks from Vue lifecycle.
71
73
// eg. mount => ['beforeMount', 'mounted']
@@ -91,6 +93,9 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
91
93
} ,
92
94
onlyIfParent : true ,
93
95
} ) ;
96
+
97
+ // call debounced end function once directly, just in case no child components call it
98
+ maybeEndRootComponentSpan ( this , timestampInSeconds ( ) , rootComponentSpanFinalTimeout ) ;
94
99
}
95
100
96
101
// 2. Component tracking filter
@@ -102,7 +107,10 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
102
107
? findTrackComponent ( options . trackComponents , componentName )
103
108
: options . trackComponents ) ;
104
109
110
+ // We always want to track root component
105
111
if ( ! shouldTrack ) {
112
+ // even if we don't track `this` component, we still want to end the root span eventually
113
+ maybeEndRootComponentSpan ( this , timestampInSeconds ( ) , rootComponentSpanFinalTimeout ) ;
106
114
return ;
107
115
}
108
116
@@ -117,7 +125,7 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
117
125
if ( activeSpan ) {
118
126
// Cancel any existing span for this operation (safety measure)
119
127
// We're actually not sure if it will ever be the case that cleanup hooks were not called.
120
- // However, we had users report that spans didn't get finished , so we finished the span before
128
+ // However, we had users report that spans didn't end , so we end the span before
121
129
// starting a new one, just to be sure.
122
130
const oldSpan = this . $_sentryComponentSpans [ operation ] ;
123
131
if ( oldSpan ) {
@@ -142,8 +150,8 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
142
150
if ( ! span ) return ; // Skip if no span was created in the "before" hook
143
151
span . end ( ) ;
144
152
145
- // For any "after" hook, also schedule the root component span to finish
146
- finishRootComponentSpan ( this , timestampInSeconds ( ) , options . timeout || 2000 ) ;
153
+ // For any "after" hook, also schedule the root component span to end
154
+ maybeEndRootComponentSpan ( this , timestampInSeconds ( ) , rootComponentSpanFinalTimeout ) ;
147
155
}
148
156
} ;
149
157
}
0 commit comments