Skip to content

Bug: Allow reporting entry logs with custom exception and exception_name #1923

Closed
@iago1460

Description

@iago1460

Expected Behaviour

Due to internal logic exception and exception_name always get overridden.

The following statement should serialize the values provided:

logger.info("Report", extra={"exception": "Oops!  That was not valid", "exception_name": "ValueError" })
logger.append_keys(exception="Oops!  That was not valid", exception_name="ValueError")
logger.info("Report")

and produce an output like:

{
        "level": "INFO",
        "message": "Report",
        "exception": "Oops!  That was not valid",
        "exception_name": "ValueError",
}

Current Behaviour

Due to internal logic these field get overridden with None:

{
        "level": "INFO",
        "message": "Report"
}

Code snippet

from aws_lambda_powertools import Logger

logger = Logger()

logger.info("Report", extra={"exception": "Oops!  That was not valid", "exception_name": "ValueError"})

Possible Solution

Checking if these fields already exist on the formatted_log instead of always calling _extract_log_exception would fix this issue.

Steps to Reproduce

See code snippet section

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions