Skip to content

Commit 183f233

Browse files
authored
fix(metrics): clarify no-metrics user warning (#1935)
1 parent 75b6924 commit 183f233

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: aws_lambda_powertools/metrics/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ def decorate(event, context):
391391
self._add_cold_start_metric(context=context)
392392
finally:
393393
if not raise_on_empty_metrics and not self.metric_set:
394-
warnings.warn("No metrics to publish, skipping", stacklevel=2)
394+
warnings.warn(
395+
"No application metrics to publish. The cold-start metric may be published if enabled. "
396+
"If application metrics should never be empty, consider using 'raise_on_empty_metrics'",
397+
stacklevel=2,
398+
)
395399
else:
396400
metrics = self.serialize_metric_set()
397401
self.clear_metrics()

Diff for: tests/functional/test_metrics.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,10 @@ def lambda_handler(evt, context):
728728
warnings.simplefilter("default")
729729
lambda_handler({}, {})
730730
assert len(w) == 1
731-
assert str(w[-1].message) == "No metrics to publish, skipping"
731+
assert str(w[-1].message) == (
732+
"No application metrics to publish. The cold-start metric may be published if enabled. "
733+
"If application metrics should never be empty, consider using 'raise_on_empty_metrics'"
734+
)
732735

733736

734737
def test_log_metrics_with_implicit_dimensions_called_twice(capsys, metric, namespace, service):

0 commit comments

Comments
 (0)