Skip to content

fix(logging): do not lower verbosity from TRACE to DEBUG during log sampling - #2763

Open
dhaiirryyaa wants to merge 1 commit into
aws-powertools:mainfrom
dhaiirryyaa:fix/sampling-rate-trace-log-level
Open

dhaiirryyaa wants to merge 1 commit into
aws-powertools:mainfrom
dhaiirryyaa:fix/sampling-rate-trace-log-level

Conversation

@dhaiirryyaa

Copy link
Copy Markdown

Summary

Changes

Log sampling exists to make sampled invocations more verbose (e.g. INFO / WARN → DEBUG).
Previously, PowertoolsLogging.setLogLevelBasedOnSamplingRate unconditionally called loggingManager.setLogLevel(Level.DEBUG) whenever an invocation was sampled.
If the logger was already configured at a higher verbosity than DEBUG (such as POWERTOOLS_LOG_LEVEL=TRACE), sampling inadvertently demoted the log level to DEBUG, disabling TRACE on the very invocations selected for detailed diagnosis.

This change:

  1. Adds a guard check !LOG.isTraceEnabled() before setting the log level to DEBUG, ensuring sampling only increases verbosity and never reduces it.
  2. Aligns behavior with powertools-lambda-typescript (PR #2902).
  3. Adds unit tests in PowertoolsLoggingTest:
    • Verifies that sampling maintains TRACE when POWERTOOLS_LOG_LEVEL=TRACE.
    • Verifies that sampling still upgrades INFO to DEBUG as expected.

Issue number: Fixes #2726


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Log sampling lowers verbosity from TRACE to DEBUG

1 participant