Skip to content

fix(metrics): account for all dimensions in setDefaultDimensions() li…#5228

Merged
svozza merged 2 commits intoaws-powertools:mainfrom
vishwakt:fix/set-default-dimensions-limit-check
May 7, 2026
Merged

fix(metrics): account for all dimensions in setDefaultDimensions() li…#5228
svozza merged 2 commits intoaws-powertools:mainfrom
vishwakt:fix/set-default-dimensions-limit-check

Conversation

@vishwakt
Copy link
Copy Markdown
Contributor

@vishwakt vishwakt commented May 7, 2026

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 checked Object.keys(currentDefaultDimensions).length + Object.keys(newDimensions).length, completely ignoring regular dimensions added via addDimension() and dimension sets from addDimensions(). This allowed silently exceeding CloudWatch's 29-dimension limit, causing metrics to be dropped.

What changed

  • Metrics.ts: Replaced the narrow default-only count with getDimensionCount() (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:
    • Verifies setDefaultDimensions() throws when regular dimensions already fill the limit
    • Verifies overriding existing default keys doesn't trigger a false limit violation

Issue 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.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 7, 2026
Comment thread packages/metrics/tests/unit/dimensions.test.ts Outdated
…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
@vishwakt vishwakt force-pushed the fix/set-default-dimensions-limit-check branch from a6e96bd to 58a27b8 Compare May 7, 2026 14:20
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 7, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 7, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

@svozza svozza merged commit 54eb80a into aws-powertools:main May 7, 2026
36 checks passed
@svozza
Copy link
Copy Markdown
Contributor

svozza commented May 7, 2026

Thank you @vishwakt, merged!

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: setDefaultDimensions() ignores regular dimensions in limit check

2 participants