1- // tslint:disable:max-classes-per-file
2-
31import { AfterViewInit , Directive , Injectable , Input , OnInit } from '@angular/core' ;
42import { Event , NavigationEnd , NavigationStart , Router } from '@angular/router' ;
53import { getCurrentHub } from '@sentry/browser' ;
@@ -54,14 +52,7 @@ export function getActiveTransaction(): Transaction | undefined {
5452 */
5553@Injectable ( { providedIn : 'root' } )
5654export 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 (
6556 filter ( event => event instanceof NavigationStart ) ,
6657 tap ( event => {
6758 if ( ! instrumentationInitialized ) {
@@ -80,7 +71,7 @@ export class TraceService {
8071 }
8172
8273 if ( activeTransaction ) {
83- this . routingSpan = activeTransaction . startChild ( {
74+ this . _routingSpan = activeTransaction . startChild ( {
8475 description : `${ navigationEvent . url } ` ,
8576 op : `angular.routing` ,
8677 tags : {
@@ -95,15 +86,22 @@ export class TraceService {
9586 } ) ,
9687 ) ;
9788
98- public navEnd$ : Observable < Event > = this . router . events . pipe (
89+ public navEnd$ : Observable < Event > = this . _router . events . pipe (
9990 filter ( event => event instanceof NavigationEnd ) ,
10091 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 ;
10495 }
10596 } ) ,
10697 ) ;
98+
99+ private _routingSpan ?: Span ;
100+
101+ public constructor ( private readonly _router : Router ) {
102+ this . navStart$ . subscribe ( ) ;
103+ this . navEnd$ . subscribe ( ) ;
104+ }
107105}
108106
109107const UNKNOWN_COMPONENT = 'unknown' ;
@@ -113,18 +111,18 @@ const UNKNOWN_COMPONENT = 'unknown';
113111 */
114112@Directive ( { selector : '[trace]' } )
115113export class TraceDirective implements OnInit , AfterViewInit {
116- private tracingSpan ?: Span ;
117-
118114 @Input ( 'trace' ) public componentName : string = UNKNOWN_COMPONENT ;
119115
116+ private _tracingSpan ?: Span ;
117+
120118 /**
121119 * Implementation of OnInit lifecycle method
122120 * @inheritdoc
123121 */
124122 public ngOnInit ( ) : void {
125123 const activeTransaction = getActiveTransaction ( ) ;
126124 if ( activeTransaction ) {
127- this . tracingSpan = activeTransaction . startChild ( {
125+ this . _tracingSpan = activeTransaction . startChild ( {
128126 description : `<${ this . componentName } >` ,
129127 op : `angular.initialize` ,
130128 } ) ;
@@ -136,8 +134,8 @@ export class TraceDirective implements OnInit, AfterViewInit {
136134 * @inheritdoc
137135 */
138136 public ngAfterViewInit ( ) : void {
139- if ( this . tracingSpan ) {
140- this . tracingSpan . finish ( ) ;
137+ if ( this . _tracingSpan ) {
138+ this . _tracingSpan . finish ( ) ;
141139 }
142140 }
143141}
@@ -148,10 +146,11 @@ export class TraceDirective implements OnInit, AfterViewInit {
148146export function TraceClassDecorator ( ) : ClassDecorator {
149147 let tracingSpan : Span ;
150148
151- return ( target : Function ) => {
149+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
150+ return target => {
152151 // tslint:disable-next-line:no-unsafe-any
153152 const originalOnInit = target . prototype . ngOnInit ;
154- // tslint: disable-next-line: no-unsafe -any
153+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
155154 target . prototype . ngOnInit = function ( ...args : any [ ] ) : ReturnType < typeof originalOnInit > {
156155 const activeTransaction = getActiveTransaction ( ) ;
157156 if ( activeTransaction ) {
@@ -161,14 +160,12 @@ export function TraceClassDecorator(): ClassDecorator {
161160 } ) ;
162161 }
163162 if ( originalOnInit ) {
164- // tslint:disable-next-line:no-unsafe-any
165163 return originalOnInit . apply ( this , args ) ;
166164 }
167165 } ;
168166
169- // tslint:disable-next-line:no-unsafe-any
170167 const originalAfterViewInit = target . prototype . ngAfterViewInit ;
171- // tslint: disable-next-line: no-unsafe -any
168+ // eslint- disable-next-line @typescript-eslint/ no-explicit -any
172169 target . prototype . ngAfterViewInit = function ( ...args : any [ ] ) : ReturnType < typeof originalAfterViewInit > {
173170 if ( tracingSpan ) {
174171 tracingSpan . finish ( ) ;
@@ -185,8 +182,10 @@ export function TraceClassDecorator(): ClassDecorator {
185182 * Decorator function that can be used to capture a single lifecycle methods of the component.
186183 */
187184export function TraceMethodDecorator ( ) : MethodDecorator {
185+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/ban-types
188186 return ( target : Object , propertyKey : string | symbol , descriptor : PropertyDescriptor ) => {
189187 const originalMethod = descriptor . value ;
188+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
190189 descriptor . value = function ( ...args : any [ ] ) : ReturnType < typeof originalMethod > {
191190 const now = timestampWithMs ( ) ;
192191 const activeTransaction = getActiveTransaction ( ) ;
0 commit comments