Skip to content

Bug: Override of default dimension with new value results into wrong CloudWatch dimension output #1773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jimmy89 opened this issue Oct 31, 2023 · 4 comments · Fixed by #1780
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped metrics This item relates to the Metrics Utility

Comments

@Jimmy89
Copy link

Jimmy89 commented Oct 31, 2023

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

@Jimmy89 Jimmy89 added triage This item has not been triaged by a maintainer, please wait bug Something isn't working labels Oct 31, 2023
Copy link

boring-cyborg bot commented Oct 31, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@dreamorosi
Copy link
Contributor

Hi @Jimmy89 thank you for taking the time to report the issue.

I was able to reproduce the bug and indeed the dimension gets duplicated.

I have created a sample minimal example which can be found in this repo: https://github.com/dreamorosi/repro-1773

I will add this to our backlog so we can fix it.

@dreamorosi dreamorosi added metrics This item relates to the Metrics Utility confirmed The scope is clear, ready for implementation and removed triage This item has not been triaged by a maintainer, please wait labels Nov 2, 2023
@am29d am29d self-assigned this Nov 2, 2023
@dreamorosi dreamorosi moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Nov 2, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Nov 2, 2023
Copy link
Contributor

github-actions bot commented Nov 2, 2023

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Nov 2, 2023
Copy link
Contributor

github-actions bot commented Nov 3, 2023

This is now released under v1.14.2 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Nov 3, 2023
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped metrics This item relates to the Metrics Utility
Projects
Development

Successfully merging a pull request may close this issue.

3 participants