Closed
Description
From the "Appending additional keys" docs:
You can append additional keys using either mechanism:
Persist new keys across all future log messages via structure_logs method
"Persist new keys across all future log messages via structure_logs method" could be read as either:
- "new keys will be added to all future logs across all Lambda invocations "
- "new keys will be added to all future logs for the duration of a Lambda invocation".
I chose the latter because of your example, which I think implies that an order_id is appended to all logs for for the duration of a Lambda invocation:
def handler(event, context):
order_id = event.get("order_id")
logger.structure_logs(append=True, order_id=order_id)
logger.info("Collecting payment")
If I change your example to this:
def handler(event, context):
logger.info('Something before order_id is known')
order_id = event.get("order_id")
logger.structure_logs(append=True, order_id=order_id)
logger.info("Collecting payment")
The result is:
- If order_id=1... Lambda is invoked the first time and the correct order_id of "1" is logged with "Collecting payment".
- If order_id=2... Lambda is invoked the second time and incorrect order_id is logged as "1" with "Something before order_id is known", and then the correct order_id of "2" is logged with "Collecting payment".
Is this expected behavior? Seems like a state issue? Either way I think it might make sense to make the docs or examples more clear! Thanks!
Environment
- Powertools version used: 1.14.0
- Packaging format (Layers, PyPi): PyPi
- AWS Lambda function runtime: Python 3.8
Metadata
Metadata
Assignees
Type
Projects
Status
Triage