Skip to content

Conversation

jotafeldmann
Copy link

@jotafeldmann jotafeldmann commented Oct 2, 2025

Addressing issue #7467

Issue number: closes #7467

Summary

Align flush_metrics behavior with the raise_on_empty_metrics documentation.

When raise_on_empty_metrics=False, no exception should be raised regardless of whether metrics exist.

Changes

  • Simplified the conditional logic in flush_metrics from if not raise_on_empty_metrics and not self.metric_set: to if not raise_on_empty_metrics:

User experience

Before:

Even when raise_on_empty_metrics=False, the code still considered the presence of metrics and could raise exceptions inconsistently.

After:

When raise_on_empty_metrics=False, no exception is raised regardless of metric set state, which is consistent with the documented intent.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…65671f9e2077eac36fd480b3814d7a9b978/aws_lambda_powertools/metrics/provider/cloudwatch_emf/cloudwatch.py#L383

Addressing issue aws-powertools#7467

Signed-off-by: Jota Feldmann <[email protected]>
@jotafeldmann jotafeldmann requested a review from a team as a code owner October 2, 2025 22:56
@jotafeldmann jotafeldmann requested a review from anafalcao October 2, 2025 22:56
Copy link

boring-cyborg bot commented Oct 2, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 2, 2025
@boring-cyborg boring-cyborg bot added the metrics label Oct 2, 2025
@jotafeldmann jotafeldmann changed the title Fix: align flush_metrics behavior with raise_on_empty_metrics documentation fix(metrics): align flush_metrics behavior with raise_on_empty_metrics documentation Oct 2, 2025
@github-actions github-actions bot added the bug Something isn't working label Oct 6, 2025
Copy link

sonarqubecloud bot commented Oct 6, 2025

@leandrodamascena
Copy link
Contributor

leandrodamascena commented Oct 6, 2025

This PR review is paused until we clarify this: #7467 (comment)

@leandrodamascena leandrodamascena added the on-hold This item is on-hold and will be revisited in the future label Oct 6, 2025
@leandrodamascena leandrodamascena requested review from leandrodamascena and removed request for anafalcao October 6, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics on-hold This item is on-hold and will be revisited in the future size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior of flush_metrics with raise_on_empty_metrics parameter
2 participants