Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
grimmbraten opened this issue Mar 13, 2025 · 7 comments · Fixed by #3722
Closed
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped logger This item relates to the Logger Utility

Comments

@grimmbraten
Copy link

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

@grimmbraten grimmbraten added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Mar 13, 2025
Copy link

boring-cyborg bot commented Mar 13, 2025

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@dreamorosi dreamorosi self-assigned this Mar 13, 2025
@dreamorosi dreamorosi added logger This item relates to the Logger Utility discussing The issue needs to be discussed, elaborated, or refined and removed triage This item has not been triaged by a maintainer, please wait labels Mar 13, 2025
@dreamorosi dreamorosi moved this from Triage to Backlog in Powertools for AWS Lambda (TypeScript) Mar 13, 2025
@dreamorosi dreamorosi added researching and removed discussing The issue needs to be discussed, elaborated, or refined labels Mar 13, 2025
@dreamorosi
Copy link
Contributor

Hi @grimmbraten - thank you for opening the issue and reporting this bug.

From a couple of initial tests I can confirm that we have a bug when using the code you shared above. This is related to some changes we introduced in 2.16.0 and this is a regression.

I am still investigating a fix, but it might require some work to accommodate the original (2.15.0) and new (2.16.0) behavior.

I'll share more info here as soon as I have them, in the meantime I'd recommend rolling back to v2.15.0.

@dreamorosi dreamorosi moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Mar 13, 2025
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation and removed researching labels Mar 13, 2025
@dreamorosi dreamorosi linked a pull request Mar 13, 2025 that will close this issue
@dreamorosi dreamorosi moved this from Working on it to Pending review in Powertools for AWS Lambda (TypeScript) Mar 13, 2025
@dreamorosi
Copy link
Contributor

I identified the issue and opened a PR that should fix it.

@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (TypeScript) Mar 13, 2025
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Mar 13, 2025
@grimmbraten
Copy link
Author

Hey @dreamorosi 👋 Thank you for fixing the bug! When will a release be available with the fix included? ☺

@dreamorosi
Copy link
Contributor

We've made a release that includes the fix less than half hour ago.

The new version (2.17.0) is already on npm but we haven't published the release notes yet.

Copy link
Contributor

This is now released under v2.17.0 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Mar 25, 2025
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped logger This item relates to the Logger Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants