fix: skip unnecessary API key retrieval when Datadog extension is present #680
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR refactors the API key retrieval logic in
MetricsListener.onStartInvocation()
to skip thegetAPIKey()
call when the Datadog Lambda Extension is running. The API key is now only fetched when the extension is not present, avoiding unnecessary Secrets Manager API calls.Motivation
This change addresses an issue where Lambda functions using provisioned concurrency with the Datadog Lambda Extension experience "Signature expired" errors in logs when using Secrets Manager for API key storage.
Root Cause:
DD_API_KEY_SECRET_ARN
is configured and the Datadog Lambda Extension is running, the code was still callinggetAPIKey()
during initializationgetAPIKey()
wasn't being awaited, the Lambda instance could pause during the 3-minute period between initialization and when requests start arriving (a characteristic of provisioned concurrency)InvalidSignatureException: Signature expired
errors being loggedEnvironment where this occurs:
DD_API_KEY_SECRET_ARN
(Secrets Manager)Testing Guidelines
Additional Notes
This change also highlights a broader architectural concern: async operations like
getAPIKey()
should generally be awaited to prevent Lambda instances from pausing unexpectedly. While this specific fix addresses the immediate issue by avoiding unnecessary API calls when the extension is running, the underlying concern about unawaited async operations remains.Types of Changes
Check all that apply