Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,35 +188,23 @@ export class AwsOpentelemetryConfigurator {
}

public configure(): Partial<NodeSDKConfiguration> {
let config: Partial<NodeSDKConfiguration>;
if (AwsOpentelemetryConfigurator.isApplicationSignalsEnabled()) {
// config.autoDetectResources is set to False, as the resources are detected and added to the
// resource ahead of time. The resource is needed to be populated ahead of time instead of letting
// the OTel Node SDK do the population work because the constructed resource was required to build
// the sampler (if using XRay sampler) and the AwsMetricAttributesSpanExporter and AwsSpanMetricsProcessor
config = {
instrumentations: this.instrumentations,
resource: this.resource,
idGenerator: this.idGenerator,
sampler: this.sampler,
// Error message 'Exporter "otlp" requested through environment variable is unavailable.'
// will appear from BasicTracerProvider that is used in the OTel JS SDK, even though the
// span processors are specified
// https://github.com/open-telemetry/opentelemetry-js/issues/3449
spanProcessors: this.spanProcessors,
autoDetectResources: false,
textMapPropagator: this.propagator,
};
} else {
// Default experience config
config = {
instrumentations: this.instrumentations,
resource: this.resource,
sampler: this.sampler,
idGenerator: this.idGenerator,
autoDetectResources: false,
};
}
// config.autoDetectResources is set to False, as the resources are detected and added to the
// resource ahead of time. The resource is needed to be populated ahead of time instead of letting
// the OTel Node SDK do the population work because the constructed resource was required to build
// the sampler (if using XRay sampler) and the AwsMetricAttributesSpanExporter and AwsSpanMetricsProcessor
const config: Partial<NodeSDKConfiguration> = {
instrumentations: this.instrumentations,
resource: this.resource,
idGenerator: this.idGenerator,
sampler: this.sampler,
// Error message 'Exporter "otlp" requested through environment variable is unavailable.'
// will appear from BasicTracerProvider that is used in the OTel JS SDK, even though the
// span processors are specified
// https://github.com/open-telemetry/opentelemetry-js/issues/3449
spanProcessors: this.spanProcessors,
autoDetectResources: false,
textMapPropagator: this.propagator,
};

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/expor
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { Resource } from '@opentelemetry/resources';
import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
import { AlwaysOffSampler, ReadableSpan, SpanProcessor, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base';
import {
AlwaysOffSampler,
BatchSpanProcessor,
ReadableSpan,
SpanProcessor,
TraceIdRatioBasedSampler,
} from '@opentelemetry/sdk-trace-base';
import {
AlwaysOnSampler,
NodeTracerProvider,
Expand Down Expand Up @@ -457,6 +463,24 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
delete process.env.AWS_XRAY_DAEMON_ADDRESS;
});

it('Tests that OTLP exporter from the configurator is UDPExporter when Application Signals is disabled on Lambda', () => {
process.env.AWS_LAMBDA_FUNCTION_NAME = 'TestFunction';
process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED = 'False';
process.env.OTEL_TRACES_EXPORTER = 'otlp';
process.env.AWS_XRAY_DAEMON_ADDRESS = 'www.test.com:2222';

const config = new AwsOpentelemetryConfigurator([]).configure();
expect((config.spanProcessors as any)[0]).toBeInstanceOf(BatchSpanProcessor);
expect((config.spanProcessors as any)[0]._exporter).toBeInstanceOf(OTLPUdpSpanExporter);
expect((config.spanProcessors as any)[0]._exporter._endpoint).toBe('www.test.com:2222');
expect(config.spanProcessors?.length).toEqual(1);

delete process.env.AWS_LAMBDA_FUNCTION_NAME;
delete process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED;
delete process.env.OTEL_TRACES_EXPORTER;
delete process.env.AWS_XRAY_DAEMON_ADDRESS;
});

it('Test CustomizeSpanProcessors for Lambda', () => {
process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED = 'True';
process.env.AWS_LAMBDA_FUNCTION_NAME = 'TestFunction';
Expand Down
Loading