|
15 | 15 | convert_timestamp_to_emf_format, |
16 | 16 | extract_cloudwatch_metric_resolution_value, |
17 | 17 | extract_cloudwatch_metric_unit_value, |
| 18 | + is_metrics_disabled, |
18 | 19 | validate_emf_timestamp, |
19 | 20 | ) |
20 | 21 | from aws_lambda_powertools.metrics.provider.base import BaseProvider |
@@ -77,6 +78,7 @@ def __init__( |
77 | 78 | self.default_dimensions = default_dimensions or {} |
78 | 79 | self.namespace = resolve_env_var_choice(choice=namespace, env=os.getenv(constants.METRICS_NAMESPACE_ENV)) |
79 | 80 | self.service = resolve_env_var_choice(choice=service, env=os.getenv(constants.SERVICE_NAME_ENV)) |
| 81 | + |
80 | 82 | self.metadata_set = metadata_set if metadata_set is not None else {} |
81 | 83 | self.timestamp: int | None = None |
82 | 84 |
|
@@ -127,6 +129,7 @@ def add_metric( |
127 | 129 | MetricResolutionError |
128 | 130 | When metric resolution is not supported by CloudWatch |
129 | 131 | """ |
| 132 | + |
130 | 133 | if not isinstance(value, numbers.Number): |
131 | 134 | raise MetricValueError(f"{value} is not a valid number") |
132 | 135 |
|
@@ -268,6 +271,7 @@ def add_dimension(self, name: str, value: str) -> None: |
268 | 271 | value : str |
269 | 272 | Dimension value |
270 | 273 | """ |
| 274 | + |
271 | 275 | logger.debug(f"Adding dimension: {name}:{value}") |
272 | 276 | if len(self.dimension_set) == MAX_DIMENSIONS: |
273 | 277 | raise SchemaValidationError( |
@@ -374,7 +378,7 @@ def flush_metrics(self, raise_on_empty_metrics: bool = False) -> None: |
374 | 378 | "If application metrics should never be empty, consider using 'raise_on_empty_metrics'", |
375 | 379 | stacklevel=2, |
376 | 380 | ) |
377 | | - else: |
| 381 | + elif not is_metrics_disabled(): |
378 | 382 | logger.debug("Flushing existing metrics") |
379 | 383 | metrics = self.serialize_metric_set() |
380 | 384 | print(json.dumps(metrics, separators=(",", ":"))) |
|
0 commit comments