Skip to content

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

Closed
1 of 2 tasks
JeffDGAWS opened this issue Apr 11, 2023 · 7 comments · Fixed by #2171
Closed
1 of 2 tasks

Feature request: Add A method to manually flush metrics #2109

JeffDGAWS opened this issue Apr 11, 2023 · 7 comments · Fixed by #2171
Assignees
Labels

Comments

@JeffDGAWS
Copy link

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

@JeffDGAWS JeffDGAWS added feature-request feature request triage Pending triage from maintainers labels Apr 11, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 11, 2023

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

@leandrodamascena
Copy link
Contributor

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.

@dreamorosi
Copy link
Contributor

Hi Leandro, in the TS version we expose a method to do this which is called publishStoredMetrics().

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.

@leandrodamascena
Copy link
Contributor

Hello @dreamorosi! Thanks so much for sharing the TS implementation and documentation. You make things easy!! 🚀

@rubenfonseca
Copy link
Contributor

Working on this today

@github-actions
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 Apr 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

This is now released under 2.15.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants