diff --git a/aws_lambda_powertools/metrics/base.py b/aws_lambda_powertools/metrics/base.py index fde191a8d94..29a780d0af1 100644 --- a/aws_lambda_powertools/metrics/base.py +++ b/aws_lambda_powertools/metrics/base.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) MAX_METRICS = 100 -MAX_DIMENSIONS = 9 +MAX_DIMENSIONS = 29 class MetricUnit(Enum): @@ -233,7 +233,7 @@ def add_dimension(self, name: str, value: str) -> None: Dimension value """ logger.debug(f"Adding dimension: {name}:{value}") - if len(self.dimension_set) == 9: + if len(self.dimension_set) == MAX_DIMENSIONS: raise SchemaValidationError( f"Maximum number of dimensions exceeded ({MAX_DIMENSIONS}): Unable to add dimension {name}." ) diff --git a/docs/core/metrics.md b/docs/core/metrics.md index 843e35b7eb8..45e3ce1a4c0 100644 --- a/docs/core/metrics.md +++ b/docs/core/metrics.md @@ -133,7 +133,7 @@ This decorator also **validates**, **serializes**, and **flushes** all your metr ???+ tip "Tip: Metric validation" If metrics are provided, and any of the following criteria are not met, **`SchemaValidationError`** exception will be raised: - * Maximum of 8 user-defined dimensions + * Maximum of 29 user-defined dimensions * Namespace is set, and no more than one * Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html) diff --git a/tests/functional/test_metrics.py b/tests/functional/test_metrics.py index 6cf33a3eaa4..1a52d84d4fe 100644 --- a/tests/functional/test_metrics.py +++ b/tests/functional/test_metrics.py @@ -8,7 +8,7 @@ from aws_lambda_powertools import Metrics, single_metric from aws_lambda_powertools.metrics import MetricUnit, MetricUnitError, MetricValueError, SchemaValidationError from aws_lambda_powertools.metrics import metrics as metrics_global -from aws_lambda_powertools.metrics.base import MetricManager +from aws_lambda_powertools.metrics.base import MAX_DIMENSIONS, MetricManager @pytest.fixture(scope="function", autouse=True) @@ -320,8 +320,8 @@ def test_schema_no_metrics(service, namespace): def test_exceed_number_of_dimensions(metric, namespace): - # GIVEN we have more dimensions than CloudWatch supports - dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(11)] + # GIVEN we have more dimensions than CloudWatch supports (N+1) + dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS + 1)] # WHEN we attempt to serialize them into a valid EMF object # THEN it should fail validation and raise SchemaValidationError @@ -332,9 +332,9 @@ def test_exceed_number_of_dimensions(metric, namespace): def test_exceed_number_of_dimensions_with_service(metric, namespace, monkeypatch): - # GIVEN we have service set and add more dimensions than CloudWatch supports (N+1) + # GIVEN we have service set and add more dimensions than CloudWatch supports (N-1) monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service") - dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)] + dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS)] # WHEN we attempt to serialize them into a valid EMF object # THEN it should fail validation and raise SchemaValidationError