-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Summary
While adding the runtime validations for the Typescript implementation of AWS Powertools Lambda Metrics, I noticed an issue when a metric name with either an empty string or with a string longer than 255 characters was used, the metrics were not being written. If this validation is not done in the runtime, the metrics will get dropped by Cloudwatch.
Why is this needed?
As per the MetricDatum API Reference, the Metric Name has a length constraint of a minimum of length 1 and a maximum of length 255. There is a validation for the metric name not being empty which satisfies the minimun length constraint. But, there validation for the metric name when it is longer than 255 characters is missing on the AddMetric
function in the Metrics
utility. If we pass ina string with more than 255 characters currently as the metric name, those metrics are being dropped by Cloudwatch silently.
Which area does this relate to?
Metrics
Solution
- Runtime Metric Name Type Validation
The Typescript implementation includes a runtime check to ensure that metric name is a string and the length constraint is satisfied. If an invalid value is passed, it raises a RangeError.
Typescript code:
if (!isString(name)) throw new Error(${name} is not a valid string
);
if (
name.length < MIN_METRIC_NAME_LENGTH ||
name.length > MAX_METRIC_NAME_LENGTH
)
throw new RangeError(
The metric name should be between ${MIN_METRIC_NAME_LENGTH} and ${MAX_METRIC_NAME_LENGTH} characters
);
Acknowledgment
- This request meets Powertools for AWS Lambda (.NET) Tenets
Metadata
Metadata
Assignees
Labels
Type
Projects
Status