Skip to content
Open
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
61 changes: 48 additions & 13 deletions nodejs/packages/layer/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray';
import { AWSXRayLambdaPropagator } from '@opentelemetry/propagator-aws-xray-lambda';

const defaultInstrumentationList = [
'aws-lambda',
'aws-sdk',
'dns',
'express',
'graphql',
Expand Down Expand Up @@ -309,21 +311,41 @@ async function defaultConfigureInstrumentations() {
}

async function createInstrumentations() {
return [
new AwsInstrumentation(
typeof configureAwsInstrumentation === 'function'
? configureAwsInstrumentation({ suppressInternalInstrumentation: true })
: { suppressInternalInstrumentation: true },
),
new AwsLambdaInstrumentation(
typeof configureLambdaInstrumentation === 'function'
? configureLambdaInstrumentation({})
: {},
),
const activeInstrumentations = getActiveInstumentations();
const instrumentations = [];

// Conditionally load AWS SDK instrumentation
if (activeInstrumentations.has('aws-sdk')) {
instrumentations.push(
new AwsInstrumentation(
typeof configureAwsInstrumentation === 'function'
? configureAwsInstrumentation({
suppressInternalInstrumentation: true,
})
: { suppressInternalInstrumentation: true },
),
);
}

// Conditionally load AWS Lambda instrumentation
if (activeInstrumentations.has('aws-lambda')) {
instrumentations.push(
new AwsLambdaInstrumentation(
typeof configureLambdaInstrumentation === 'function'
? configureLambdaInstrumentation({})
: {},
),
);
}

// Load other instrumentations
instrumentations.push(
...(typeof configureInstrumentations === 'function'
? configureInstrumentations()
: await defaultConfigureInstrumentations()),
];
);

return instrumentations;
}

function getPropagator(): TextMapPropagator {
Expand Down Expand Up @@ -465,13 +487,26 @@ async function initializeMeterProvider(
'@opentelemetry/exporter-metrics-otlp-http'
);

// Configure default meter provider (doesn't export metrics)
// Configure default meter provider with configurable export interval
const metricExporter = new OTLPMetricExporter();

// Respect OTEL_METRIC_EXPORT_INTERVAL for Lambda serverless environments
// Default 60s is too long for Lambda (functions finish in ~5s and freeze)
const exportIntervalMillis = process.env.OTEL_METRIC_EXPORT_INTERVAL
? parseInt(process.env.OTEL_METRIC_EXPORT_INTERVAL, 10)
: 60000;

const exportTimeoutMillis = process.env.OTEL_METRIC_EXPORT_TIMEOUT
? parseInt(process.env.OTEL_METRIC_EXPORT_TIMEOUT, 10)
: 30000;

let meterConfig: unknown = {
resource,
readers: [
new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis,
exportTimeoutMillis,
}),
],
};
Expand Down