Skip to content

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]

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

[Metrics(Namespace = "dotnet-powertools-test", Service = "testService")]
public void AddMultipleDimensionsInSameSet()
{
    // Add multiple dimensions at once
    Metrics.AddDimensions(
        ("Environment", "test"), 
        ("Region", "us-west-2")
    );

    Metrics.AddMetric("TestMetric", 1.0, MetricUnit.Count);
}

Output

{
  "_aws": {
    "Timestamp": 1747649334042,
    "CloudWatchMetrics": [
      {
        "Namespace": "dotnet-powertools-test",
        "Metrics": [
          {
            "Name": "TestMetric",
            "Unit": "Count"
          }
        ],
        "Dimensions": [
          [
            "Service",
            "Environment",
            "Region"
          ]
        ]
      }
    ]
  },
  "Service": "testService",
  "Environment": "test",
  "Region": "us-west-2",
  "TestMetric": 1
}

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 77.28%. Comparing base (b445d3f) to head (72d35e8).
Report is 7 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    77.24%   77.28%   +0.03%     
===========================================
  Files          272      272              
  Lines        10812    10875      +63     
  Branches      1264     1278      +14     
===========================================
+ Hits          8352     8405      +53     
- Misses        2047     2054       +7     
- Partials       413      416       +3     

☔ 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.

Copy link

Copy link

sonarqubecloud bot commented Jul 8, 2025

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Amazing job @hjgraca!

@hjgraca hjgraca merged commit fa2243e into develop Jul 8, 2025
10 checks passed
@hjgraca hjgraca deleted the feature/metrics-multiple-dimensions branch July 8, 2025 09:44
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
2 participants