fix(metrics): account for all dimensions in setDefaultDimensions() li…#5228
Merged
svozza merged 2 commits intoaws-powertools:mainfrom May 7, 2026
Merged
Conversation
svozza
reviewed
May 7, 2026
…mit check The setDefaultDimensions() method previously only checked default dimension count against the limit, ignoring regular dimensions added via addDimension() and dimension sets from addDimensions(). This allowed silently exceeding CloudWatch's 29-dimension limit. Now uses getDimensionCount() which correctly sums all dimension types (default + regular + dimension sets), and only counts genuinely new keys to avoid double-counting when overriding existing defaults. Closes aws-powertools#5206
a6e96bd to
58a27b8
Compare
|
svozza
approved these changes
May 7, 2026
Contributor
|
Thank you @vishwakt, merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Changes
Fixes the dimension limit check in
setDefaultDimensions()to account for all dimension types (default + regular + dimension sets), not just existing defaults.Previously,
setDefaultDimensions()only checkedObject.keys(currentDefaultDimensions).length + Object.keys(newDimensions).length, completely ignoring regular dimensions added viaaddDimension()and dimension sets fromaddDimensions(). This allowed silently exceeding CloudWatch's 29-dimension limit, causing metrics to be dropped.What changed
Metrics.ts: Replaced the narrow default-only count withgetDimensionCount()(which correctly sums all dimension types). Also filters for genuinely new keys to avoid double-counting when overriding existing defaults.dimensions.test.ts: Added two tests:setDefaultDimensions()throws when regular dimensions already fill the limitIssue number: Closes #5206
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.