From 3c99485e40725cdbe0bf2b7429602464609a6c89 Mon Sep 17 00:00:00 2001 From: srikaaviya Date: Sun, 15 Feb 2026 06:18:23 -0800 Subject: [PATCH 1/4] Fix falcon-instrumentation _handle_exception method to remove pylint disables --- .../instrumentation/falcon/__init__.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 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 3a8c7600aa..9bd47ae2e2 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -328,33 +328,33 @@ def __del__(self): if self in _InstrumentedFalconAPI._instrumented_falcon_apps: _InstrumentedFalconAPI._instrumented_falcon_apps.remove(self) - def _handle_exception(self, arg1, arg2, arg3, arg4): # pylint: disable=C0103 - # Falcon 3 does not execute middleware within the context of the exception - # so we capture the exception here and save it into the env dict + if _falcon_version == 1: - # Translation layer for handling the changed arg position of "ex" in Falcon > 2 vs - # Falcon < 2 - if not self._is_instrumented_by_opentelemetry: - return super()._handle_exception(arg1, arg2, arg3, arg4) - - if _falcon_version == 1: - ex = arg1 - req = arg2 - resp = arg3 - params = arg4 - else: - req = arg1 - resp = arg2 - ex = arg3 - params = arg4 + def _handle_exception(self, ex, req, resp, params): + # Falcon 3 does not execute middleware within the context + # of the exception so we capture the exception here and + # save it into the env dict + if not self._is_instrumented_by_opentelemetry: + return super()._handle_exception(ex, req, resp, params) - _, exc, _ = exc_info() - req.env[_ENVIRON_EXC] = exc + _, exc, _ = exc_info() + req.env[_ENVIRON_EXC] = exc - if _falcon_version == 1: return super()._handle_exception(ex, req, resp, params) - return super()._handle_exception(req, resp, ex, params) + else: + + def _handle_exception(self, req, resp, ex, params): + # Falcon 3 does not execute middleware within the context + # of the exception so we capture the exception here and + # save it into the env dict + if not self._is_instrumented_by_opentelemetry: + return super()._handle_exception(req, resp, ex, params) + + _, exc, _ = exc_info() + req.env[_ENVIRON_EXC] = exc + + return super()._handle_exception(req, resp, ex, params) def __call__(self, env, start_response): # pylint: disable=E1101 From 30eebd235c2879db463ba64835dec52806883f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C3=ADdio=20Neto?= <9735060+emdneto@users.noreply.github.com> Date: Thu, 19 Feb 2026 21:32:02 -0300 Subject: [PATCH 2/4] Refactor _handle_exception method for Falcon 3 --- .../opentelemetry/instrumentation/falcon/__init__.py | 11 ----------- 1 file changed, 11 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 25907f8241..9bd47ae2e2 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -328,13 +328,7 @@ def __del__(self): if self in _InstrumentedFalconAPI._instrumented_falcon_apps: _InstrumentedFalconAPI._instrumented_falcon_apps.remove(self) -<<<<<<< fix/falcon-handle-exception-pylint-4198 if _falcon_version == 1: -======= - def _handle_exception(self, arg1, arg2, arg3, arg4): # pylint: disable=C0103,W0237 - # Falcon 3 does not execute middleware within the context of the exception - # so we capture the exception here and save it into the env dict ->>>>>>> main def _handle_exception(self, ex, req, resp, params): # Falcon 3 does not execute middleware within the context @@ -346,12 +340,7 @@ def _handle_exception(self, ex, req, resp, params): _, exc, _ = exc_info() req.env[_ENVIRON_EXC] = exc -<<<<<<< fix/falcon-handle-exception-pylint-4198 return super()._handle_exception(ex, req, resp, params) -======= - if _falcon_version == 1: - return super()._handle_exception(ex, req, resp, params) # pylint: disable=W1114 ->>>>>>> main else: From a23c80c115560f1a56118f578a2277319614e7c9 Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Thu, 19 Feb 2026 21:52:25 -0300 Subject: [PATCH 3/4] try fix Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> --- .../instrumentation/falcon/__init__.py | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 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 9bd47ae2e2..09429f8bb5 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -328,33 +328,22 @@ def __del__(self): if self in _InstrumentedFalconAPI._instrumented_falcon_apps: _InstrumentedFalconAPI._instrumented_falcon_apps.remove(self) - if _falcon_version == 1: - - def _handle_exception(self, ex, req, resp, params): - # Falcon 3 does not execute middleware within the context - # of the exception so we capture the exception here and - # save it into the env dict - if not self._is_instrumented_by_opentelemetry: - return super()._handle_exception(ex, req, resp, params) - - _, exc, _ = exc_info() - req.env[_ENVIRON_EXC] = exc - - return super()._handle_exception(ex, req, resp, params) - - else: + def _handle_exception(self, *args): + # Falcon 3 does not execute middleware within the context + # of the exception so we capture the exception here and + # save it into the env dict + if not self._is_instrumented_by_opentelemetry: + return super()._handle_exception(*args) - def _handle_exception(self, req, resp, ex, params): - # Falcon 3 does not execute middleware within the context - # of the exception so we capture the exception here and - # save it into the env dict - if not self._is_instrumented_by_opentelemetry: - return super()._handle_exception(req, resp, ex, params) + if _falcon_version == 1: + _, req, _, _ = args # ex, req, resp, params + else: + req, _, _, _ = args # req, resp, ex, params - _, exc, _ = exc_info() - req.env[_ENVIRON_EXC] = exc + _, exc, _ = exc_info() + req.env[_ENVIRON_EXC] = exc - return super()._handle_exception(req, resp, ex, params) + return super()._handle_exception(*args) def __call__(self, env, start_response): # pylint: disable=E1101 From 27508edf188a38abeeadb58748e0710aa26198a4 Mon Sep 17 00:00:00 2001 From: srikaaviya Date: Thu, 19 Feb 2026 20:28:32 -0800 Subject: [PATCH 4/4] Add CHANGELOG entry for falcon _handle_exception refactor (#4207) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0faa56ae..8c51817656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#4078](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4171)) - `opentelemetry-instrumentation-aiohttp-server`: fix HTTP error inconsistencies ([#4175](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4175)) +- `opentelemetry-instrumentation-falcon`: Refactor `_handle_exception` to remove pylint disables + ([#4207](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4207)) ### Breaking changes