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: Create an environment variable to allow customer disable custom metrics #2996

Closed
2 tasks done
leandrodamascena opened this issue Aug 24, 2023 · 8 comments · Fixed by #6046
Closed
2 tasks done
Assignees
Labels
feature-request feature request good first issue Good for newcomers metrics

Comments

@leandrodamascena
Copy link
Contributor

Use case

Original discussion: #2986

Similar to the Tracer utility (https://docs.powertools.aws.dev/lambda/python/latest/core/tracer/#environment-variables), our customers want to disable custom metrics in environments like dev and others.

More information here: https://discord.com/channels/1006478942305263677/1006478942787604491/1143575948994826260

Solution/User Experience

Create an environment variable to explicitly disable custom metrics.

Alternative solutions

No response

Acknowledgment

@dreamorosi
Copy link
Contributor

The discussion on Discord seems to suggest that this is going to be a feature for non-production environments and/or testing, if this is the case, should this be part of the existing POWERTOOLS_DEV variable described in aws-powertools/powertools-lambda#86?

@leandrodamascena
Copy link
Contributor Author

The discussion on Discord seems to suggest that this is going to be a feature for non-production environments and/or testing, if this is the case, should this be part of the existing POWERTOOLS_DEV variable described in aws-powertools/powertools-lambda#86?

That's a great point @dreamorosi! I think we need to create an explicit variable like POWERTOOLS_METRICS_DISABLED to allow customers to only disable custom metrics and no matter the environment, it's a customer choice.

But what you're suggesting is: if the POWERTOOLS_DEV env is set, we automatically disable custom metrics the same way we do with Tracer, right? It makes lot of sense to me and I think we should go in this way.

@dreamorosi
Copy link
Contributor

dreamorosi commented Aug 24, 2023

But what you're suggesting is: if the POWERTOOLS_DEV env is set, we automatically disable custom metrics the same way we do with Tracer, right? It makes lot of sense to me and I think we should go in this way.

Yes

I think we need to create an explicit variable like POWERTOOLS_METRICS_DISABLED to allow customers to only disable custom metrics and no matter the environment, it's a customer choice.

I think the question here is: what type of use case does this environment variable enable, and when do we want customers to use it?

The reasoning we have been using with Tracer and Event Handler is that the default behavior is for tracing to be enabled and for Event Handler to have (for example) CORS enabled & scoped down. By providing an environment we allow customers to override this behavior in particular occasions like testing or development environments.

The key proposition of these env variables is not to provide yet another configuration option but rather allow customers to temporarily tweak the behavior in some cases without having to change their code: i.e. I can test my production code without changes but I want to disable tracing because the X-Ray Daemon is not available in my testing environment.

While it's indeed a customer choice, I think it should be explicit that we want these behaviors (i.e. tracing being disabled, metrics not being emitted, event handler allowing any origins, etc.) only in development environments and not in production.

Having these settings behind an env variable that is explicitly named after the use case (POWERTOOLS_DEV) conveys this message and avoids foot guns like customer inadvertently leaves/sets POWERTOOLS_METRICS_DISABLED or POWERTOOLS_TRACER_DISABLED enabled in production & loses data.

If they really don't want to emit metrics / traces in any of their environments, including production, then they should remove the dependency altogether to avoid having dead code / code that is a no-op but still gets imported and has potential impact on their Init phase.

To sum up: I'm not against giving customers choice, but I think that we also have the responsibility to educate customers and be opinionated on topics like this, otherwise we'll end up becoming yet another k8s with dozens of knobs & handles.

This by the way, was also the aim of the POWERTOOLS_DEV RFC which also mentions a potential future deprecation of one-off variables like POWERTOOLS_EVENT_HANDLER_DEBUG:

This change future-proof additional convenience for customers and lower cognitive load on needing multiple env vars to the same end. We will create a new section in the documentation to keep track of behaviours this env var will enable.

In my opinion adding a POWERTOOLS_METRICS_DISABLED would go against that and encourage the sprawl.

With that said, I'm happy to discuss this further and commit in case everyone else wants to go in this direction.

@leandrodamascena
Copy link
Contributor Author

I think the question here is: what type of use case does this environment variable enable, and when do we want customers to use it?

I see many cases where customers can use this: development environment, stage environment, stress testing where custom metrics don't matter, even in production if the customer just wants to disable metrics globally without changing code. There are many use cases where I don't think we can cover them all, and forcing clients to use POWERTOOLS_DEV in all those cases is not the best choice.

The key proposition of these env variables is not to provide yet another configuration option but rather allow customers to temporarily tweak the behavior in some cases without having to change their code: i.e. I can test my production code without changes but I want to disable tracing because the X-Ray Daemon is not available in my testing environment.

I think this is a configuration that makes the adoption of a library like Powertools more flexible and allows customers to choose their desired behavior. As I said in the first paragraph, I can't think of all the use cases customers might have, but I would like to have the option to only disable custom business metrics if I'm running a stress test in the pre-production environment.

If they really don't want to emit metrics / traces in any of their environments, including production, then they should remove the dependency altogether to avoid having dead code / code that is a no-op but still gets imported and has potential impact on their Init phase.

This is true for Tracer, where the customer can remove the X-Ray dependency, but for Metrics there is no such option as our default provider uses print/console.log to generate EMF to the standard output CloudWatch.

To sum up: I'm not against giving customers choice, but I think that we also have the responsibility to educate customers and be opinionated on topics like this, otherwise we'll end up becoming yet another k8s with dozens of knobs & handles.

Yes, I agree that we should avoid creating a complex ecosystem where customers need dozens of resources to deploy a Hello World and we're still far from that. We're just giving the customer more flexibility in a controlled environment.

With that said, I'm happy to discuss this further and commit in case everyone else wants to go in this direction.

I fully agree that we need to listen to others before making a decision.

Thank you very much for raising all these points, as we are always doing an amazing job when we try to cover as many situations as possible to deliver the best customer experience. 🚀

cc @rubenfonseca @heitorlessa

@rubenfonseca
Copy link
Contributor

Great points here! I also believe that running a staging / QA environment with POWERTOOLS_DEV would not be smart. Besides, you might have different reasons for enabling metrics BUT not logs, or vice-verse. So I believe integrating with POWERTOOLS_DEV and having a dedicated environment variable makes sense here.

@leandrodamascena leandrodamascena moved this from Triage to Pending review in Powertools for AWS Lambda (Python) Aug 24, 2023
@leandrodamascena leandrodamascena removed the triage Pending triage from maintainers label Aug 25, 2023
@leandrodamascena leandrodamascena added the need-customer-feedback Requires more customers feedback before making or revisiting a decision label Sep 25, 2023
@leandrodamascena leandrodamascena added the good first issue Good for newcomers label Aug 12, 2024
@anafalcao anafalcao moved this from Pending review to Backlog in Powertools for AWS Lambda (Python) Jan 23, 2025
@anafalcao anafalcao added help wanted Could use a second pair of eyes/hands metrics and removed need-customer-feedback Requires more customers feedback before making or revisiting a decision labels Jan 23, 2025
@anafalcao anafalcao self-assigned this Feb 5, 2025
@leandrodamascena
Copy link
Contributor Author

@anafalcao is working to add this support.

@leandrodamascena leandrodamascena moved this from Backlog to Working on it in Powertools for AWS Lambda (Python) Feb 6, 2025
@anafalcao anafalcao linked a pull request Feb 7, 2025 that will close this issue
7 tasks
@leandrodamascena leandrodamascena removed the help wanted Could use a second pair of eyes/hands label Feb 10, 2025
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Feb 11, 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 the pending-release Fix or implementation already in dev waiting to be released label Feb 11, 2025
Copy link
Contributor

This is now released under 3.6.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 11, 2025
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request good first issue Good for newcomers metrics
Projects
Status: Shipped
4 participants