Skip to content

Bug: manually calling refreshSampleRateCalculation does not refresh the sampling decision #3718

Closed
@grimmbraten

Description

@grimmbraten

Expected Behavior

Invoking a hot Lambda function refreshes the sampling decision. This results in that log level being sometimes lowered to DEBUG based on my set sampleRateValue.

Image

Current Behavior

Invoking a hot Lambda function does not refresh the sampling decision. The sampling decision seems to only happen on Logger initialization.

Image

Code snippet

The Lambda function uses the POWERTOOLS_LOGGER_SAMPLE_RATE environment variable with a value of 0.5.

import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({
  serviceName: 'powertools-logger-test',
});

export const handler = async () => {
  logger.refreshSampleRateCalculation();

  logger.debug('visible sometimes');
  logger.info('@aws-lambda-powertools/logger" = 2.xx');
};

Steps to Reproduce

  1. Create a Lambda function according to the provided code snippet.
  2. Ensure that the Lambda function uses the POWERTOOLS_LOGGER_SAMPLE_RATE environment variable and that it has a high percentage to lower the log level.
  3. Install version 2.15.0 of the @aws-lambda-powertools/logger, deploy the function, and invoke it a few times to confirm that the DEBUG log level is sometimes used.
  4. Install version 2.16.0 of the @aws-lambda-powertools/logger, deploy the function, and invoke it a few times. The DEBUG log level will be used for all invocations or none of them (refreshSampleRateCalculation function has no effect).

Possible Solution

No response

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

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