generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 465
Open
Labels
Description
Expected Behaviour
Logging and Metric decorators support Durable Context.
Current Behaviour
- The
logger.inject_lambda_context()andmetrics.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.
- 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.
Code snippet
from aws_durable_execution_sdk_python import (
DurableContext,
StepContext,
durable_execution,
durable_step,
)
from aws_durable_execution_sdk_python.config import Duration
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.buffer import LoggerBufferConfig
logger = Logger(
service="durable",
level="INFO",
serialize_stacktrace=False,
sampling_rate=0.1,
)
@durable_execution
@logger.inject_lambda_context(log_event=True)
def lambda_handler(event: dict, context: DurableContext) -> str:
"""Simple durable function."""
logger.info("an info log")
return "Hello world"Possible Solution
Check if the provided context is a Durable Context. If so, unwrap the Lambda Context from the Durable Context.
Steps to Reproduce
- Create lambda function with durable config specified
- Invoke handler above
- Observe error
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.14
Packaging format used
PyPi
Debugging logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Working on it