Skip to content
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

Send request exception signal in common handler #1326

Merged
merged 3 commits into from
Jul 19, 2021

Conversation

Agalin
Copy link
Contributor

@Agalin Agalin commented Nov 22, 2020

Flask's default error handler sends got_request_exception signal (see this method). Handler provided by connexion doesn't do that and breaks integration of other apps, e.g. Sentry (see Flask integration implementation).

Changes proposed in this pull request:

  • Send got_request_exception signal in common_exception_handler registered for Flask application.
  • Due to got_request_exception expecting an instance common_exception_hanndler is changed from static method to a normal instance method.

@RobbeSneyders RobbeSneyders changed the base branch from master to main July 19, 2021 15:20
Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @Agalin!

@RobbeSneyders RobbeSneyders merged commit a9a40df into spec-first:main Jul 19, 2021
@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 97.02% when pulling bf5653d on Agalin:exception_signal into 005d046 on zalando:main.

hauntsaninja pushed a commit to hauntsaninja/connexion that referenced this pull request Aug 10, 2022
* Send request exception signal in common handler

* Sort imports

Co-authored-by: Robbe Sneyders <[email protected]>
RobbeSneyders pushed a commit that referenced this pull request Dec 7, 2022
Fixes the problem of non-exceptional "exceptions" being recorded by
telemetry systems as a serious error. This expands on the changes made
in #1326. The intention of that other change seems to be making
telemetry systems like Sentry record serious errors. Diving into the
Sentry implementation even shows that the signalled exception is
recorded at "level" = "error".

The root of the problem is that exceptions are being used for control
flow, which is not ideal - convenient for app writers but not always for
library maintainers. The connexion BadRequestProblem and
NotFoundProblem, for example, should not be recorded as an error in a
telemetry system. In my case
[elastic-apm-python](https://github.com/elastic/apm-agent-python) is
receiving these signals and recording 4xx events as serious errors.

This pull request only propagates an exception signal to flask if it's a
serious error.

Aiohttp applications have a similar problem with exceptions being used
for control flow - the problems middleware will convert the exception
into an appropriate problem response but things like the elastic apm
python telemetry middleware will see that exception and record it as a
serious error. Interestingly aiohttp also uses exceptions for control
flow and the elastic apm agent was patched to specifically ignore aio
web exceptions below the 5xx status response range. Elastic apm and
sentry cannot be expected to be aware of non-serious control flow
exceptions used by various libraries though. So, a solution for Aiohttp
applications is a separate problem.

Co-authored-by: Enerqi <>
RobbeSneyders pushed a commit that referenced this pull request Jan 24, 2023
Fixes the problem of non-exceptional "exceptions" being recorded by
telemetry systems as a serious error. This expands on the changes made
in #1326. The intention of that other change seems to be making
telemetry systems like Sentry record serious errors. Diving into the
Sentry implementation even shows that the signalled exception is
recorded at "level" = "error".

The root of the problem is that exceptions are being used for control
flow, which is not ideal - convenient for app writers but not always for
library maintainers. The connexion BadRequestProblem and
NotFoundProblem, for example, should not be recorded as an error in a
telemetry system. In my case
[elastic-apm-python](https://github.com/elastic/apm-agent-python) is
receiving these signals and recording 4xx events as serious errors.

This pull request only propagates an exception signal to flask if it's a
serious error.

Aiohttp applications have a similar problem with exceptions being used
for control flow - the problems middleware will convert the exception
into an appropriate problem response but things like the elastic apm
python telemetry middleware will see that exception and record it as a
serious error. Interestingly aiohttp also uses exceptions for control
flow and the elastic apm agent was patched to specifically ignore aio
web exceptions below the 5xx status response range. Elastic apm and
sentry cannot be expected to be aware of non-serious control flow
exceptions used by various libraries though. So, a solution for Aiohttp
applications is a separate problem.

Co-authored-by: Enerqi <>
jcristau added a commit to jcristau/tooltool that referenced this pull request Dec 18, 2023
spec-first/connexion#1326 changed
FlaskApp.common_error_handler from a static method to a regular method, which
means we can't use it without an actual FlaskApp, or we'd turn any error
into a TypeError and 500.

Fixes mozilla-releng#1159
jcristau added a commit to mozilla-releng/tooltool that referenced this pull request Dec 20, 2023
spec-first/connexion#1326 changed
FlaskApp.common_error_handler from a static method to a regular method, which
means we can't use it without an actual FlaskApp, or we'd turn any error
into a TypeError and 500.

Fixes #1159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants