@@ -41,6 +41,28 @@ function parseNumber(value: string | undefined): number | undefined {
4141 return Number . isFinite ( parsed ) ? parsed : undefined ;
4242}
4343
44+ function parseExporterProtocol (
45+ value : string | undefined ,
46+ ) : ExporterProtocol | undefined {
47+ if ( value === 'grpc' || value === 'http/protobuf' ) {
48+ return value ;
49+ }
50+
51+ return undefined ;
52+ }
53+
54+ function parseSamplerName ( value : string | undefined ) : SamplerName | undefined {
55+ if (
56+ value === 'always_on' ||
57+ value === 'always_off' ||
58+ value === 'traceidratio'
59+ ) {
60+ return value ;
61+ }
62+
63+ return undefined ;
64+ }
65+
4466function parseHeaders ( value : string | undefined ) : Record < string , string > {
4567 if ( ! value ) {
4668 return { } ;
@@ -98,13 +120,10 @@ function startupInstrumentationConfig(
98120 DEFAULT_INSTRUMENTATIONS ,
99121 ) as ( keyof InstrumentationToggles ) [ ] ;
100122
101- return keys . reduce (
102- ( result , key ) => {
103- result [ key ] = resolveInstrumentationToggle ( key , overrides ) ;
104- return result ;
105- } ,
106- { } as InstrumentationToggles ,
107- ) ;
123+ return keys . reduce ( ( result , key ) => {
124+ result [ key ] = resolveInstrumentationToggle ( key , overrides ) ;
125+ return result ;
126+ } , { } as InstrumentationToggles ) ;
108127}
109128
110129function resolveServiceInfo (
@@ -136,13 +155,15 @@ function resolveExporterConfig(
136155 overrides : Partial < ObservabilityConfig > | undefined ,
137156 env : NodeJS . ProcessEnv ,
138157) {
139- const exporterProtocol = ( overrides ?. exporterProtocol ??
140- ( env . OTEL_EXPORTER_OTLP_PROTOCOL as ExporterProtocol | undefined ) ??
141- DEFAULT_OBSERVABILITY_CONFIG . exporterProtocol ) as ExporterProtocol ;
158+ const exporterProtocol =
159+ overrides ?. exporterProtocol ??
160+ parseExporterProtocol ( env . OTEL_EXPORTER_OTLP_PROTOCOL ) ??
161+ DEFAULT_OBSERVABILITY_CONFIG . exporterProtocol ;
142162
143- const sampler = ( overrides ?. sampler ??
144- ( env . OTEL_TRACES_SAMPLER as SamplerName | undefined ) ??
145- DEFAULT_OBSERVABILITY_CONFIG . sampler ) as SamplerName ;
163+ const sampler =
164+ overrides ?. sampler ??
165+ parseSamplerName ( env . OTEL_TRACES_SAMPLER ) ??
166+ DEFAULT_OBSERVABILITY_CONFIG . sampler ;
146167
147168 const samplerArg =
148169 overrides ?. samplerArg ??
@@ -159,7 +180,13 @@ function resolveExporterConfig(
159180 ...overrides ?. otlpHeaders ,
160181 } ;
161182
162- return { exporterProtocol, sampler, samplerArg, otlpEndpoint, otlpHeaders} ;
183+ return {
184+ exporterProtocol,
185+ sampler,
186+ samplerArg,
187+ otlpEndpoint,
188+ otlpHeaders,
189+ } ;
163190}
164191
165192export function resolveBootstrapConfig (
0 commit comments