-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract fields from errors #237
Conversation
extract_fields_for_failures(MyException, lambda e: {"code": e.code}) | ||
|
||
If no extraction function is registered for a class Eliot will look for registered functions for its base classes. | ||
By default Eliot will automatically extract fields from ``OSError``, ``IOError`` and other subclasses of Python's ``EnvironmentError``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered defaulting to extracting .args
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. We already do repr(exception)
for the reason... but that does leave out some info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so {"args": safe_repr(exception.args)}
as default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my thought. I haven't looked at examples or anything, to see if it reasonable. Actually, {"args": map(safe_repr, exception.args)}
maybe even (typically args
is a tuple, so turning into a structured thing would be nice).
Also occurs to me that |
@@ -140,3 +140,26 @@ You can add fields to both the start message and the success message of an actio | |||
|
|||
If you want to include some extra information in case of failures beyond the exception you can always log a regular message with that information. | |||
Since the message will be recorded inside the context of the action its information will be clearly tied to the result of the action by the person (or code!) reading the logs later on. | |||
|
|||
|
|||
.. _extract errors: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why not use error-handling
as the section reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see that you get that for free from the title below.
The reference is there purely for linking from the release notes.
Thanks @itamarst Looks good. A few points:
Please address or answer the points above (including Tom's) and then merge. |
…t-fields-from-errors-236
The type system is a tricky one, yeah... Requiring every ActionType to specify every possible exception-extracted field seems unreasonable, seems better to do it on per-exception level. However, there's still issue with adding these new fields to |
The type system is to help:
First use case seems irrelevant here, since it's errors coming out of the running system - unexpected results don't mean a bug in logging code. Second use case is still relevant though. |
As far as having default that uses |
…t-fields-from-errors-236
Extract fields from errors. Fixes #236.
Fixes #236.
This will allow e.g. including HTTP response code as a field in failed actions due to
flocker.restapi._error.BadRequest
.