From 821e332d7e0db040ad59077e0f02d4bb60a199a9 Mon Sep 17 00:00:00 2001 From: Sri Kaaviya <107148069+srikaaviya@users.noreply.github.com> Date: Mon, 2 Mar 2026 03:27:24 -0800 Subject: [PATCH] Fix falcon-instrumentation _handle_exception method to remove pylint disables (#4207) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix falcon-instrumentation _handle_exception method to remove pylint disables * Refactor _handle_exception method for Falcon 3 * try fix Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> * Add CHANGELOG entry for falcon _handle_exception refactor (#4207) --------- Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com> Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> Co-authored-by: Riccardo Magliocchetti --- CHANGELOG.md | 2 ++ .../instrumentation/falcon/__init__.py | 27 ++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96c77c1a8..4481a1128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,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)) - `opentelemetry-docker-tests` Fix docker-tests assumption by Postgres-Sqlalchemy case about scope of metrics ([#4258](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4258)) - `opentelemetry-instrumentation-threading`: fix AttributeError when Thread is run without starting 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 bfc82b7a1..09429f8bb 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 @@ class _InstrumentedFalconAPI(getattr(falcon, _instrument_app)): if self in _InstrumentedFalconAPI._instrumented_falcon_apps: _InstrumentedFalconAPI._instrumented_falcon_apps.remove(self) - 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 - - # Translation layer for handling the changed arg position of "ex" in Falcon > 2 vs - # Falcon < 2 + 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(arg1, arg2, arg3, arg4) + return super()._handle_exception(*args) if _falcon_version == 1: - ex = arg1 - req = arg2 - resp = arg3 - params = arg4 + _, req, _, _ = args # ex, req, resp, params else: - req = arg1 - resp = arg2 - ex = arg3 - params = arg4 + req, _, _, _ = args # req, resp, ex, params _, exc, _ = exc_info() req.env[_ENVIRON_EXC] = exc - if _falcon_version == 1: - return super()._handle_exception(ex, req, resp, params) # pylint: disable=W1114 - - return super()._handle_exception(req, resp, ex, params) + return super()._handle_exception(*args) def __call__(self, env, start_response): # pylint: disable=E1101