1- import { Logger } from '@opentelemetry/api' ;
2- import { ConnectionString , ConnectionStringKey } from '../Declarations/Contracts' ;
1+ import type { Logger } from '@opentelemetry/api' ;
2+ import { NoopLogger } from '@opentelemetry/core' ;
3+ import type { ConnectionString , ConnectionStringKey } from '../Declarations/Contracts' ;
34
45import * as Constants from '../Declarations/Constants' ;
56
@@ -8,7 +9,7 @@ export class ConnectionStringParser {
89
910 private static readonly FIELD_KEY_VALUE_SEPARATOR = '=' ;
1011
11- public static parse ( connectionString ?: string , logger ? : Logger ) : ConnectionString {
12+ public static parse ( connectionString ?: string , logger : Logger = new NoopLogger ( ) ) : ConnectionString {
1213 if ( ! connectionString ) {
1314 return { } ;
1415 }
@@ -25,13 +26,11 @@ export class ConnectionStringParser {
2526 const value = kvParts [ 1 ] ;
2627 return { ...fields , [ key ] : value } ;
2728 }
28- if ( logger ) {
29- logger . error (
30- `Connection string key-value pair is invalid: ${ kv } ` ,
31- `Entire connection string will be discarded` ,
32- connectionString ,
33- ) ;
34- }
29+ logger . error (
30+ `Connection string key-value pair is invalid: ${ kv } ` ,
31+ `Entire connection string will be discarded` ,
32+ connectionString ,
33+ ) ;
3534 isValid = false ;
3635 return fields ;
3736 } , { } ) ;
@@ -50,19 +49,14 @@ export class ConnectionStringParser {
5049 // apply the default endpoints
5150 result . ingestionendpoint = result . ingestionendpoint || Constants . DEFAULT_BREEZE_ENDPOINT ;
5251 result . liveendpoint = result . liveendpoint || Constants . DEFAULT_LIVEMETRICS_ENDPOINT ;
53- if ( result . authorization && result . authorization . toLowerCase ( ) !== 'ikey' && logger ) {
52+ if ( result . authorization && result . authorization . toLowerCase ( ) !== 'ikey' ) {
5453 logger . warn (
5554 `Connection String contains an unsupported 'Authorization' value: ${ result . authorization } . Defaulting to 'Authorization=ikey'. Instrumentation Key ${ result . instrumentationkey } ` ,
5655 ) ;
5756 }
5857 }
5958
60- if ( logger ) {
61- logger . error (
62- 'An invalid connection string was passed in. There may be telemetry loss' ,
63- connectionString ,
64- ) ;
65- }
59+ logger . error ( 'An invalid connection string was passed in. There may be telemetry loss' , connectionString ) ;
6660 return result ;
6761 }
6862}
0 commit comments