Repository navigation
Conversation
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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.