Skip to content

fix(metrics): clarify no-metrics user warning #1935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down