From 5daec4dd79229cf7faae320fcbafdf4bbbbfbb86 Mon Sep 17 00:00:00 2001 From: Nao Iizuka Date: Thu, 16 Oct 2025 19:28:03 +0900 Subject: [PATCH] fix: skip API key retrieval when extension is running Move getAPIKey call to avoid unnecessary Secrets Manager calls when Datadog Lambda Extension is present, preventing Signature expired errors in provisioned concurrency environments. --- src/metrics/listener.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/metrics/listener.ts b/src/metrics/listener.ts index 60cf0ded..65f9712e 100644 --- a/src/metrics/listener.ts +++ b/src/metrics/listener.ts @@ -74,13 +74,6 @@ export class MetricsListener { } public async onStartInvocation(_: any, context?: Context) { - // We get the API key in onStartInvocation rather than in the constructor because in busy functions, - // initialization may occur more than 5 minutes before the first invocation (due to proactive initialization), - // resulting in AWS errors: https://github.com/aws/aws-sdk-js-v3/issues/5192#issuecomment-2073243617 - if (!this.apiKey) { - this.apiKey = this.getAPIKey(this.config); - } - if (this.isExtensionRunning === undefined) { this.isExtensionRunning = await isExtensionRunning(); logDebug(`Extension present: ${this.isExtensionRunning}`); @@ -98,6 +91,12 @@ export class MetricsListener { return; } + // We get the API key in onStartInvocation rather than in the constructor because in busy functions, + // initialization may occur more than 5 minutes before the first invocation (due to proactive initialization), + // resulting in AWS errors: https://github.com/aws/aws-sdk-js-v3/issues/5192#issuecomment-2073243617 + if (!this.apiKey) { + this.apiKey = this.getAPIKey(this.config); + } this.currentProcessor = this.createProcessor(this.config, this.apiKey); }