@@ -355,13 +355,15 @@ function getPropagator(): TextMapPropagator {
355355 return new CompositePropagator ( { propagators } ) ;
356356}
357357
358- function getExportersFromEnv ( ) : SpanExporter [ ] {
358+ function getExportersFromEnv ( ) : SpanExporter [ ] | null {
359359 if (
360360 process . env . OTEL_TRACES_EXPORTER == null ||
361- process . env . OTEL_TRACES_EXPORTER . trim ( ) === '' ||
362- process . env . OTEL_TRACES_EXPORTER . includes ( 'none' )
361+ process . env . OTEL_TRACES_EXPORTER . trim ( ) === ''
363362 ) {
364- return [ new OTLPTraceExporter ( ) ] ;
363+ return [ ] ;
364+ }
365+ if ( process . env . OTEL_TRACES_EXPORTER . includes ( 'none' ) ) {
366+ return null ;
365367 }
366368
367369 const stringToExporter = new Map < string , ( ) => SpanExporter > ( [
@@ -385,16 +387,23 @@ function getExportersFromEnv(): SpanExporter[] {
385387
386388async function initializeTracerProvider (
387389 resource : Resource ,
388- ) : Promise < TracerProvider > {
390+ ) : Promise < TracerProvider | undefined > {
389391 let config : TracerConfig = {
390392 resource,
391393 spanProcessors : [ ] ,
392394 } ;
393395
396+ const exporters = getExportersFromEnv ( ) ;
397+ if ( ! exporters ) {
398+ return ;
399+ }
400+
394401 if ( typeof configureTracer === 'function' ) {
395402 config = configureTracer ( config ) ;
396- } else if ( process . env . OTEL_TRACES_EXPORTER ) {
397- const exporters = getExportersFromEnv ( ) ;
403+ }
404+
405+ if ( exporters . length ) {
406+ config . spanProcessors = [ ] ;
398407 exporters . map ( exporter => {
399408 if ( exporter instanceof ConsoleSpanExporter ) {
400409 config . spanProcessors ?. push ( new SimpleSpanProcessor ( exporter ) ) ;
@@ -403,16 +412,16 @@ async function initializeTracerProvider(
403412 }
404413 } ) ;
405414 }
406- if ( config . spanProcessors ?. length === 0 ) {
415+
416+ config . spanProcessors = config . spanProcessors || [ ] ;
417+ if ( config . spanProcessors . length === 0 ) {
407418 // Default
408- config . spanProcessors ?. push (
409- new BatchSpanProcessor ( new OTLPTraceExporter ( ) ) ,
410- ) ;
419+ config . spanProcessors . push ( new BatchSpanProcessor ( new OTLPTraceExporter ( ) ) ) ;
411420 }
412421
413422 // Logging for debug
414423 if ( logLevel === DiagLogLevel . DEBUG ) {
415- config . spanProcessors ? .push (
424+ config . spanProcessors . push (
416425 new SimpleSpanProcessor ( new ConsoleSpanExporter ( ) ) ,
417426 ) ;
418427 }
@@ -522,7 +531,7 @@ async function initializeProvider() {
522531 detectors : [ awsLambdaDetector , envDetector , processDetector ] ,
523532 } ) ;
524533
525- const tracerProvider : TracerProvider =
534+ const tracerProvider : TracerProvider | undefined =
526535 await initializeTracerProvider ( resource ) ;
527536 const meterProvider : unknown | undefined =
528537 await initializeMeterProvider ( resource ) ;
0 commit comments