From e43cfd917f338cb8ce769ce8c261038b1d8bcbdd Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 2 Nov 2025 16:03:01 -1000 Subject: [PATCH 1/2] fix(nodejs): make aws-lambda and aws-sdk instrumentations respect OTEL_NODE_DISABLED_INSTRUMENTATIONS Extends PR #1653 to make AWS-specific instrumentations (aws-lambda, aws-sdk) also respect the OTEL_NODE_DISABLED_INSTRUMENTATIONS environment variable. Previously, these instrumentations were always loaded regardless of the disable flag. Now they follow the same conditional loading pattern as other instrumentations. Fixes: Users can now disable AWS Lambda auto-instrumentation in dev mode --- nodejs/packages/layer/src/wrapper.ts | 46 ++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/nodejs/packages/layer/src/wrapper.ts b/nodejs/packages/layer/src/wrapper.ts index 39c8e82d26..acbb974a7c 100644 --- a/nodejs/packages/layer/src/wrapper.ts +++ b/nodejs/packages/layer/src/wrapper.ts @@ -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', @@ -309,21 +311,39 @@ 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()), - ]; + : await defaultConfigureInstrumentations()) + ); + + return instrumentations; } function getPropagator(): TextMapPropagator { From f936f9b017ef16ee362d1d9fc3d47d8ebbf96c10 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 11 Nov 2025 15:52:00 -1000 Subject: [PATCH 2/2] fix: apply GTS linting fixes to wrapper.ts - Add trailing commas per Prettier rules - Fix object formatting with proper line breaks - Resolves CI lint failures in PR #2012 --- nodejs/packages/layer/src/wrapper.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/nodejs/packages/layer/src/wrapper.ts b/nodejs/packages/layer/src/wrapper.ts index acbb974a7c..1b9cc76ba2 100644 --- a/nodejs/packages/layer/src/wrapper.ts +++ b/nodejs/packages/layer/src/wrapper.ts @@ -319,9 +319,11 @@ async function createInstrumentations() { instrumentations.push( new AwsInstrumentation( typeof configureAwsInstrumentation === 'function' - ? configureAwsInstrumentation({ suppressInternalInstrumentation: true }) + ? configureAwsInstrumentation({ + suppressInternalInstrumentation: true, + }) : { suppressInternalInstrumentation: true }, - ) + ), ); } @@ -332,7 +334,7 @@ async function createInstrumentations() { typeof configureLambdaInstrumentation === 'function' ? configureLambdaInstrumentation({}) : {}, - ) + ), ); } @@ -340,7 +342,7 @@ async function createInstrumentations() { instrumentations.push( ...(typeof configureInstrumentations === 'function' ? configureInstrumentations() - : await defaultConfigureInstrumentations()) + : await defaultConfigureInstrumentations()), ); return instrumentations; @@ -485,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, }), ], };