String metric values are not rejected, but do not work.
bobtfish opened this issue · comments
I've found that it's possible to accidentally call putMetric
with a string value, and this value is saved and outputted to cloudwatch as a quoted string, which of course doesn't work as a metric.
The typescript code has type checking that putMetric
is called with a number, but this doesn't help if you're writing Javascript, and of course doesn't help at runtime.
It can be subtle and hard to spot what is going on, as if you accidentally push a numeric metric that is typed as a string, then it just ends up quoted in the generated JSON, which is hard to spot until it doesn't work, e.g. putMetric('someKey', '200')
.
The library should explicitly convert all values it's sent to Number()
so that if someone accidentally sends string values then they'll be dealt with correctly if they can be easily converted to numeric.