Skip to content

Commit e542d69

Browse files
feat(metrics): update max user-defined dimensions from 9 to 29 (#1417)
Co-authored-by: heitorlessa <[email protected]>
1 parent c679f51 commit e542d69

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Diff for: aws_lambda_powertools/metrics/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
logger = logging.getLogger(__name__)
1515

1616
MAX_METRICS = 100
17-
MAX_DIMENSIONS = 9
17+
MAX_DIMENSIONS = 29
1818

1919

2020
class MetricUnit(Enum):
@@ -233,7 +233,7 @@ def add_dimension(self, name: str, value: str) -> None:
233233
Dimension value
234234
"""
235235
logger.debug(f"Adding dimension: {name}:{value}")
236-
if len(self.dimension_set) == 9:
236+
if len(self.dimension_set) == MAX_DIMENSIONS:
237237
raise SchemaValidationError(
238238
f"Maximum number of dimensions exceeded ({MAX_DIMENSIONS}): Unable to add dimension {name}."
239239
)

Diff for: docs/core/metrics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ This decorator also **validates**, **serializes**, and **flushes** all your metr
133133
???+ tip "Tip: Metric validation"
134134
If metrics are provided, and any of the following criteria are not met, **`SchemaValidationError`** exception will be raised:
135135

136-
* Maximum of 8 user-defined dimensions
136+
* Maximum of 29 user-defined dimensions
137137
* Namespace is set, and no more than one
138138
* Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html)
139139

Diff for: tests/functional/test_metrics.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from aws_lambda_powertools import Metrics, single_metric
99
from aws_lambda_powertools.metrics import MetricUnit, MetricUnitError, MetricValueError, SchemaValidationError
1010
from aws_lambda_powertools.metrics import metrics as metrics_global
11-
from aws_lambda_powertools.metrics.base import MetricManager
11+
from aws_lambda_powertools.metrics.base import MAX_DIMENSIONS, MetricManager
1212

1313

1414
@pytest.fixture(scope="function", autouse=True)
@@ -320,8 +320,8 @@ def test_schema_no_metrics(service, namespace):
320320

321321

322322
def test_exceed_number_of_dimensions(metric, namespace):
323-
# GIVEN we have more dimensions than CloudWatch supports
324-
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(11)]
323+
# GIVEN we have more dimensions than CloudWatch supports (N+1)
324+
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS + 1)]
325325

326326
# WHEN we attempt to serialize them into a valid EMF object
327327
# THEN it should fail validation and raise SchemaValidationError
@@ -332,9 +332,9 @@ def test_exceed_number_of_dimensions(metric, namespace):
332332

333333

334334
def test_exceed_number_of_dimensions_with_service(metric, namespace, monkeypatch):
335-
# GIVEN we have service set and add more dimensions than CloudWatch supports (N+1)
335+
# GIVEN we have service set and add more dimensions than CloudWatch supports (N-1)
336336
monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service")
337-
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)]
337+
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS)]
338338

339339
# WHEN we attempt to serialize them into a valid EMF object
340340
# THEN it should fail validation and raise SchemaValidationError

0 commit comments

Comments
 (0)