fix(logger): scope lambda context per invocation under LMI concurrency#5430
Merged
Conversation
f33f4e4 to
89b72fd
Compare
89b72fd to
5e3e50e
Compare
dreamorosi
approved these changes
Jul 9, 2026
|
2 tasks
svozza
added a commit
that referenced
this pull request
Jul 9, 2026
…ogs by request id With the lambda context now scoped per invocation under LMI (#5430), the handler selects its own log lines by function_request_id — an independent per-invocation attribute — and the test asserts the InvokeStore-scoped invocationKey on those lines, making the suite a regression check for both the context scoping and appendKeys isolation. The suite adds ~4 minutes to the logger e2e cell, inside the agreed budget for running on every e2e dispatch, so the RUN_LMI_TESTS gate and workflow input are removed.
svozza
added a commit
that referenced
this pull request
Jul 10, 2026
…ogs by request id With the lambda context now scoped per invocation under LMI (#5430), the handler selects its own log lines by function_request_id — an independent per-invocation attribute — and the test asserts the InvokeStore-scoped invocationKey on those lines, making the suite a regression check for both the context scoping and appendKeys isolation. The suite adds ~4 minutes to the logger e2e cell, inside the agreed budget for running on every e2e dispatch, so the RUN_LMI_TESTS gate and workflow input are removed.
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.



Summary
Logger.addContext()stored the Lambda context in plain instance state, so when Lambda Managed Instances multiplexes concurrent invocations into the same execution environment, invocations overwrite each other's context and emitted log lines carry the wrongfunction_request_id,tenant_id, andcold_start. This PR scopes the wholelambdaContextper invocation via the InvokeStore whenAWS_LAMBDA_MAX_CONCURRENCYis set, using the same dual-path pattern already used for temporary attributes.Changes
setLambdaContext()/getLambdaContext()toLogAttributesStore, storing the context in the InvokeStore under a private symbol whenshouldUseInvokeStore()is true, and in instance state otherwise (throwsInvokeStore is not availableif the store is missing, matching the existing attribute methods)Logger.addContext()writes through the store;getPowertoolsLogData()andcreateChild()read through it, so formatters and child loggers stay consistentaddContext()/info()calls viasequence(): with the InvokeStore each log line carries its own invocation's request id, tenant id, and cold start; without it the last-write-wins behavior is preservedIssue number: closes #5429
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.