Closed
Description
What were you trying to accomplish?
Have a custom middleware to inject additional keys to the Logger as well as using inject_lambda_context
.
@lambda_handler_decorator(trace_execution=True)
def process_booking_handler(
handler: Callable, event: Dict, context: Any, logger: Logger = None
) -> Callable:
if logger is None:
logger = Logger()
handler = logger.inject_lambda_context(handler)
logger.info("Injecting and annotating process booking state machine")
process_booking_context = _build_process_booking_model(event)
_logger_inject_process_booking_sfn(logger=logger, event=event)
_tracer_annotate_process_booking_sfn(process_booking_context=process_booking_context)
return handler(event, context)
Expected Behavior
Have additional key added to the log when structure_logs
is used outside the handler e.g. shared file, before the handler
Current Behavior
Any additional key is removed once the handler is executed with inject_lambda_context
Possible Solution
inject_lambda_context
is overwriting existing structured logs instead of appending
Steps to Reproduce (for bugs)
- Use
structure_logs
beforeinject_lambda_context
is used
Code
logger = Logger()
logger.structure_logs(append=True, additional_key="test")
@logger.inject_lambda_context
def handler(event, context):
logger.info("Hello") # will not contain additional_key
handler({}, lambda_context)
Environment
- Powertools version used: 1.0.0
- Packaging format (Layers, PyPi): PyPi
- AWS Lambda function runtime: Python 3.7
- Debugging logs
# paste logs here
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Triage