Skip to content

Falcon exceptions should not always be masked as 500 and marked as error #1532

@andre-meneses-fivestars

Description

Is your feature request related to a problem?
In a Falcon app, if we raise an Exception of a type that is a subclass of a falcon.HTTPError or falcon.HTTPStatus it ends up being always marked as error and the trace status code set as 500 (Except if it is a 404).

Describe the solution you'd like
All exceptions that are subclasses of falcon.HTTPError or falcon.HTTPStatus should not always be masked with 500 status code. Additionally, status codes in the 4xx range are not server errors and should not be marked as errors, which, from what I can read in the code are not, but since everything is being set as 500, they end up being marked as errors.

Describe alternatives you've considered
My suggestion would be something like checking the exception to see if it is a subclass of a falcon.HTTPError or falcon.HTTPStatus and try to extract its status code from there. Only if it wasn't possible we would follow into the current path.

#instrumentation/falcon/__init__.py around like 499 could be something like:

if exc_type and not req_succeeded:
  if "HTTPNotFound" in exc_type.__name__:
    status = "404"
    reason = "NotFound"
  else:
    if isinstance(exc, falcon.HTTPError) or isinstance(exc, falcon.HTTPStatus):
      try:
        status = int(exc.title.split(" ")[0])
      except ValueError:
        status = "500"
    reason = f"{exc_type.__name__}: {exc}"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions