Description
Expected Behavior
No warning logged that the current log level does not match AWS Lambda Advanced Logging Controls minimum log level when injectLambdaContext
Middy middleware is used.
Current Behavior
On every warm execution with injectLambdaContext
Middy middleware a warning is logged that the current log level does not match AWS Lambda Advanced Logging Controls minimum log level.
Problem:
injectLambdaContext
callsrefreshSampleRateCalculation
on every execution;refreshSampleRateCalculation
callsthis.setLogLevel
with the#initialLogLevel
on every warm call when debug sampling is not enabled;- #initialLogLevel contains the default value INFO, because AWS Lambda Advanced Logging Controls minimum log level is set (to a higher value than INFO).
Since the following commit 8c8d6b2, because refreshSampleRateCalculation
was added to middy.ts
.
Code snippet
import { Logger } from '@aws-lambda-powertools/logger';
import middy from '@middy/core';
const logger = new Logger();
export const handler = middy()
.use(injectLambdaContext(logger))
.handler(async () => ({}));
Steps to Reproduce
- Set application log level to WARN (AWS Lambda Advanced Logging Controls |
systemLogLevelV2
); - Set environment variable
POWERTOOLS_LOG_LEVEL=WARN
; - Don't configure any debug sampling;
- Use
injectLambdaContext
Middy middleware; - From a warm execution (coldStart=false) onwards every time a WARN is logged.
Possible Solution
setInitialLogLevel
in Logger.ts
assigns the #initialLogLevel
regardless if awsLogLevelShortCircuit is true and another check is added (or replaced for the awsLogLevelShortCircuit
condition in setInitialLogLevel
) if AWS Lambda Advanced Logging Controls is configured and sets the initial log level with this value.
Another solution would be documenting that Powertool's log level should be combined with AWS Lambda's application log level. The downside of this would be possible log pollution coming from libraries that don't use the Powertool logger, but something else (console eg).
Powertools for AWS Lambda (TypeScript) version
V2.16.0 - V2.18.0 (latest currently)
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
{
"level": "WARN",
"message": "Current log level (INFO) does not match AWS Lambda Advanced Logging Controls minimum log level (WARN). This can lead to data loss, consider adjusting them.",
"timestamp": "X",
"service": "X",
"cold_start": false,
"function_arn": "X",
"function_memory_size": "128",
"function_name": "X",
"function_request_id": "X",
"sampling_rate": 0,
"xray_trace_id": "X"
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status