Skip to content

Conversation

@hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Dec 12, 2025

Please provide the issue number

Issue number: #1079

Summary

Changes

This pull request introduces thread-safe handling for metrics contexts, enabling correct behavior when Lambda functions process multiple concurrent requests (e.g., when AWS_LAMBDA_MAX_CONCURRENCY > 1). It also adds a new test project for concurrency testing and updates internal visibility accordingly.

Thread safety and concurrency improvements:

  • Refactored Metrics in Metrics.cs to use a ConcurrentDictionary for per-thread metrics context storage. Shared configuration (namespace, service, default dimensions) is now kept in static fields, with thread-safe updates and propagation to all contexts. The singleton instance is now thread-safe, and all metrics operations (add, flush, set namespace/dimensions, etc.) operate on the current thread's context. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

Other changes:

  • Updated the XRayTraceId property in PowertoolsConfigurations.cs to use LambdaTraceProvider.CurrentTraceId for improved trace ID retrieval.
  • Added missing using directives for required namespaces. [1] [2] [3]

User experience

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

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.

…orage.

Add new TraceId capture from Lambda.Core to PowertoolsConfigurations.cs
add new concurrency tests
@boring-cyborg boring-cyborg bot added area/common Core Powertools utility area/logging Core logging utility area/metrics Core metrics utility area/parameters area/tracing Core tracing utility tests labels Dec 12, 2025
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 12, 2025
@github-actions github-actions bot added the feature New features or minor changes label Dec 12, 2025
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 86.25592% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.28%. Comparing base (eff1550) to head (cdbb572).
⚠️ Report is 21 commits behind head on develop.

Files with missing lines Patch % Lines
...Lambda.Powertools.Metrics/Model/MetricDirective.cs 79.41% 10 Missing and 4 partials ⚠️
...aries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs 90.55% 8 Missing and 4 partials ⚠️
...rc/AWS.Lambda.Powertools.Metrics/Model/Metadata.cs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1080      +/-   ##
===========================================
+ Coverage    78.18%   78.28%   +0.10%     
===========================================
  Files          298      298              
  Lines        12037    12122      +85     
  Branches      1449     1456       +7     
===========================================
+ Hits          9411     9490      +79     
- Misses        2161     2166       +5     
- Partials       465      466       +1     

☔ 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/common Core Powertools utility area/logging Core logging utility area/metrics Core metrics utility area/parameters area/tracing Core tracing utility feature New features or minor changes size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant