@@ -79,6 +79,7 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
79
79
mixins [ internalHook ] = function ( this : VueSentry ) {
80
80
const isRoot = this . $root === this ;
81
81
82
+ // 1. Root span creation
82
83
if ( isRoot ) {
83
84
this . $_sentryRootSpan =
84
85
this . $_sentryRootSpan ||
@@ -92,35 +93,39 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
92
93
} ) ;
93
94
}
94
95
95
- // Skip components that we don't want to track to minimize the noise and give a more granular control to the user
96
- const name = formatComponentName ( this , false ) ;
96
+ // 2. Component tracking filter
97
+ const componentName = formatComponentName ( this , false ) ;
97
98
98
- const shouldTrack = Array . isArray ( options . trackComponents )
99
- ? findTrackComponent ( options . trackComponents , name )
100
- : options . trackComponents ;
99
+ const shouldTrack =
100
+ isRoot || // We always want to track the root component
101
+ ( Array . isArray ( options . trackComponents )
102
+ ? findTrackComponent ( options . trackComponents , componentName )
103
+ : options . trackComponents ) ;
101
104
102
- // We always want to track root component
103
- if ( ! isRoot && ! shouldTrack ) {
105
+ if ( ! shouldTrack ) {
104
106
return ;
105
107
}
106
108
107
109
this . $_sentrySpans = this . $_sentrySpans || { } ;
108
110
109
- // Start a new span if current hook is a 'before' hook.
110
- // Otherwise, retrieve the current span and finish it.
111
- if ( internalHook == internalHooks [ 0 ] ) {
112
- const activeSpan = this . $root ?. $_sentryRootSpan || getActiveSpan ( ) ;
111
+ // 3. Span lifecycle management based on the hook type
112
+ const isBeforeHook = internalHook === internalHooks [ 0 ] ;
113
+ const activeSpan = this . $root ?. $_sentryRootSpan || getActiveSpan ( ) ;
114
+
115
+ if ( isBeforeHook ) {
116
+ // Starting a new span in the "before" hook
113
117
if ( activeSpan ) {
114
- // Cancel old span for this hook operation in case it didn't get cleaned up. We're not actually sure if it
115
- // will ever be the case that cleanup hooks re not called, but we had users report that spans didn't get
116
- // finished so we finish the span before starting a new one, just to be sure.
118
+ // Cancel any existing span for this operation (safety measure)
119
+ // 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
121
+ // starting a new one, just to be sure.
117
122
const oldSpan = this . $_sentrySpans [ operation ] ;
118
123
if ( oldSpan ) {
119
124
oldSpan . end ( ) ;
120
125
}
121
126
122
127
this . $_sentrySpans [ operation ] = startInactiveSpan ( {
123
- name : `Vue ${ name } ` ,
128
+ name : `Vue ${ componentName } ` ,
124
129
op : `${ VUE_OP } .${ operation } ` ,
125
130
attributes : {
126
131
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.vue' ,
@@ -134,9 +139,10 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
134
139
const span = this . $_sentrySpans [ operation ] ;
135
140
// The before hook did not start the tracking span, so the span was not added.
136
141
// This is probably because it happened before there is an active transaction
137
- if ( ! span ) return ;
142
+ if ( ! span ) return ; // Skip if no span was created in the "before" hook
138
143
span . end ( ) ;
139
144
145
+ // For any "after" hook, also schedule the root span to finish
140
146
finishRootSpan ( this , timestampInSeconds ( ) , options . timeout || 2000 ) ;
141
147
}
142
148
} ;
0 commit comments