Skip to content

feat(metrics): add runtime validations for the metric name #7026

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

Conversation

sdangol
Copy link
Contributor

@sdangol sdangol commented Jul 23, 2025

Issue number: #7010

Summary

This PR adds runtime validation for the metric name. It ensures that the metric name meets the required constraints before they are added, providing better error handling and feedback to users. This was done to prevent potential issues that could have come up due to invalid metric name being passed to Cloudwatch.

Changes

User experience

Before this, for the users who were passing in an invalid metric name (empty string or a string of more than 255 characters), the metrics would get silently dropped. But, now the users will get an error.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sdangol sdangol requested a review from a team as a code owner July 23, 2025 10:32
@sdangol sdangol requested a review from anafalcao July 23, 2025 10:32
Copy link

boring-cyborg bot commented Jul 23, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 23, 2025
@leandrodamascena leandrodamascena changed the title improv(metrics): Added runtime validations for the metric name feat(metrics): add runtime validations for the metric name Jul 23, 2025
@leandrodamascena leandrodamascena linked an issue Jul 23, 2025 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added the feature New feature or functionality label Jul 23, 2025
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.24%. Comparing base (a73282d) to head (bf7639c).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
aws_lambda_powertools/metrics/base.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7026      +/-   ##
===========================================
- Coverage    96.25%   96.24%   -0.02%     
===========================================
  Files          275      275              
  Lines        12884    12896      +12     
  Branches       950      952       +2     
===========================================
+ Hits         12402    12412      +10     
- Misses         377      378       +1     
- Partials       105      106       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sdangol thanks a lot for submitting this PR!! I just left a small comment and we are good to merge.

Copy link

@leandrodamascena leandrodamascena self-requested a review July 23, 2025 12:57
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this and addressing the feedback @sdangol!

@leandrodamascena leandrodamascena merged commit dcd61f3 into aws-powertools:develop Jul 23, 2025
10 checks passed
Copy link

boring-cyborg bot commented Jul 23, 2025

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: Add runtime validation for the metric name
3 participants