Skip to content
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

Feature request: Calculate Log Sampling Per Request #3278

Open
2 tasks done
jasonwadsworth opened this issue Nov 1, 2024 · 4 comments
Open
2 tasks done

Feature request: Calculate Log Sampling Per Request #3278

jasonwadsworth opened this issue Nov 1, 2024 · 4 comments
Labels
feature-request This item refers to a feature request for an existing or new utility logger This item relates to the Logger Utility need-customer-feedback Requires more customers feedback before making or revisiting a decision revisit-in-3-months Blocked issues/PRs that need to be revisited

Comments

@jasonwadsworth
Copy link

Use case

The log sampling concept is great but not very useful in practice if you have provisioned concurrency turned on due to the decision happening at initialization.

Solution/User Experience

Per request sampling would be ideal, as opposed to per log sampling. That would give the user the ability to see the entirety of a request that was sampled rather than a mix of logs for different requests.

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

@jasonwadsworth jasonwadsworth added feature-request This item refers to a feature request for an existing or new utility triage This item has not been triaged by a maintainer, please wait labels Nov 1, 2024
@dreamorosi
Copy link
Contributor

dreamorosi commented Nov 4, 2024

Hi @jasonwadsworth, thanks for opening this issue.

This is an intended limitation that is documented in the docs, and we designed this feature this way to avoid adding overhead for those customers who don't use the feature.

Up until now we have never gotten any demand of changing this behavior, but it's something we could consider provided that there's enough demand from multiple customers.

In the meantime, you can call the logger.refreshSampleRateCalculation() method manually at the beginning or end of your function handler to recalculate the sampling.

@dreamorosi dreamorosi added logger This item relates to the Logger Utility need-customer-feedback Requires more customers feedback before making or revisiting a decision revisit-in-3-months Blocked issues/PRs that need to be revisited and removed triage This item has not been triaged by a maintainer, please wait labels Nov 4, 2024
@dreamorosi
Copy link
Contributor

Hi @jasonwadsworth, are you by chance using the Middy.js middleware or class method decorator like:

import { Logger } from '@aws-lambda-powertools/logger';
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
import middy from '@middy/core';

export const handler = middy(async () => {
  // your code
}).use(injectLambdaContext(logger);

or

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

class Lambda {
  @logger.injectLambdaContext()
  async handler (event, context) {
    // your code
  }
}

const lambda = new Lambda();
export const handler = lambda.handler.bind(lambda);

If yes, we could add an option to both of them to allow you to configure this behavior and opt-in into recalculating the rate at every request, for example:

import { Logger } from '@aws-lambda-powertools/logger';
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
import middy from '@middy/core';

export const handler = middy(async () => {
  // your code
}).use(injectLambdaContext(logger, { refreshSampleRateCalculation: true }); // same for the decorator

This would be an unobtrusive change that we could roll out easily at any time.l

@jasonwadsworth
Copy link
Author

I'm not, but I was going to try your first suggestion for now.

@dreamorosi
Copy link
Contributor

Thank you for clarifying.

As of now, unless you're using one of these two methods then the Logger has no way of knowing when a request starts/ends, so it'd be tricky to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This item refers to a feature request for an existing or new utility logger This item relates to the Logger Utility need-customer-feedback Requires more customers feedback before making or revisiting a decision revisit-in-3-months Blocked issues/PRs that need to be revisited
Projects
Development

No branches or pull requests

2 participants