1
- import { EventProcessor , Hub , Integration , IntegrationClass , Span } from '@sentry/types' ;
1
+ import { EventProcessor , Hub , Integration , Span , Transaction } from '@sentry/types' ;
2
2
import { basename , getGlobalObject , logger , timestampWithMs } from '@sentry/utils' ;
3
3
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
+ }
11
13
12
14
/** Global Vue object limited to the methods/attributes we require */
13
15
interface VueInstance {
@@ -137,7 +139,6 @@ export class Vue implements Integration {
137
139
private readonly _componentsCache : { [ key : string ] : string } = { } ;
138
140
private _rootSpan ?: Span ;
139
141
private _rootSpanTimer ?: ReturnType < typeof setTimeout > ;
140
- private _tracingActivity ?: number ;
141
142
142
143
/**
143
144
* @inheritDoc
@@ -221,27 +222,20 @@ export class Vue implements Integration {
221
222
// On the first handler call (before), it'll be undefined, as `$once` will add it in the future.
222
223
// However, on the second call (after), it'll be already in place.
223
224
if ( this . _rootSpan ) {
224
- this . _finishRootSpan ( now , getCurrentHub ) ;
225
+ this . _finishRootSpan ( now ) ;
225
226
} else {
226
227
vm . $once ( `hook:${ hook } ` , ( ) => {
227
228
// Create an activity on the first event call. There'll be no second call, as rootSpan will be in place,
228
229
// thus new event handler won't be attached.
229
230
230
231
// We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency.
231
232
// 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
+ } ) ;
245
239
}
246
240
} ) ;
247
241
}
@@ -264,7 +258,7 @@ export class Vue implements Integration {
264
258
// However, on the second call (after), it'll be already in place.
265
259
if ( span ) {
266
260
span . finish ( ) ;
267
- this . _finishRootSpan ( now , getCurrentHub ) ;
261
+ this . _finishRootSpan ( now ) ;
268
262
} else {
269
263
vm . $once ( `hook:${ hook } ` , ( ) => {
270
264
if ( this . _rootSpan ) {
@@ -306,23 +300,14 @@ export class Vue implements Integration {
306
300
} ;
307
301
308
302
/** 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 {
310
304
if ( this . _rootSpanTimer ) {
311
305
clearTimeout ( this . _rootSpanTimer ) ;
312
306
}
313
307
314
308
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 ) ;
326
311
}
327
312
} , this . _options . tracingOptions . timeout ) ;
328
313
}
@@ -333,7 +318,7 @@ export class Vue implements Integration {
333
318
334
319
this . _options . Vue . mixin ( {
335
320
beforeCreate ( this : ViewModel ) : void {
336
- if ( getCurrentHub ( ) . getIntegration ( TRACING_GETTER ) ) {
321
+ if ( getActiveTransaction ( getCurrentHub ( ) ) ) {
337
322
// `this` points to currently rendered component
338
323
applyTracingHooks ( this , getCurrentHub ) ;
339
324
} else {
0 commit comments