Skip to content

Commit 44f1989

Browse files
authored
Merge branch 'main' into update_actions_version
2 parents d2d1f3f + 470c0d1 commit 44f1989

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,23 @@ export class AwsOpentelemetryConfigurator {
188188
}
189189

190190
public configure(): Partial<NodeSDKConfiguration> {
191-
let config: Partial<NodeSDKConfiguration>;
192-
if (AwsOpentelemetryConfigurator.isApplicationSignalsEnabled()) {
193-
// config.autoDetectResources is set to False, as the resources are detected and added to the
194-
// resource ahead of time. The resource is needed to be populated ahead of time instead of letting
195-
// the OTel Node SDK do the population work because the constructed resource was required to build
196-
// the sampler (if using XRay sampler) and the AwsMetricAttributesSpanExporter and AwsSpanMetricsProcessor
197-
config = {
198-
instrumentations: this.instrumentations,
199-
resource: this.resource,
200-
idGenerator: this.idGenerator,
201-
sampler: this.sampler,
202-
// Error message 'Exporter "otlp" requested through environment variable is unavailable.'
203-
// will appear from BasicTracerProvider that is used in the OTel JS SDK, even though the
204-
// span processors are specified
205-
// https://github.com/open-telemetry/opentelemetry-js/issues/3449
206-
spanProcessors: this.spanProcessors,
207-
autoDetectResources: false,
208-
textMapPropagator: this.propagator,
209-
};
210-
} else {
211-
// Default experience config
212-
config = {
213-
instrumentations: this.instrumentations,
214-
resource: this.resource,
215-
sampler: this.sampler,
216-
idGenerator: this.idGenerator,
217-
autoDetectResources: false,
218-
};
219-
}
191+
// config.autoDetectResources is set to False, as the resources are detected and added to the
192+
// resource ahead of time. The resource is needed to be populated ahead of time instead of letting
193+
// the OTel Node SDK do the population work because the constructed resource was required to build
194+
// the sampler (if using XRay sampler) and the AwsMetricAttributesSpanExporter and AwsSpanMetricsProcessor
195+
const config: Partial<NodeSDKConfiguration> = {
196+
instrumentations: this.instrumentations,
197+
resource: this.resource,
198+
idGenerator: this.idGenerator,
199+
sampler: this.sampler,
200+
// Error message 'Exporter "otlp" requested through environment variable is unavailable.'
201+
// will appear from BasicTracerProvider that is used in the OTel JS SDK, even though the
202+
// span processors are specified
203+
// https://github.com/open-telemetry/opentelemetry-js/issues/3449
204+
spanProcessors: this.spanProcessors,
205+
autoDetectResources: false,
206+
textMapPropagator: this.propagator,
207+
};
220208

221209
return config;
222210
}

aws-distro-opentelemetry-node-autoinstrumentation/test/aws-opentelemetry-configurator.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/expor
99
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
1010
import { Resource } from '@opentelemetry/resources';
1111
import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
12-
import { AlwaysOffSampler, ReadableSpan, SpanProcessor, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base';
12+
import {
13+
AlwaysOffSampler,
14+
BatchSpanProcessor,
15+
ReadableSpan,
16+
SpanProcessor,
17+
TraceIdRatioBasedSampler,
18+
} from '@opentelemetry/sdk-trace-base';
1319
import {
1420
AlwaysOnSampler,
1521
NodeTracerProvider,
@@ -457,6 +463,24 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
457463
delete process.env.AWS_XRAY_DAEMON_ADDRESS;
458464
});
459465

466+
it('Tests that OTLP exporter from the configurator is UDPExporter when Application Signals is disabled on Lambda', () => {
467+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'TestFunction';
468+
process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED = 'False';
469+
process.env.OTEL_TRACES_EXPORTER = 'otlp';
470+
process.env.AWS_XRAY_DAEMON_ADDRESS = 'www.test.com:2222';
471+
472+
const config = new AwsOpentelemetryConfigurator([]).configure();
473+
expect((config.spanProcessors as any)[0]).toBeInstanceOf(BatchSpanProcessor);
474+
expect((config.spanProcessors as any)[0]._exporter).toBeInstanceOf(OTLPUdpSpanExporter);
475+
expect((config.spanProcessors as any)[0]._exporter._endpoint).toBe('www.test.com:2222');
476+
expect(config.spanProcessors?.length).toEqual(1);
477+
478+
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
479+
delete process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED;
480+
delete process.env.OTEL_TRACES_EXPORTER;
481+
delete process.env.AWS_XRAY_DAEMON_ADDRESS;
482+
});
483+
460484
it('Test CustomizeSpanProcessors for Lambda', () => {
461485
process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED = 'True';
462486
process.env.AWS_LAMBDA_FUNCTION_NAME = 'TestFunction';

0 commit comments

Comments
 (0)