Skip to content

fix(metrics): align addDimensions boundary check#5209

Open
toby-bridges wants to merge 1 commit intoaws-powertools:mainfrom
toby-bridges:fix/issue-5204-bug-adddimensions-is-one-dimension-more-
Open

fix(metrics): align addDimensions boundary check#5209
toby-bridges wants to merge 1 commit intoaws-powertools:mainfrom
toby-bridges:fix/issue-5204-bug-adddimensions-is-one-dimension-more-

Conversation

@toby-bridges
Copy link
Copy Markdown

Summary

Changes

  • allow addDimensions() to accept a dimension set when the final total reaches MAX_DIMENSION_COUNT, matching the existing addDimension() boundary behavior
  • add a regression test for the exact 28 + 1 case from the issue so the two APIs stay aligned

Issue number: closes #5204

Validation

  • npx @biomejs/biome check packages/metrics/src/Metrics.ts packages/metrics/tests/unit/dimensions.test.ts
  • npx vitest --run packages/metrics/tests/unit/dimensions.test.ts -t "allows adding a dimension set when it reaches the limit exactly"
  • npm run build --workspace @aws-lambda-powertools/commons --workspace @aws-lambda-powertools/testing-utils --workspace @aws-lambda-powertools/metrics
  • npm test --workspace @aws-lambda-powertools/metrics

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 24, 2026

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@sonarqubecloud
Copy link
Copy Markdown

@svozza
Copy link
Copy Markdown
Contributor

svozza commented Apr 24, 2026

Apologies, I made a mistake in the proposed solution section of the issue. I think we should mirror the behaviour of addDimension and allow 29 dimensions. This means that we stay within the 30 dimension limit CloudWatch allows, 29 free dimensions + the default service dimension.

);
});

it('allows adding a dimension set when it reaches the limit exactly', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a test that calls both addDimension and addDimesions to ensure they behave in the same way. E.g., add 29 dimensions and then check that we throw when we try to add another dimension using both APIs.

@svozza
Copy link
Copy Markdown
Contributor

svozza commented Apr 29, 2026

Hi @toby-bridges, do you need any help with this PR, e.g., clarifications on the comments I made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: addDimensions() is one dimension more restrictive than addDimension() at the boundary

2 participants