1
- // tslint:disable:max-classes-per-file
2
-
3
1
import { AfterViewInit , Directive , Injectable , Input , OnInit } from '@angular/core' ;
4
2
import { Event , NavigationEnd , NavigationStart , Router } from '@angular/router' ;
5
3
import { getCurrentHub } from '@sentry/browser' ;
@@ -54,14 +52,7 @@ export function getActiveTransaction(): Transaction | undefined {
54
52
*/
55
53
@Injectable ( { providedIn : 'root' } )
56
54
export class TraceService {
57
- private routingSpan ?: Span ;
58
-
59
- public constructor ( private readonly router : Router ) {
60
- this . navStart$ . subscribe ( ) ;
61
- this . navEnd$ . subscribe ( ) ;
62
- }
63
-
64
- public navStart$ : Observable < Event > = this . router . events . pipe (
55
+ public navStart$ : Observable < Event > = this . _router . events . pipe (
65
56
filter ( event => event instanceof NavigationStart ) ,
66
57
tap ( event => {
67
58
if ( ! instrumentationInitialized ) {
@@ -80,7 +71,7 @@ export class TraceService {
80
71
}
81
72
82
73
if ( activeTransaction ) {
83
- this . routingSpan = activeTransaction . startChild ( {
74
+ this . _routingSpan = activeTransaction . startChild ( {
84
75
description : `${ navigationEvent . url } ` ,
85
76
op : `angular.routing` ,
86
77
tags : {
@@ -95,15 +86,22 @@ export class TraceService {
95
86
} ) ,
96
87
) ;
97
88
98
- public navEnd$ : Observable < Event > = this . router . events . pipe (
89
+ public navEnd$ : Observable < Event > = this . _router . events . pipe (
99
90
filter ( event => event instanceof NavigationEnd ) ,
100
91
tap ( ( ) => {
101
- if ( this . routingSpan ) {
102
- this . routingSpan . finish ( ) ;
103
- delete this . routingSpan ;
92
+ if ( this . _routingSpan ) {
93
+ this . _routingSpan . finish ( ) ;
94
+ delete this . _routingSpan ;
104
95
}
105
96
} ) ,
106
97
) ;
98
+
99
+ private _routingSpan ?: Span ;
100
+
101
+ public constructor ( private readonly _router : Router ) {
102
+ this . navStart$ . subscribe ( ) ;
103
+ this . navEnd$ . subscribe ( ) ;
104
+ }
107
105
}
108
106
109
107
const UNKNOWN_COMPONENT = 'unknown' ;
@@ -113,18 +111,18 @@ const UNKNOWN_COMPONENT = 'unknown';
113
111
*/
114
112
@Directive ( { selector : '[trace]' } )
115
113
export class TraceDirective implements OnInit , AfterViewInit {
116
- private tracingSpan ?: Span ;
117
-
118
114
@Input ( 'trace' ) public componentName : string = UNKNOWN_COMPONENT ;
119
115
116
+ private _tracingSpan ?: Span ;
117
+
120
118
/**
121
119
* Implementation of OnInit lifecycle method
122
120
* @inheritdoc
123
121
*/
124
122
public ngOnInit ( ) : void {
125
123
const activeTransaction = getActiveTransaction ( ) ;
126
124
if ( activeTransaction ) {
127
- this . tracingSpan = activeTransaction . startChild ( {
125
+ this . _tracingSpan = activeTransaction . startChild ( {
128
126
description : `<${ this . componentName } >` ,
129
127
op : `angular.initialize` ,
130
128
} ) ;
@@ -136,8 +134,8 @@ export class TraceDirective implements OnInit, AfterViewInit {
136
134
* @inheritdoc
137
135
*/
138
136
public ngAfterViewInit ( ) : void {
139
- if ( this . tracingSpan ) {
140
- this . tracingSpan . finish ( ) ;
137
+ if ( this . _tracingSpan ) {
138
+ this . _tracingSpan . finish ( ) ;
141
139
}
142
140
}
143
141
}
@@ -148,10 +146,11 @@ export class TraceDirective implements OnInit, AfterViewInit {
148
146
export function TraceClassDecorator ( ) : ClassDecorator {
149
147
let tracingSpan : Span ;
150
148
151
- return ( target : Function ) => {
149
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
150
+ return target => {
152
151
// tslint:disable-next-line:no-unsafe-any
153
152
const originalOnInit = target . prototype . ngOnInit ;
154
- // tslint: disable-next-line: no-unsafe -any
153
+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
155
154
target . prototype . ngOnInit = function ( ...args : any [ ] ) : ReturnType < typeof originalOnInit > {
156
155
const activeTransaction = getActiveTransaction ( ) ;
157
156
if ( activeTransaction ) {
@@ -161,14 +160,12 @@ export function TraceClassDecorator(): ClassDecorator {
161
160
} ) ;
162
161
}
163
162
if ( originalOnInit ) {
164
- // tslint:disable-next-line:no-unsafe-any
165
163
return originalOnInit . apply ( this , args ) ;
166
164
}
167
165
} ;
168
166
169
- // tslint:disable-next-line:no-unsafe-any
170
167
const originalAfterViewInit = target . prototype . ngAfterViewInit ;
171
- // tslint: disable-next-line: no-unsafe -any
168
+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
172
169
target . prototype . ngAfterViewInit = function ( ...args : any [ ] ) : ReturnType < typeof originalAfterViewInit > {
173
170
if ( tracingSpan ) {
174
171
tracingSpan . finish ( ) ;
@@ -185,8 +182,10 @@ export function TraceClassDecorator(): ClassDecorator {
185
182
* Decorator function that can be used to capture a single lifecycle methods of the component.
186
183
*/
187
184
export function TraceMethodDecorator ( ) : MethodDecorator {
185
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/ban-types
188
186
return ( target : Object , propertyKey : string | symbol , descriptor : PropertyDescriptor ) => {
189
187
const originalMethod = descriptor . value ;
188
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
189
descriptor . value = function ( ...args : any [ ] ) : ReturnType < typeof originalMethod > {
191
190
const now = timestampWithMs ( ) ;
192
191
const activeTransaction = getActiveTransaction ( ) ;
0 commit comments