Closed
Description
Expected Behavior
When adding a dimension to my metrics, I should get a warning if the dimension value is invalid aka an empty string (""
) or undefined
/null
, and the dimension should not be added to the EMF blobs emitted by the utility.
Current Behavior
Currently the utility doesn't validate the input but only enforces types. In practice this means it's unlikely customers can pass undefined
or null
unless they're suppressing the warning, but can pass an empty string and generate an EMF blob that will have the invalid dimension.
Code snippet
import { Metrics } from '@aws-lambda-powertools/metrics';
const metrics = new Metrics();
export const handler = async () => {
metrics.addDimension('FunctionName', '');
metrics.addMetric('CustomMetric', 'Count', 1);
metrics.publishStoredMetrics();
};
Steps to Reproduce
- Run the code above
- Observe that the EMF blob emitted has an empty dimension
- Verify that the processed metric in CloudWatch does not include any dimensions
Possible Solution
We should: 1/ validate the input when adding a dimension, 2/ emit a warning if invalid, and 3/ don't add the dimension to the EMF blob
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
{
"_aws": {
"Timestamp": 1731086204245,
"CloudWatchMetrics": [
{
"Namespace": "default_namespace",
"Dimensions": [
[
"service",
"FunctionName"
]
],
"Metrics": [
{
"Name": "CustomMetric",
"Unit": "Count"
}
]
}
]
},
"service": "service_undefined",
"FunctionName": "",
"CustomMetric": 1
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped