Skip to content

chore: add support for multiple dimensions #884

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented May 15, 2025

Please provide the issue number

Issue number: #845

Summary

Changes

adding support for multiple dimensions in a single call, updating dimension validation and management logic, and introducing new unit tests to ensure robustness.

Enhancements to Dimension Handling:

  • Added a new AddDimensions method to support adding multiple dimensions at once, with validation for non-null keys and values (libraries/src/AWS.Lambda.Powertools.Metrics/IMetrics.cs, libraries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs, libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricDirective.cs). [1] [2] [3]
  • Updated logic to ensure all dimensions are added to the same set when possible, preventing redundant dimension keys and enforcing a maximum limit (libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricDirective.cs). [1] [2]

API Improvements:

  • Introduced a static SetService method for setting the service name and a static AddDimensions method for adding dimensions globally (libraries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs). [1] [2]
  • Added a new AddDimensionSet method to handle lists of dimensions, ensuring they are treated as cohesive units (libraries/src/AWS.Lambda.Powertools.Metrics/Model/Metadata.cs, libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricsContext.cs). [1] [2]

Updates to Tests:

  • Expanded test coverage with new unit tests for AddDimensions, verifying behaviors such as overwriting existing dimensions, handling empty or invalid inputs, and including default dimensions (libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/EMFValidationTests.cs).
  • Adjusted the test for the maximum dimension limit to reflect the updated threshold of 29 dimensions (libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/EMFValidationTests.cs).

Refactoring and Bug Fixes:

  • Refactored the ExpandAllDimensionSets method to ensure the last value for duplicate keys is used, aligning with expected behavior (libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricDirective.cs).
  • Fixed an issue where dimension keys were not properly validated before being added to the Dimensions list (libraries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs).

These updates enhance the flexibility and reliability of the Metrics library, making it easier to manage and validate dimensions in AWS Lambda applications.

User experience

// Add multiple dimensions
Metrics.AddDimensions(
    ("dimension1", "1"),
    ("dimension2", "2")
);

Checklist

Please leave checklist items unchecked if they do not apply to your change.

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.

@boring-cyborg boring-cyborg bot added area/metrics Core metrics utility tests labels May 15, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 15, 2025
@hjgraca hjgraca linked an issue May 15, 2025 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added the internal Maintenance changes label May 15, 2025
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 86.36364% with 12 lines in your changes missing coverage. Please review.

Project coverage is 76.58%. Comparing base (4c8cec9) to head (8331132).
Report is 10 commits behind head on develop.

Files with missing lines Patch % Lines
...Lambda.Powertools.Metrics/Model/MetricDirective.cs 80.00% 8 Missing and 3 partials ⚠️
...aries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs 96.42% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #884   +/-   ##
========================================
  Coverage    76.57%   76.58%           
========================================
  Files          248      248           
  Lines         9696     9759   +63     
  Branches      1071     1085   +14     
========================================
+ Hits          7425     7474   +49     
- Misses        1933     1942    +9     
- Partials       338      343    +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/metrics Core metrics utility internal Maintenance changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add multiple dimensets to the same Metrics instance
1 participant