File tree 4 files changed +10
-7
lines changed
4 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 56
56
* ```
57
57
*/
58
58
export class Utility {
59
-
60
59
private coldStart : boolean = true ;
60
+ private readonly defaultServiceName : string = 'service_undefined' ;
61
61
62
62
public getColdStart ( ) : boolean {
63
63
if ( this . coldStart ) {
@@ -69,6 +69,10 @@ export class Utility {
69
69
return false ;
70
70
}
71
71
72
+ public getDefaultServiceName ( ) : string {
73
+ return this . defaultServiceName ;
74
+ }
75
+
72
76
public isColdStart ( ) : boolean {
73
77
return this . getColdStart ( ) ;
74
78
}
Original file line number Diff line number Diff line change @@ -118,8 +118,6 @@ class Logger extends Utility implements ClassThatLogs {
118
118
119
119
private static readonly defaultLogLevel : LogLevel = 'INFO' ;
120
120
121
- private static readonly defaultServiceName : string = 'service_undefined' ;
122
-
123
121
// envVarsService is always initialized in the constructor in setOptions()
124
122
private envVarsService ! : EnvironmentVariablesService ;
125
123
@@ -786,7 +784,7 @@ class Logger extends Utility implements ClassThatLogs {
786
784
this . getEnvVarsService ( ) . getCurrentEnvironment ( ) ,
787
785
sampleRateValue : this . getSampleRateValue ( ) ,
788
786
serviceName :
789
- serviceName || this . getCustomConfigService ( ) ?. getServiceName ( ) || this . getEnvVarsService ( ) . getServiceName ( ) || Logger . defaultServiceName ,
787
+ serviceName || this . getCustomConfigService ( ) ?. getServiceName ( ) || this . getEnvVarsService ( ) . getServiceName ( ) || this . getDefaultServiceName ( ) ,
790
788
} ,
791
789
persistentLogAttributes ,
792
790
) ;
Original file line number Diff line number Diff line change @@ -473,7 +473,7 @@ class Metrics extends Utility implements MetricsInterface {
473
473
private setService ( service : string | undefined ) : void {
474
474
const targetService = ( service ||
475
475
this . getCustomConfigService ( ) ?. getServiceName ( ) ||
476
- this . getEnvVarsService ( ) . getServiceName ( ) ) as string ;
476
+ this . getEnvVarsService ( ) . getServiceName ( ) ) as string || this . getDefaultServiceName ( ) ;
477
477
if ( targetService . length > 0 ) {
478
478
this . setDefaultDimensions ( { service : targetService } ) ;
479
479
}
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ class Tracer extends Utility implements TracerInterface {
128
128
// envVarsService is always initialized in the constructor in setOptions()
129
129
private envVarsService ! : EnvironmentVariablesService ;
130
130
131
- private serviceName ? : string ;
131
+ private serviceName ! : string ;
132
132
133
133
private tracingEnabled : boolean = true ;
134
134
@@ -189,7 +189,7 @@ class Tracer extends Utility implements TracerInterface {
189
189
*
190
190
*/
191
191
public addServiceNameAnnotation ( ) : void {
192
- if ( ! this . isTracingEnabled ( ) || this . serviceName === undefined ) {
192
+ if ( ! this . isTracingEnabled ( ) ) {
193
193
return ;
194
194
}
195
195
this . putAnnotation ( 'Service' , this . serviceName ) ;
@@ -836,6 +836,7 @@ class Tracer extends Utility implements TracerInterface {
836
836
837
837
return ;
838
838
}
839
+ this . serviceName = this . getDefaultServiceName ( ) ;
839
840
}
840
841
841
842
/**
You can’t perform that action at this time.
0 commit comments