Skip to content
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

feat(metrics): warn when overwriting dimension #5653

Merged
merged 3 commits into from
Nov 26, 2024

Conversation

anafalcao
Copy link
Collaborator

Issue number:
#5638

Summary

Changes

Please provide a summary of what's being changed

When using dimensions with the Metrics class, the default behavior is to overwrite existing dimensions if a new dimension with the same name/key is added. To improve troubleshooting and prevent silent data loss, we've implemented a warning system that alerts users when dimension overwriting occurs.

User experience

Please share what the user experience looks like before and after this change

from aws_lambda_powertools.metrics import Metrics

metrics = Metrics(namespace="MyApp")

metrics.add_dimension(name="test", value="foo")
metrics.add_dimension(name="test", value="bar")  # "bar" replaces "foo"

# A warning is now issued:
# UserWarning: Dimension 'test' has already been added. The previous value will be overwritten.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@anafalcao anafalcao requested a review from a team as a code owner November 26, 2024 13:08
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 26, 2024
@anafalcao anafalcao marked this pull request as draft November 26, 2024 13:09
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.17%. Comparing base (fb245cc) to head (f7be51b).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5653   +/-   ##
========================================
  Coverage    96.17%   96.17%           
========================================
  Files          231      231           
  Lines        10916    10920    +4     
  Branches      2018     2019    +1     
========================================
+ Hits         10498    10502    +4     
  Misses         329      329           
  Partials        89       89           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anafalcao anafalcao marked this pull request as ready for review November 26, 2024 15:13
@anafalcao anafalcao changed the title feat(metrics): warn when overwriting dimension - WIP feat(metrics): warn when overwriting dimension Nov 26, 2024
@github-actions github-actions bot added the feature New feature or functionality label Nov 26, 2024
@anafalcao anafalcao requested a review from dreamorosi November 26, 2024 15:28
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for implementing this quickly!

@anafalcao anafalcao merged commit 8648078 into aws-powertools:develop Nov 26, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Warn users when adding multiple values to dimension before flushing
2 participants