-
Notifications
You must be signed in to change notification settings - Fork 437
Labels
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 meetsShould this be considered in other Powertools for AWS Lambda languages? i.e. , , andTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped
Milestone
Relationships
Development
Select code repository
Activity
leandrodamascena commentedon Apr 10, 2025
Hi @waffleshop! Thanks for opening this issue! Yes, I think it makes a lot of sense to serialize the notes added when logging an exception or error with
exc_info=True
.Notes are supported in Python 3.11+ and Powertools supports 3.9+, so we need to add a condition when serializing the exception to check if the Python version is 3.11+ or just if the
__notes__
field exists in that object.Would you like to submit a PR to implement this? I'd love to have your contribution here.
5 remaining items