Skip to content

Commit 470c0d1

Browse files
authored
UDPExporter should be useable when Application Signals is disabled on Lambda (#148)
*Issue #, if available:* Currently, if AppSignals is disabled, UDP Span Exporter not usable in Lambda. [According to this comment](https://github.com/aws-observability/aws-otel-js-instrumentation/blob/v0.5.0/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts#L440-L443), the correct logic should be: >If isLambdaEnvironment is true, we will default to exporting OTel spans via udp_exporter, regardless of whether AppSignals is true or false. Currently, this is not respected because when AppSignals is disabled, ADOT's otel config cannot use the UDPExporter - Currently, the only difference between the `AppSignals enabled` and `AppSignals disabled` configurations is that in the "disabled" case, ADOT leaves the Span Exporter/Processor and textMapPropagator initialization work to the OTel JS SDK. Only in `AppSignals enabled` scenario, the configured UDPExporter is accessible. *Description of changes:* Update `configure()` to not depend on AppSignalsEnabled flag (always use the Span Exporter/Processor and textMapPropagator configurations made from the ADOT configurator) - [Similarly to Python](https://github.com/aws-observability/aws-otel-python-instrumentation/blob/v0.8.0/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py#L181), always use the ADOT configured Span Exporter/Processor, which is already configured based on the AppSignalsEnabled flag - textMapPropagator configuration is still using [upstream's configuration](https://github.com/aws-observability/aws-otel-js-instrumentation/blob/v0.5.0/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts#L163) (includes the XRay Propagator) *Testing:* - Add Unit Test - Test that spans are exported in Lambda when AppSignals is disabled By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 6036eb2 commit 470c0d1

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)