1- import { EventProcessor , Hub , Integration , IntegrationClass , Span } from '@sentry/types' ;
1+ import { EventProcessor , Hub , Integration , Span , Transaction } from '@sentry/types' ;
22import { basename , getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
33
4- /**
5- * Used to extract Tracing integration from the current client,
6- * without the need to import `Tracing` itself from the @sentry/apm package.
7- */
8- const TRACING_GETTER = ( {
9- id : 'Tracing' ,
10- } as any ) as IntegrationClass < Integration > ;
4+ // tslint:disable-next-line: completed-docs
5+ function getActiveTransaction ( hub : Hub ) : Transaction | undefined {
6+ const scope = hub . getScope ( ) ;
7+ if ( scope ) {
8+ return scope . getTransaction ( ) ;
9+ }
10+
11+ return undefined ;
12+ }
1113
1214/** Global Vue object limited to the methods/attributes we require */
1315interface VueInstance {
@@ -137,7 +139,6 @@ export class Vue implements Integration {
137139 private readonly _componentsCache : { [ key : string ] : string } = { } ;
138140 private _rootSpan ?: Span ;
139141 private _rootSpanTimer ?: ReturnType < typeof setTimeout > ;
140- private _tracingActivity ?: number ;
141142
142143 /**
143144 * @inheritDoc
@@ -221,27 +222,20 @@ export class Vue implements Integration {
221222 // On the first handler call (before), it'll be undefined, as `$once` will add it in the future.
222223 // However, on the second call (after), it'll be already in place.
223224 if ( this . _rootSpan ) {
224- this . _finishRootSpan ( now , getCurrentHub ) ;
225+ this . _finishRootSpan ( now ) ;
225226 } else {
226227 vm . $once ( `hook:${ hook } ` , ( ) => {
227228 // Create an activity on the first event call. There'll be no second call, as rootSpan will be in place,
228229 // thus new event handler won't be attached.
229230
230231 // We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency.
231232 // We also need to ask for the `.constructor`, as `pushActivity` and `popActivity` are static, not instance methods.
232- const tracingIntegration = getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ;
233- if ( tracingIntegration ) {
234- // tslint:disable-next-line:no-unsafe-any
235- this . _tracingActivity = ( tracingIntegration as any ) . constructor . pushActivity ( 'Vue Application Render' ) ;
236- // tslint:disable-next-line:no-unsafe-any
237- const transaction = ( tracingIntegration as any ) . constructor . getTransaction ( ) ;
238- if ( transaction ) {
239- // tslint:disable-next-line:no-unsafe-any
240- this . _rootSpan = transaction . startChild ( {
241- description : 'Application Render' ,
242- op : 'Vue' ,
243- } ) ;
244- }
233+ const activeTransaction = getActiveTransaction ( getCurrentHub ( ) ) ;
234+ if ( activeTransaction ) {
235+ this . _rootSpan = activeTransaction . startChild ( {
236+ description : 'Application Render' ,
237+ op : 'Vue' ,
238+ } ) ;
245239 }
246240 } ) ;
247241 }
@@ -264,7 +258,7 @@ export class Vue implements Integration {
264258 // However, on the second call (after), it'll be already in place.
265259 if ( span ) {
266260 span . finish ( ) ;
267- this . _finishRootSpan ( now , getCurrentHub ) ;
261+ this . _finishRootSpan ( now ) ;
268262 } else {
269263 vm . $once ( `hook:${ hook } ` , ( ) => {
270264 if ( this . _rootSpan ) {
@@ -306,23 +300,14 @@ export class Vue implements Integration {
306300 } ;
307301
308302 /** Finish top-level span and activity with a debounce configured using `timeout` option */
309- private _finishRootSpan ( timestamp : number , getCurrentHub : ( ) => Hub ) : void {
303+ private _finishRootSpan ( timestamp : number ) : void {
310304 if ( this . _rootSpanTimer ) {
311305 clearTimeout ( this . _rootSpanTimer ) ;
312306 }
313307
314308 this . _rootSpanTimer = setTimeout ( ( ) => {
315- if ( this . _tracingActivity ) {
316- // We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency.
317- // We also need to ask for the `.constructor`, as `pushActivity` and `popActivity` are static, not instance methods.
318- const tracingIntegration = getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ;
319- if ( tracingIntegration ) {
320- // tslint:disable-next-line:no-unsafe-any
321- ( tracingIntegration as any ) . constructor . popActivity ( this . _tracingActivity ) ;
322- if ( this . _rootSpan ) {
323- this . _rootSpan . finish ( timestamp ) ;
324- }
325- }
309+ if ( this . _rootSpan ) {
310+ this . _rootSpan . finish ( timestamp ) ;
326311 }
327312 } , this . _options . tracingOptions . timeout ) ;
328313 }
@@ -333,7 +318,7 @@ export class Vue implements Integration {
333318
334319 this . _options . Vue . mixin ( {
335320 beforeCreate ( this : ViewModel ) : void {
336- if ( getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ) {
321+ if ( getActiveTransaction ( getCurrentHub ( ) ) ) {
337322 // `this` points to currently rendered component
338323 applyTracingHooks ( this , getCurrentHub ) ;
339324 } else {
0 commit comments