Skip to content

Bug: Conflict between POWERTOOLS_LOG_LEVEL and Lambda applicationLogLevelV2 #7220

@andresionek91

Description

@andresionek91

Expected Behaviour

POWERTOOLS_LOG_LEVEL (and POWERTOOLS_LOGGER_SAMPLE_RATE`) should decide what log lines Powertools emits.

Lambda’s applicationLogLevelV2 should only act as a platform filter (drop logs below that threshold before forwarding to CloudWatch).

Examples:

  • If POWERTOOLS_LOG_LEVEL=INFO and applicationLogLevelV2=DEBUG, then only INFO+ should be emitted, and those should appear in CloudWatch.
  • If POWERTOOLS_LOG_LEVEL=DEBUG and applicationLogLevelV2=INFO, then DEBUG logs should be emitted by Powertools but dropped by the platform, so only INFO+ appear in CloudWatch.

Current Behaviour

applicationLogLevelV2=DEBUG causes all logs, including DEBUG, to appear in CloudWatch, even if POWERTOOLS_LOG_LEVEL=INFO.

In effect, the Lambda application log level is overriding Powertools’ log level instead of filtering logs after emission.

POWERTOOLS_LOGGER_SAMPLE_RATE becomes ineffective when combined with applicationLogLevelV2=DEBUG, because all requests in a container emit DEBUG regardless of Powertools’ base level.

Code snippet

from aws_lambda_powertools import Logger

logger = Logger()

@logger.inject_lambda_context
def handler(event, context):
    logger.debug("Debug log line")
    logger.info("Info log line")
    return {"status": "ok"}

Possible Solution

Ensure Powertools filtering (POWERTOOLS_LOG_LEVEL, POWERTOOLS_LOGGER_SAMPLE_RATE) applies before logs are emitted.

The Lambda runtime should then filter logs again according to applicationLogLevelV2.

If this behavior is by design, document clearly that:

  • applicationLogLevelV2=DEBUG will force DEBUG logs through, regardless of Powertools config.
  • Sampling (POWERTOOLS_LOGGER_SAMPLE_RATE) works per-container and will appear overridden if applicationLogLevelV2=DEBUG is set.

Steps to Reproduce

Case 1

  • applicationLogLevelV2 = INFO
  • POWERTOOLS_LOG_LEVEL = DEBUG
  • Behaviour: Only INFO+ appear.
  • ✅ Expected: Only INFO+ appear. (works correctly)

Case 2

  • applicationLogLevelV2 = DEBUG
  • POWERTOOLS_LOG_LEVEL = INFO
  • Behaviour: DEBUG logs also appear.
  • ❌ Expected: Only INFO+ logs, since Powertools should suppress DEBUG.

Case 3

  • applicationLogLevelV2 = DEBUG
  • POWERTOOLS_LOG_LEVEL = INFO
  • POWERTOOLS_LOGGER_SAMPLE_RATE = 0.5
  • Behaviour: All requests show DEBUG logs.
  • ❌ Expected: Only ~50% of requests should show DEBUG logs.

Case 4

  • applicationLogLevelV2 = INFO
  • POWERTOOLS_LOG_LEVEL = INFO
  • POWERTOOLS_LOGGER_SAMPLE_RATE = 0.5
  • Behaviour: Only INFO+ appear.
  • ❌ Expected: Some requests/containers show DEBUG logs due to sampling.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions