Skip to content

improv(metrics): Added runtime validations for the metrics utility functions #4181

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

Merged

Conversation

sdangol
Copy link
Contributor

@sdangol sdangol commented Jul 16, 2025

Summary

This PR adds runtime validations for the metrics utility functions. It ensures that metrics and dimensions meet 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 data being passed to Cloudwatch.

Changes

  • Added runtime validation for the following:
  • Added a new utility function isStringUndefinedNullEmpty in the commons package to validate string inputs
  • Added constants for metric name length constraints (MIN_METRIC_NAME_LENGTH and MAX_METRIC_NAME_LENGTH)
  • Added tests for the new validations

Issue number:
#4135


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.

@boring-cyborg boring-cyborg bot added commons This item relates to the Commons Utility metrics This item relates to the Metrics Utility tests PRs that add or change tests labels Jul 16, 2025
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jul 16, 2025
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Great work on this PR Swopnil!

Left 3 minor comments but other than it's almost good to go!

Regarding the discussion we were having about other Powertools for AWS runtimes in the linked issue, did you see if they are implementing the same check you brought up?

@dreamorosi dreamorosi linked an issue Jul 16, 2025 that may be closed by this pull request
2 tasks
@sdangol sdangol force-pushed the improv/metrics-runtime-validations branch from 49d3454 to f673c07 Compare July 16, 2025 17:02
@sdangol
Copy link
Contributor Author

sdangol commented Jul 16, 2025

Regarding the discussion we were having about other Powertools for AWS runtimes in the linked issue, did you see if they are implementing the same check you brought up?

Yes, I looked into the Python and .NET and the metric name constraint validation is missing. I tested the python version and the metrics were getting silently dropped there as well. I will create the issues for this in their repos.

@sdangol sdangol requested a review from dreamorosi July 16, 2025 17:16
@sdangol sdangol force-pushed the improv/metrics-runtime-validations branch 2 times, most recently from 5affe3b to 91b7682 Compare July 16, 2025 20:34
@sdangol sdangol force-pushed the improv/metrics-runtime-validations branch from 91b7682 to 4ed8433 Compare July 16, 2025 20:36
Copy link

@dreamorosi dreamorosi merged commit 4226058 into aws-powertools:main Jul 16, 2025
46 checks passed
@dreamorosi
Copy link
Contributor

Thank you for the work on this PR @swopnildangol - great work and turnaround :)

Copy link
Contributor

@aws-powertools/lambda-typescript No related issues found. Please ensure 'pending-release' label is applied before releasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons This item relates to the Commons Utility metrics This item relates to the Metrics Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: improve runtime validations in Metrics utility
2 participants