Repository navigation
fix(metrics): respect POWERTOOLS_METRICS_DISABLED in every emission path - #8668
leandrodamascena merged 2 commits into
Conversation
|
Hi @soujasK, I saw you closed this one. No problem, I just want to understand what you'd prefer. The bug is real and triaged for 3.40.0, and I already worked on it on my side. Do you want to reopen so I review your PR, or should I open a new one myself? Either way is fine, just let me know. |
|
Reopening this. I closed it by mistake. I need a bit more time to test and validate it properly, so I'll update here once that's done. |
|
Thanks @soujasK, same story as #8664, this missed 3.40.0 and goes in 3.41.0. The change is right and the six tests cover every path. It overlaps with #8797, which touches the same lines in |
# Conflicts: # aws_lambda_powertools/metrics/base.py
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @soujasK! Reviewed on top of develop with #8797 in: every emission path now checks the flag, including the cold start metric and the Datadog submit, and the six tests cover them. I merged develop into your branch to clear the one-line overlap with #8797, nothing else changed. Goes out in 3.41.0, you'll be in the release notes.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8668 +/- ##
========================================
Coverage 97.17% 97.17%
========================================
Files 323 323
Lines 16629 16630 +1
Branches 1509 1510 +1
========================================
+ Hits 16160 16161 +1
Misses 328 328
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Issue number: closes #8667
Summary
Changes
POWERTOOLS_METRICS_DISABLED(added in #6046 for both providers) was only checked inflush_metrics(). This adds the sameis_metrics_disabled()check to the other emission paths:single_metric(metrics/base.py): only prints when metrics aren't disabled. This also covers the CloudWatchColdStartmetric, which is emitted throughsingle_metric. It also no longer prints anullline when thewithbody raises (metric_setis stillNoneat that point); the exception still propagates.AmazonCloudWatchEMFProvider.add_metric: the automatic flush at 100 metrics / 100 values doesn't print when disabled. The metric set is still cleared, as before.DatadogProvider.flush_metrics: doesn't submit throughdatadog_lambda'slambda_metricwhen disabled.Since
is_metrics_disabled()also returns true forPOWERTOOLS_DEV=truewithoutPOWERTOOLS_METRICS_DISABLED,single_metricand the cold start metric are now silent in dev mode too, the same asflush_metrics()already was.The legacy
MetricManagerinmetrics/base.pyisn't changed: it's only reached throughSingleMetric, which can't hit its auto-flush.Tests: one per path (
single_metric, cold start vialog_metrics, the 100-metric auto-flush, Datadoglambda_metricmocked), aPOWERTOOLS_DEVcase forsingle_metric, and thenullline when the body raises. The five path tests fail without the change.tests/functional/metricspasses; on Linux (Python 3.12) ruff, mypy, ty, bandit and xenon pass. Runningtests/unit,tests/functional/metricsandtests/functional/batchtogether on Linux,test_datadog_write_to_log_with_env_variablefails the same way ondevelopwithout this change (it passes on its own), so it looks like existing cross-test state.User experience
Before: with metrics disabled, the
ColdStartmetric,single_metric, the 100-metric auto-flush and Datadog extension submissions were still emitted (and EMF lines are ingested by CloudWatch).After: nothing is emitted when metrics are disabled.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.