@@ -31,8 +31,8 @@ const HOOKS: { [key in Operation]: Hook[] } = {
3131 update : [ 'beforeUpdate' , 'updated' ] ,
3232} ;
3333
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 {
3636 if ( vm . $_sentryRootComponentSpanTimer ) {
3737 clearTimeout ( vm . $_sentryRootComponentSpanTimer ) ;
3838 }
@@ -66,6 +66,8 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
6666
6767 const mixins : Mixins = { } ;
6868
69+ const rootComponentSpanFinalTimeout = options . timeout || 2000 ;
70+
6971 for ( const operation of hooks ) {
7072 // Retrieve corresponding hooks from Vue lifecycle.
7173 // eg. mount => ['beforeMount', 'mounted']
@@ -91,6 +93,9 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
9193 } ,
9294 onlyIfParent : true ,
9395 } ) ;
96+
97+ // call debounced end function once directly, just in case no child components call it
98+ maybeEndRootComponentSpan ( this , timestampInSeconds ( ) , rootComponentSpanFinalTimeout ) ;
9499 }
95100
96101 // 2. Component tracking filter
@@ -102,7 +107,10 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
102107 ? findTrackComponent ( options . trackComponents , componentName )
103108 : options . trackComponents ) ;
104109
110+ // We always want to track root component
105111 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 ) ;
106114 return ;
107115 }
108116
@@ -117,7 +125,7 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
117125 if ( activeSpan ) {
118126 // Cancel any existing span for this operation (safety measure)
119127 // 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
121129 // starting a new one, just to be sure.
122130 const oldSpan = this . $_sentryComponentSpans [ operation ] ;
123131 if ( oldSpan ) {
@@ -142,8 +150,8 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
142150 if ( ! span ) return ; // Skip if no span was created in the "before" hook
143151 span . end ( ) ;
144152
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 ) ;
147155 }
148156 } ;
149157 }
0 commit comments