Skip to content

feat(logging): add ExtraKeys to logger#1128

Open
hjgraca wants to merge 2 commits intodevelopfrom
feat/logger-extra-keys
Open

feat(logging): add ExtraKeys to logger#1128
hjgraca wants to merge 2 commits intodevelopfrom
feat/logger-extra-keys

Conversation

@hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Feb 4, 2026

Please provide the issue number

Issue number: #1037

Summary

Changes

  • Add ExtraKeys() method to Logger for temporary key management within scopes
  • Implement AsyncLocal-based scope storage to support async/await boundaries
  • Replace thread-based scope isolation with async execution context isolation
  • Add LoggerScopeContext disposable for automatic key cleanup on scope exit
  • Support multiple overloads: Dictionary, params tuples, and nested scopes
  • Add documentation with examples for Dictionary, Tuples, and nested usage
  • Add AsyncSafetyTests to verify keys flow correctly across async operations
  • Add ExtraKeysTests to validate temporary key isolation and cleanup
  • Update KeyIsolationTests for new async-based scope implementation

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.

- Add ExtraKeys() method to Logger for temporary key management within scopes
- Implement AsyncLocal-based scope storage to support async/await boundaries
- Replace thread-based scope isolation with async execution context isolation
- Add LoggerScopeContext disposable for automatic key cleanup on scope exit
- Support multiple overloads: Dictionary, params tuples, and nested scopes
- Add comprehensive documentation with examples for Dictionary, Tuples, and nested usage
- Add AsyncSafetyTests to verify keys flow correctly across async operations
- Add ExtraKeysTests to validate temporary key isolation and cleanup
- Update KeyIsolationTests for new async-based scope implementation
- Provide guidance on ExtraKeys vs AppendKey usage patterns
Copilot AI review requested due to automatic review settings February 4, 2026 11:39
@boring-cyborg boring-cyborg bot added area/logging Core logging utility documentation Improvements or additions to documentation tests labels Feb 4, 2026
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 4, 2026
@github-actions github-actions bot added the feature New features or minor changes label Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 86.53846% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.24%. Comparing base (989220b) to head (a40b308).
⚠️ Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
...a.Powertools.Logging/PowertoolsLoggerExtensions.cs 0.00% 6 Missing ⚠️
.../src/AWS.Lambda.Powertools.Logging/Logger.Scope.cs 97.82% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1128   +/-   ##
========================================
  Coverage    79.23%   79.24%           
========================================
  Files          299      299           
  Lines        12441    12495   +54     
  Branches      1490     1495    +5     
========================================
+ Hits          9858     9902   +44     
- Misses        2128     2137    +9     
- Partials       455      456    +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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements the ExtraKeys feature for the Logger, addressing issue #1037. The feature provides a convenient scoped way to add temporary logging keys that are automatically removed when the scope is disposed.

Changes:

  • Migrated from thread-based scope isolation to AsyncLocal-based execution context isolation for better async/await support
  • Added ExtraKeys methods with Dictionary and tuple overloads for temporary key management
  • Added comprehensive test coverage including async safety tests and extra keys tests
  • Updated documentation with examples and usage guidance

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
libraries/src/AWS.Lambda.Powertools.Logging/Logger.Scope.cs Implements AsyncLocal-based scope storage, ExtraKeys methods, and LoggerExtraKeysScope disposable
libraries/src/AWS.Lambda.Powertools.Logging/PowertoolsLoggerExtensions.cs Adds ExtraKeys extension methods for ILogger
libraries/tests/AWS.Lambda.Powertools.ConcurrencyTests/Logging/ExtraKeysTests.cs Comprehensive tests for ExtraKeys functionality
libraries/tests/AWS.Lambda.Powertools.ConcurrencyTests/Logging/AsyncSafetyTests.cs Tests validating async/await safety of logger keys
libraries/tests/AWS.Lambda.Powertools.ConcurrencyTests/Logging/KeyIsolationTests.cs Updated to use Logger.UseScope() for simulating Lambda multi-threaded mode
docs/core/logging.md Added documentation for ExtraKeys with examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hjgraca hjgraca linked an issue Feb 4, 2026 that may be closed by this pull request
2 tasks
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

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

Labels

area/logging Core logging utility documentation Improvements or additions to documentation 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.

Feature request: Implement the ExtraKeys method described in the Docs

1 participant