33// Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.
44
55import { TextMapPropagator , diag } from '@opentelemetry/api' ;
6+ import { getPropagator } from '@opentelemetry/auto-configuration-propagators' ;
67import { getResourceDetectors as getResourceDetectorsFromEnv } from '@opentelemetry/auto-instrumentations-node' ;
78import {
8- CompositePropagator ,
99 ENVIRONMENT ,
1010 TracesSamplerValues ,
1111 getEnv ,
1212 getEnvWithoutDefaults ,
13- W3CBaggagePropagator ,
14- W3CTraceContextPropagator ,
1513} from '@opentelemetry/core' ;
1614import { OTLPMetricExporter as OTLPGrpcOTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc' ;
1715import {
@@ -24,8 +22,6 @@ import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/expo
2422import { ZipkinExporter } from '@opentelemetry/exporter-zipkin' ;
2523import { AWSXRayIdGenerator } from '@opentelemetry/id-generator-aws-xray' ;
2624import { Instrumentation } from '@opentelemetry/instrumentation' ;
27- import { AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray' ;
28- import { AWSXRayLambdaPropagator } from '@opentelemetry/propagator-aws-xray-lambda' ;
2925import { awsEc2DetectorSync , awsEcsDetectorSync , awsEksDetectorSync } from '@opentelemetry/resource-detector-aws' ;
3026import {
3127 Detector ,
@@ -85,12 +81,6 @@ const FORMAT_OTEL_UNSAMPLED_TRACES_BINARY_PREFIX = 'T1U';
8581// which will reduce the chance of UDP package size is larger than 64KB
8682const LAMBDA_SPAN_EXPORT_BATCH_SIZE = 10 ;
8783
88- const propagatorMap = new Map < string , ( ) => TextMapPropagator > ( [
89- [ 'tracecontext' , ( ) => new W3CTraceContextPropagator ( ) ] ,
90- [ 'baggage' , ( ) => new W3CBaggagePropagator ( ) ] ,
91- [ 'xray' , ( ) => new AWSXRayPropagator ( ) ] ,
92- [ 'xray-lambda' , ( ) => new AWSXRayLambdaPropagator ( ) ] ,
93- ] ) ;
9484/**
9585 * Aws Application Signals Config Provider creates a configuration object that can be provided to
9686 * the OTel NodeJS SDK for Auto Instrumentation with Application Signals Functionality.
@@ -179,7 +169,7 @@ export class AwsOpentelemetryConfigurator {
179169 this . resource = autoResource ;
180170
181171 this . instrumentations = instrumentations ;
182- this . propagator = this . getPropagator ( ) ;
172+ this . propagator = getPropagator ( ) ;
183173
184174 // TODO: Consider removing AWSXRayIdGenerator as it is not needed
185175 // Similarly to Java, always use AWS X-Ray Id Generator
@@ -206,32 +196,6 @@ export class AwsOpentelemetryConfigurator {
206196 return autoResource ;
207197 }
208198
209- private getPropagator ( ) : TextMapPropagator {
210- if ( process . env . OTEL_PROPAGATORS == null || process . env . OTEL_PROPAGATORS . trim ( ) === '' ) {
211- return new CompositePropagator ( {
212- propagators : [ new W3CTraceContextPropagator ( ) , new W3CBaggagePropagator ( ) ] ,
213- } ) ;
214- }
215- const propagatorsFromEnv = Array . from (
216- new Set ( process . env . OTEL_PROPAGATORS ?. split ( ',' ) . map ( value => value . toLowerCase ( ) . trim ( ) ) )
217- ) ;
218- const propagators = propagatorsFromEnv . flatMap ( propagatorName => {
219- if ( propagatorName === 'none' ) {
220- diag . info (
221- 'Not selecting any propagator for value "none" specified in the environment variable OTEL_PROPAGATORS'
222- ) ;
223- return [ ] ;
224- }
225- const propagatorFactoryFunction = propagatorMap . get ( propagatorName ) ;
226- if ( propagatorFactoryFunction == null ) {
227- diag . warn ( `Invalid propagator "${ propagatorName } " specified in the environment variable OTEL_PROPAGATORS` ) ;
228- return [ ] ;
229- }
230- return propagatorFactoryFunction ( ) ;
231- } ) ;
232- return new CompositePropagator ( { propagators } ) ;
233- }
234-
235199 public configure ( ) : Partial < NodeSDKConfiguration > {
236200 // config.autoDetectResources is set to False, as the resources are detected and added to the
237201 // resource ahead of time. The resource is needed to be populated ahead of time instead of letting
0 commit comments