feat(logger,metrics): add DurableContext support for decorators#7911
Closed
oyiz-michael wants to merge 7 commits intoaws-powertools:developfrom
Closed
feat(logger,metrics): add DurableContext support for decorators#7911oyiz-michael wants to merge 7 commits intoaws-powertools:developfrom
oyiz-michael wants to merge 7 commits intoaws-powertools:developfrom
Conversation
- Add _unwrap_durable_context() helper to detect and unwrap DurableContext - Update build_lambda_context_model() to handle both LambdaContext and DurableContext - Add comprehensive tests for DurableContext support in logger decorators - Fixes compatibility with AWS Durable Execution SDK
…t docstring - Document that inject_lambda_context supports DurableContext - Note automatic unwrapping behavior for better UX
- Add _unwrap_durable_context() helper in base provider - Update _add_cold_start_metric() to unwrap DurableContext before passing to providers - Add documentation noting DurableContext support in log_metrics decorator Relates to aws-powertools#7763
…ator - Add tests for capture_cold_start_metric with DurableContext - Add regression test for standard LambdaContext compatibility - Verify function_name extraction from unwrapped context Relates to aws-powertools#7763
… blobs - Fix test to use capture_metrics_output_multiple_emf_objects for cold start tests - Remove duplicate assertion lines - All 9 DurableContext tests now passing
|
Contributor
|
Hey @oyiz-michael thanks a lot for this PR, but we merged the #7765 today morning! I'm closing this without merge! Thanks a lot for offering help here and we have some bugs opened. Feel free to pick up one and work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #7763
Summary
Changes
This PR adds support for AWS Durable Execution SDK's
DurableContextin Logger and Metrics decorators, addressing compatibility issues when using Powertools with durable Lambda functions.Core Implementation:
_unwrap_durable_context()helper function to detect and unwrapDurableContextvia duck typing (checking forlambda_contextandstateattributes)build_lambda_context_model()in logger to automatically unwrapDurableContextbefore accessing Lambda context properties_add_cold_start_metric()in metrics base provider to unwrapDurableContextbefore passing toadd_cold_start_metric()inject_lambda_contextandlog_metricsdecorators to document DurableContext supportTesting:
inject_lambda_contextdecorator with DurableContextlog_metricsdecorator with DurableContextLambdaContextlog_event=True,clear_state=True,capture_cold_start_metric=True, and explicit function namesQuality:
User experience
Before:
Users using AWS Durable Execution SDK would encounter errors when using Logger or Metrics decorators because the decorators expected a standard
LambdaContextbut received aDurableContextwrapper instead.After:
The decorators now seamlessly work with both standard LambdaContext and DurableContext. The unwrapping happens automatically and transparently to the user.
The implementation uses duck typing to detect DurableContext checking for lambda_context and state, automatically extracts the underlying LambdaContextand processes it normally.
This approach:
Requires no code changes from users
Maintains full backward compatibility
Follows the same pattern used in Idempotency utility
Is fully tested with both context types
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.