feat: Make ApiKeyFactory return Option<String>#25
Merged
Conversation
duncanista
approved these changes
Jul 9, 2025
lym953
added a commit
to DataDog/datadog-lambda-extension
that referenced
this pull request
Jul 17, 2025
# Context The previous PR #717 defers API key resolution from extension init stage to flush time. However, that PR doesn't well handle the failure case. - Before that PR, if resolution fails in init stage, the extension will run an idle loop. - After that PR, the extension will crash at flush time, which will kill the runtime as well, which is not desired. # What does this PR do? 1. For traces, defer key resolution from `TraceProcessor.process_traces()` to `TraceFlusher.flush()`. - (This should ideally be in the previous PR, but since that is already approved, let me add this change in this new PR.) 2. If resolution fails at flush time, then make flush a no-op, so the extension can keep running and consume events without crashing. # Dependencies 1. DataDog/serverless-components#25 2. DataDog/libdatadog#1140 # Manual Test ## Steps 1. Create a layer in sandbox 2. Apply the layer to a Lambda function 3. Set the env var `DD_API_KEY_SECRET_ARN` to an invalid value 5. Run the Lambda 6. Then set `DD_API_KEY_SECRET_ARN` to a valid value 7. Run the Lambda ## Result 1. The function was successful <img width="319" alt="image" src="https://github.com/user-attachments/assets/f8a5cb36-f678-4643-ba1c-85f41256ffa1" /> 2. The extension printed some error logs <img width="737" height="33" alt="image" src="https://github.com/user-attachments/assets/22553d24-e1f5-4ee5-9a91-0d18e3e2f297" /> <img width="603" height="186" alt="image" src="https://github.com/user-attachments/assets/e797f991-ecba-45f0-8f49-7b7b59dd9e7b" /> 3. With valid secret ARN, the Lambda runs successfully and reports to Datadog <img width="678" height="150" alt="image" src="https://github.com/user-attachments/assets/073089f8-1e9a-4728-b8d1-1db7aa85d031" /> <img width="533" height="96" alt="image" src="https://github.com/user-attachments/assets/d5f2b81c-5e02-42bc-b3ef-85e611228fc6" /> # Automated Test I didn't add any automated test because from what I see in the codebase, existing tests are usually unit tests for short functions and not for long functions that this PR touches. Please let me know if you think I should add automated tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
ApiKeyFactoryreturnsString. This PR makes it returnOption<String>.Flusher, if API key resolution fails, then makeflush_metrics()a no-op by returning early.Motivation
API key resolution can fail. In this case, we should allow the resolver function to return
None.Additional Notes
Describe how to test/QA your changes
Used and tested in bottlecap: DataDog/datadog-lambda-extension#732