fix(logger): scope debug sampling log level per invocation under LMI concurrency - #5544
Open
vishwakt wants to merge 1 commit into
Open
fix(logger): scope debug sampling log level per invocation under LMI concurrency#5544vishwakt wants to merge 1 commit into
vishwakt wants to merge 1 commit into
Conversation
…concurrency refreshSampleRateCalculation() runs once per invocation and wrote its random sampling decision into the instance-level log level shared by all concurrent invocations. Under Lambda Managed Instances concurrency, whichever invocation's refresh ran last won for every in-flight invocation: sampled-in invocations had their debug logs silently dropped, and sampled-out invocations emitted debug logs they were never sampled for. Store the effective log level in the InvokeStore when concurrency is enabled and an invocation context is active, falling back to the instance level set at initialization. The cold-start refresh guard stays environment-wide so only the first invocation of an environment keeps the boot-time sampling decision. Closes aws-powertools#5542
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
Changes
refreshSampleRateCalculation()runs once per invocation (from both theinjectLambdaContextmiddy middleware and the decorator) and wrote its random sampling decision intothis.logLevel, an instance field shared by all concurrent invocations. Under Lambda Managed Instances concurrency, whichever invocation's refresh ran last won for every in-flight invocation: sampled-in invocations had their debug logs silently dropped after a concurrent sampled-out invocation reset the level, and sampled-out invocations emitted debug logs they were never sampled for.Following the direction agreed in the issue:
AWS_LAMBDA_MAX_CONCURRENCYset) and an invocation context is active, with the instance level set at initialization as the fallback. A private#getLogLevel()accessor resolves reads (thelevelgetter,getLevelName(), the print gate, and the sampling refresh guard), and a private#setLogLevel()routes writes: inside an invocation context they go to the InvokeStore, outside one (e.g. during init) they set the instance level as before.refreshedTimes) stays environment-wide, so only the first invocation of an environment keeps the boot-time sampling decision and warm invocations re-roll as they do today.Added regression tests in
tests/unit/concurrency/sampling.test.ts:setLogLevel('DEBUG')does not leak into later invocations (fails on main)setLogLevel()outside an invocation context sets the instance levelAll existing logger unit tests pass unchanged (228 tests), including the existing non-concurrent sampling suite, with 100% coverage on
Logger.ts.Issue number: closes #5542
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.