Skip to content

Conversation

@ConnorKirk
Copy link
Contributor

Issue number: closes #7762

Summary

This PR updates the Logger and Metric decorators to handle DurableContexts. If a DurableContext is present, it is unwrapped to access the Lambda Context

The logger.inject_lambda_context() and metrics.log_metrics() decorators raise an error in some configurations when used with a Durable Execution.
The decorators access the Lambda Context. In durable executions, the Lambda Context is wrapped with the Durable Context. The Durable Context is now passed to the handler and thus the decorators.
This affects the @logger.inject_lambda_context(log_event=True) and @metrics.log_metrics(capture_cold_start_metric=True) decorators (when included params are True). These decorators work without these parameters set. Other decorators do not use the context object, so are not affected

Changes

  • Logger - decorate - Detect if a context is durable or lambda. Extract the lambda context
  • Metrics - decorate - Detect if a context is durable or lambda. Extract the lambda context
  • Metrics Provider - decorate - Detect if a context is durable or lambda. Extract the lambda context

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.

This commit updates the Logger and Metric decorators to handle
DurableContexts. If a DurableContext is present, it is unwrapped to
access the Lambda Context
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 2, 2025
@ConnorKirk ConnorKirk changed the title Support Durable Function Context in logger and metric decorators feat(decorators): Support Durable Context in logger and metric decorators Dec 2, 2025
@github-actions github-actions bot added the feature New feature or functionality label Dec 2, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 2, 2025

@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.51%. Comparing base (fcefc8d) to head (59d95f6).
⚠️ Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
aws_lambda_powertools/metrics/base.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7765      +/-   ##
===========================================
- Coverage    96.52%   96.51%   -0.01%     
===========================================
  Files          275      275              
  Lines        13123    13125       +2     
  Branches       990      990              
===========================================
+ Hits         12667    12668       +1     
- Misses         353      354       +1     
  Partials       103      103              

☔ 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

feature New feature or functionality logger metrics size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: add support for durable function in Idempotency Utility

1 participant