flask-rebar icon indicating copy to clipboard operation
flask-rebar copied to clipboard

Flask signals not triggered on unhandled exceptions

Open airstandley opened this issue 2 years ago • 0 comments

Flask has a signal got_request_exception intended to signify that an unhandled exception occurred in a handler. This signal is triggered by the default error handler, ref: https://github.com/pallets/flask/blob/0d8c8ba71bc6362e6ea9af08146dc97e1a0a8abc/src/flask/app.py#L1675. This means that to Flask, adding error handlers is equivalent to catching an exception; their documentation attempts to explains this, but it can be easy to miss the implication that the exception signal is not sent if a registered error handler matches the exception.

Existing instrumentation/observability tooling uses this signal to detect when an unexpected error has occurred in a service.

Rebar currently registers a generic Exception error handler, ref: https://github.com/plangrid/flask-rebar/blob/63922a17379a5b5a99c7422b7f7b881f8c08eb13/flask_rebar/rebar.py#L818-L827.

This causes tools/plugins that rely on the got_request_exception signal to fail to work with a Rebar service.

Rebar should either

  1. Switch the generic error handler to register for InternalServerError; meaning that the rebar handler would only run after the default flask handler had run and sent the got_request_exception signal.
  2. Send the got_request_exception signal as part of it's generic exception handling.

airstandley avatar Oct 04 '22 17:10 airstandley