Description
Use case
As a developer, I would like PowerTools' Logging to support the notes feature (BaseException.__notes__
) so my log messages can be enriched with data and code natively available via Python exceptions.
Solution/User Experience
PowerTools' log messages include a notes: list[str]
attribute populated by Python's BaseException.__notes__
.
The common use case is when you want to add context to a potential exception but not explicitly log at the time.
try:
get_data(customer_id)
except Exception as exc:
exc.add_note(f"Customer: '{customer_id}'")
raise
Ideally, the log message would then include a notes
attribute:
{
"level": "ERROR",
"location": "update_all_customers:64",
"message": "Super detailed message here.",
"timestamp": "2025-04-10 15:00:27,218+0000",
"service": "CustomerManagement",
"cold_start": true,
"function_name": "customer_profile_updater",
"function_memory_size": "512",
"function_arn": "arn:aws:lambda:us-west-2:111111111111111:function:customer_profile_updater",
"function_request_id": "b0635544-37e1-4407-8366-35b0c86222e5",
"taskName": "Task-1",
"xray_trace_id": "7812696e-9dc6-4909-b314-3d7c2c93da04",
"notes": [
"Encountered errors while updating customer profiles.",
"Customer: '123456'"
]
}
Alternative solutions
PowerTools' Logging feature already includes alternate solutions but they're specific to PowerTools. It would be great if PowerTools' Logger leveraged the `BaseException.__notes__` attribute already available.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped