Skip to content

Bug: log sampling is not working in v2 #2668

Closed
@theburningmonk

Description

@theburningmonk

Expected Behavior

When POWERTOOLS_LOG_SAMPLE_RATE is set to 0.1 and every invocation includes a call to logger.refreshSampleRateCalculation() to recalculate the sampling rate, the debug logs should be recorded for only 10% of invocations.

Current Behavior

The sampling decision is made at cold start, and then all invocations afterwards will either log all debug logs or none at all. The refreshSampleRateCalculation() method is not giving the correct behaviour.

Code snippet

This line is included at the start of a handler function:

logger.refreshSampleRateCalculation()

The POWERTOOLS_LOG_LEVEL env var is set to ERROR.
The POWERTOOLS_LOGGER_SAMPLE_RATE env var is set to 0.1

Steps to Reproduce

Create a function with:

  • POWERTOOLS_LOGGER_SAMPLE_RATE env var set to 0.1
  • POWERTOOLS_LOG_LEVEL env var set to ERROR
  • include a call to logger.refreshSampleRateCalculation() at the start of the handler
  • include a few debug logs
    Invoke the function multiple times to see sampling decision is taken once, at cold start, but then never changed on subsequent invocations on the same worker

Possible Solution

No response

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions