Skip to content

fix(metrics): skip non-finite metric values with a warning - #5963

Merged
dreamorosi merged 1 commit into
aws-powertools:mainfrom
anishmehta24:fix/metrics-skip-non-finite-values
Nov 13, 2026
Merged

dreamorosi merged 1 commit into
aws-powertools:mainfrom
anishmehta24:fix/metrics-skip-non-finite-values

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

Summary

NaN, Infinity and -Infinity pass isNumber, so storeMetric stored them and JSON.stringify wrote them as null in the EMF line. As agreed in #5961, storeMetric now warns and skips the value, the same approach as aws-powertools/powertools-lambda-python#8797.

Changes

  • storeMetric returns without storing anything when !Number.isFinite(value), right after the isNumber check, and logs a warning with the metric name and the value
  • Unit tests for NaN, Infinity and -Infinity check the warning and that the EMF output only has the other metric from the same flush
  • Unit test for a non-finite value added to a metric that already has values (ok is emitted as [1, 2])

Issue number: closes #5961


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.

NaN, Infinity and -Infinity pass isNumber, so storeMetric stored them
and JSON.stringify wrote them as null in the EMF line. storeMetric now
logs a warning naming the metric and the value, and returns without
storing it.

@dreamorosi dreamorosi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for fixing this!

@dreamorosi
dreamorosi merged commit fcf3bd4 into aws-powertools:main Nov 13, 2026
45 checks passed
@powertools-for-aws-oss-automation

Copy link
Copy Markdown

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

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Metrics serializes a NaN or infinite metric value as null in the EMF line

2 participants