Repository navigation
feat: support logging of exceptions - #277
IzaakGough wants to merge 26 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces exception logging capabilities to the logger, including a new exception function to log active stack traces and utility functions to safely serialize exceptions and handle circular references in exception arguments. Comprehensive tests have been added to verify these changes. The review feedback suggests improving type safety by changing the type of the refs parameter from set[_typing.Any] to set[int] in both _exception_from_args and _remove_circular, as it is used to track object IDs.
|
My main concern here is divergence from what JS does. I think JS puts the stack trace into the message field. It has no separate field or exception dict equivalent. Generally we need to keep the SDKs aligned Can we check if exceptions logged via this new approach show up in the error reporting console? |
|
Dug into the Error Reporting docs: Could we add a code comment where we set |
Also test dict key coercion directly, since wrapping the payload in an exception stringified it before the key handling ran.
|
@cabljac I deployed this branch to a test project (Python 3.13, 2nd gen) to check Error Reporting:
All three arrived as |
Fixes #172.
reprraises, and non-string dict keys are coerced to strings instead of raisingTypeError. Bothlogger.error("...", error=e)and the documentedsys.exc_info()[0]pattern now work.stack_trace. It comes from an exception passed to the logger, or from the exception currently being handled when none is passed. The JS SDK puts the trace inmessage, but Error Reporting checksstack_tracefirst, so Python uses the dedicated field.stack_traceis added rather than falling back to the active exception.Covered by unit tests, and verified on a deployed Python 3.13 function: errors logged with a passed or active exception show up in Error Reporting, and a never-raised exception adds no trace.