@@ -89,12 +89,14 @@ export class TraceService implements OnDestroy {
89
89
if ( client ) {
90
90
// see comment in `_isPageloadOngoing` for rationale
91
91
if ( ! this . _isPageloadOngoing ( ) ) {
92
- startBrowserTracingNavigationSpan ( client , {
93
- name : strippedUrl ,
94
- attributes : {
95
- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.navigation.angular' ,
96
- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
97
- } ,
92
+ runOutsideAngular ( ( ) => {
93
+ startBrowserTracingNavigationSpan ( client , {
94
+ name : strippedUrl ,
95
+ attributes : {
96
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.navigation.angular' ,
97
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
98
+ } ,
99
+ } ) ;
98
100
} ) ;
99
101
} else {
100
102
// The first time we end up here, we set the pageload flag to false
@@ -104,7 +106,7 @@ export class TraceService implements OnDestroy {
104
106
}
105
107
106
108
this . _routingSpan =
107
- startInactiveSpan ( {
109
+ runOutsideAngular ( ( ) => startInactiveSpan ( {
108
110
name : `${ navigationEvent . url } ` ,
109
111
op : ANGULAR_ROUTING_OP ,
110
112
attributes : {
@@ -115,7 +117,7 @@ export class TraceService implements OnDestroy {
115
117
navigationTrigger : navigationEvent . navigationTrigger ,
116
118
} ) ,
117
119
} ,
118
- } ) || null ;
120
+ } ) ) || null ;
119
121
120
122
return ;
121
123
}
@@ -252,11 +254,11 @@ export class TraceDirective implements OnInit, AfterViewInit {
252
254
}
253
255
254
256
if ( getActiveSpan ( ) ) {
255
- this . _tracingSpan = startInactiveSpan ( {
257
+ this . _tracingSpan = runOutsideAngular ( ( ) => startInactiveSpan ( {
256
258
name : `<${ this . componentName } >` ,
257
259
op : ANGULAR_INIT_OP ,
258
260
attributes : { [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.angular.trace_directive' } ,
259
- } ) ;
261
+ } ) ) ;
260
262
}
261
263
}
262
264
@@ -266,7 +268,7 @@ export class TraceDirective implements OnInit, AfterViewInit {
266
268
*/
267
269
public ngAfterViewInit ( ) : void {
268
270
if ( this . _tracingSpan ) {
269
- this . _tracingSpan . end ( ) ;
271
+ runOutsideAngular ( ( ) => this . _tracingSpan ! . end ( ) ) ;
270
272
}
271
273
}
272
274
}
@@ -298,14 +300,14 @@ export function TraceClass(options?: TraceClassOptions): ClassDecorator {
298
300
const originalOnInit = target . prototype . ngOnInit ;
299
301
// eslint-disable-next-line @typescript-eslint/no-explicit-any
300
302
target . prototype . ngOnInit = function ( ...args : any [ ] ) : ReturnType < typeof originalOnInit > {
301
- tracingSpan = startInactiveSpan ( {
303
+ tracingSpan = runOutsideAngular ( ( ) => startInactiveSpan ( {
302
304
onlyIfParent : true ,
303
305
name : `<${ options && options . name ? options . name : 'unnamed' } >` ,
304
306
op : ANGULAR_INIT_OP ,
305
307
attributes : {
306
308
[ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.angular.trace_class_decorator' ,
307
309
} ,
308
- } ) ;
310
+ } ) ) ;
309
311
310
312
if ( originalOnInit ) {
311
313
return originalOnInit . apply ( this , args ) ;
@@ -316,7 +318,7 @@ export function TraceClass(options?: TraceClassOptions): ClassDecorator {
316
318
// eslint-disable-next-line @typescript-eslint/no-explicit-any
317
319
target . prototype . ngAfterViewInit = function ( ...args : any [ ] ) : ReturnType < typeof originalAfterViewInit > {
318
320
if ( tracingSpan ) {
319
- tracingSpan . end ( ) ;
321
+ runOutsideAngular ( ( ) => tracingSpan . end ( ) ) ;
320
322
}
321
323
if ( originalAfterViewInit ) {
322
324
return originalAfterViewInit . apply ( this , args ) ;
@@ -344,15 +346,17 @@ export function TraceMethod(options?: TraceMethodOptions): MethodDecorator {
344
346
descriptor . value = function ( ...args : any [ ] ) : ReturnType < typeof originalMethod > {
345
347
const now = timestampInSeconds ( ) ;
346
348
347
- startInactiveSpan ( {
348
- onlyIfParent : true ,
349
- name : `<${ options && options . name ? options . name : 'unnamed' } >` ,
350
- op : `${ ANGULAR_OP } .${ String ( propertyKey ) } ` ,
351
- startTime : now ,
352
- attributes : {
353
- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.angular.trace_method_decorator' ,
354
- } ,
355
- } ) . end ( now ) ;
349
+ runOutsideAngular ( ( ) => {
350
+ startInactiveSpan ( {
351
+ onlyIfParent : true ,
352
+ name : `<${ options && options . name ? options . name : 'unnamed' } >` ,
353
+ op : `${ ANGULAR_OP } .${ String ( propertyKey ) } ` ,
354
+ startTime : now ,
355
+ attributes : {
356
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.angular.trace_method_decorator' ,
357
+ } ,
358
+ } ) . end ( now ) ;
359
+ } ) ;
356
360
357
361
if ( originalMethod ) {
358
362
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
0 commit comments