From a214384686ad4a239407e95e235e3f24eee605ac Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Thu, 16 Feb 2023 14:43:11 +0100 Subject: [PATCH] fix(metrics): clarify no-metrics user warning --- aws_lambda_powertools/metrics/base.py | 6 +++++- tests/functional/test_metrics.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/aws_lambda_powertools/metrics/base.py b/aws_lambda_powertools/metrics/base.py index 89a6dc6f4cd..b96356192ab 100644 --- a/aws_lambda_powertools/metrics/base.py +++ b/aws_lambda_powertools/metrics/base.py @@ -391,7 +391,11 @@ def decorate(event, context): self._add_cold_start_metric(context=context) finally: if not raise_on_empty_metrics and not self.metric_set: - warnings.warn("No metrics to publish, skipping", stacklevel=2) + warnings.warn( + "No application metrics to publish. The cold-start metric may be published if enabled. " + "If application metrics should never be empty, consider using 'raise_on_empty_metrics'", + stacklevel=2, + ) else: metrics = self.serialize_metric_set() self.clear_metrics() diff --git a/tests/functional/test_metrics.py b/tests/functional/test_metrics.py index 2a53b42cd16..c0c41f3bf88 100644 --- a/tests/functional/test_metrics.py +++ b/tests/functional/test_metrics.py @@ -728,7 +728,10 @@ def lambda_handler(evt, context): warnings.simplefilter("default") lambda_handler({}, {}) assert len(w) == 1 - assert str(w[-1].message) == "No metrics to publish, skipping" + assert str(w[-1].message) == ( + "No application metrics to publish. The cold-start metric may be published if enabled. " + "If application metrics should never be empty, consider using 'raise_on_empty_metrics'" + ) def test_log_metrics_with_implicit_dimensions_called_twice(capsys, metric, namespace, service):