Skip to content

fix(metrics): reset custom timestamp after flushing metrics - #8903

Open
ibrhmyi wants to merge 1 commit into
aws-powertools:developfrom
ibrhmyi:fix/metrics-reset-timestamp-after-flush
Open

ibrhmyi wants to merge 1 commit into
aws-powertools:developfrom
ibrhmyi:fix/metrics-reset-timestamp-after-flush

Conversation

@ibrhmyi

@ibrhmyi ibrhmyi commented Nov 24, 2026 •

Copy link
Copy Markdown

Issue number: closes #8902

Summary

Changes

clear_metrics() now also resets the timestamp set via set_timestamp(), together with the rest of the metric state (one line in cloudwatch.py), plus a regression test.

User experience

Before: on a warm Lambda, a timestamp set in the first invocation stayed in place after clear_metrics()/flush, so every later invocation emitted the first invocation's timestamp.
After: each invocation starts without a custom timestamp unless it calls set_timestamp() again.

Verification

  • New test in tests/functional/metrics/ (public API); it fails on develop without the fix and passes with it.
  • pytest tests/functional/metrics: 169 passed, 1 skipped.
  • ruff check and ruff format --check: clean.

An AI assistant (Claude Code) helped write this change; I reviewed it and ran the tests myself.


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.

clear_metrics() left the timestamp set by set_timestamp() in place, so on a warm Lambda every later invocation reused the first invocation's timestamp. Reset it together with the rest of the metric state.

closes aws-powertools#8902
@ibrhmyi
ibrhmyi requested a review from a team as a code owner November 24, 2026 21:04
@ibrhmyi
ibrhmyi requested a review from svozza November 24, 2026 21:04
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 24, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metrics size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Metrics reuses a custom timestamp on the next warm Lambda invocation

1 participant