-
Notifications
You must be signed in to change notification settings - Fork 421
Feature request: Add A method to manually flush metrics #2109
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @JeffDGAWS! Thank you for opening this issue and helping us understand the special use cases where Powertools can help. I'm adding this issue to our backlog to keep our eyes on it and start a discussion on how we can best do this. |
Hi Leandro, in the TS version we expose a method to do this which is called I'm just sharing this in case you might want to consider using a similar name (with snake_case of course), and to share the implementation & docs. |
Hello @dreamorosi! Thanks so much for sharing the TS implementation and documentation. You make things easy!! 🚀 |
Working on this today |
|
This is now released under 2.15.0 version! |
Use case
When not running within a standard Lambda handler (in my case, running within the Lambda Web Adapter), the @log_metrics decorator does not function. It is expecting the standard Lambda event,context parameters to be passed in.
Would be helpful to have a function that you could manually call before returning from a function to flush the metrics out to stdout so that they get logged.
Solution/User Experience
Based on the decorator code, I built the is as a function in my code that flushes the metrics, but would be more resilient if it were in the class.
def flush_metrics(a=None): m = metrics.serialize_metric_set() metrics.clear_metrics() print(json.dumps(m, separators=(",", ":"))) return a
Note the parameter (a) there is not used in the function at all, and is simply returned to the caller. This was done so that I could wrap the "flush" and return into one line such as:
return flush_metrics({"message": f"Count: {count}"})
Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: