-
Notifications
You must be signed in to change notification settings - Fork 680
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
Add Global Error Handler #1080
Add Global Error Handler #1080
Conversation
After taking a closer look, I think the examples I had in mind during the SIG can probably all be solved by either directly raising or re-raising the exception somewhere. E.g.: try:
do_stuff(arg)
except InvalidArg:
with GlobalErrorHandler():
raise InvalidArg
do_something_else() However, maybe having a |
🤔 What is the purpose of |
As a general question, since I am not quite sure what the intention behind the spec was, could you maybe share your understanding of what kinds of errors a user should be able to register handlers for? The spec only mentions relevant errors, so I'm not quite sure where we would make use of these error handlers in the first place. |
Just for the record, here is more context related to relevant errors. I can think about a way of getting the return value of error handlers using the context manager, let me write something down... |
The example is supposed to be SDK internal. If we put all error handling code for relevant internal errors into error handlers, our code will become more fragmented. IMO the above example is better than one where we have to jump to another class to see what happens if we encounter an error. I also don't know if we want to give users the ability, or the obligation, to supply return values that get used in case of an error. At least the spec only talks about enabling strict error handling, so I think we should keep it simple. |
The spec requires to be possible for users to register their own error handlers, that's basically what is being implemented here. I agree that giving the users the return value of an error handler is outside of the scope of the requirement and probably self defeating also, since it would require the application code to act on the registered handlers themselves, breaking the separation between application code and error handlers. Because of this, I have removed the return of any value in the error handlers. |
Co-authored-by: Daniel <[email protected]>
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.
Tested this by walking through the doc, this looks great, just a few minor updates requested.
docs/examples/error_hander/error_handler_1/src/error_handler_1/version.py
Outdated
Show resolved
Hide resolved
Co-authored-by: alrex <[email protected]>
…/version.py Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
Co-authored-by: alrex <[email protected]>
…/version.py Co-authored-by: alrex <[email protected]>
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.
Thanks for including my suggestions, this looks good to me.
|
||
In order for the error handlers to be registered, they need to create a class | ||
that inherits from ``opentelemetry.sdk.error_handler.ErrorHandler`` and at | ||
least one ``Exception``-type class. For example, this is an error handler that |
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.
What is the reason for needing to inherit from an Exception
type class? Is there a necessity that the behaviour of handle
must rely on the type of the exception?
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.
Please read comment below.
"opentelemetry_error_handler" | ||
): | ||
|
||
error_handler_class = error_handler_entry_point.load() |
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.
I don't think I can see anything that enforces a specific handler to handle only certain types of errors (inheriting for an Error
doesn't really enforce this). With that being said, this logic will run through all the handlers regardless of what kind of errors they are handling. Does this make sense if there are multiple handlers handling the same type of error already?
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.
I imagine most implementations of the handlers having to deal with checking the exception type if this is not implemented somewhere else. It seems natural to me that handlers are made for specific exceptions, and they will not be interested in any other exception types, so I preferred to put this check in the global error handler. I am open to other design ideas, this is not something I consider definitive for this particular feature.
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's fine then. I think we can leave it up to the user's discretion to check exception type and handle them appropriately (if they have multiple handlers executing on the same error type then that is up to them). Is the order of execution of the handlers known somehow? Or does that depend on which iter point is loaded first?
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 would depend on the iter_points
order. So, you prefer that the global error handler does not check exception type and all error handlers are called?
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.
I think the current implementation is fine.
Just curious, are we going to wrap our entire sdk in an global error handler context to catch unhandled exceptions? |
I was not thinking about that when I was writing this error handler, I am also not sure how "doable" that is (I mean, how certainly can we guarantee that we can catch any SDK-related exception). |
@ocelotl |
Description
Add a global error handler. This object allows users to pass exceptions to pre-registered error handlers.
Fixes #1079
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Added unit tests.
Checklist: