Closed
Description
Expected Behaviour
If I set a default dimension, e.g. type
with the value meeting
, and then set through singleMetric with the same dimension name set to another value, the output to CloudWatch contains twice the dimension type
. This is incorrect in my understanding.
Current Behaviour
Code snippet
import {Metrics, MetricUnits} from "@aws-lambda-powertools/metrics";
const metrics = new Metrics({
namespace: 'testing',
serviceName: 'serviceA',
});
export const handler = (event, handler) => {
metrics.setDefaultDimensions({ type: "meeting" });
const singleMetric = metrics.singleMetric();
singleMetric.addDimension("type", "a");
singleMetric.addMetric("hello", MetricUnits.Count, 1);
metrics.publishStoredMetrics();
};
Output:
{"_aws":{"Timestamp":1698769257078,"CloudWatchMetrics":[{"Namespace":"testing","Dimensions":[["service","type","type"]],"Metrics":[{"Name":"hello","Unit":"Count"}]}]},"service":"serviceA","type":"a","hello":1}
The Dimensions
field contains type
twice, which should be once in my understanding.
Steps to Reproduce
Run code snippet below and watch output.
Possible Solution
When writing the dimension you could use new Set
to ensure the array does not contain duplicates.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
18.x
Packaging format used
npm
Execution logs
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped