From c44244c2015234fcccd74f255b182326a4238735 Mon Sep 17 00:00:00 2001 From: Filip Nikolovski Date: Tue, 10 Dec 2024 13:28:16 +0100 Subject: [PATCH] fix exceptions to not be masked as 500 on every thrown exception --- .../opentelemetry/instrumentation/falcon/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 429db76d9f..2069e6e55f 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -516,14 +516,21 @@ def process_response(self, req, resp, resource, req_succeeded=None): # pylint:d if resource is None: status = "404" else: + exc_type, exc = None, None if _ENVIRON_EXC in req.env: exc = req.env[_ENVIRON_EXC] exc_type = type(exc) - else: - exc_type, exc = None, None + if exc_type and not req_succeeded: if "HTTPNotFound" in exc_type.__name__: status = "404" + elif isinstance(exc, falcon.HTTPError) or isinstance( + exc, falcon.HTTPStatus + ): + try: + status = exc.title.split(" ")[0] + except ValueError: + status = "500" else: status = "500"