Fix falcon-instrumentation _handle_exception method to remove pylint disables (#4207)

* 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 <riccardo.magliocchetti@gmail.com>
This commit is contained in:
Sri Kaaviya
2026-03-02 03:27:24 -08:00
committed by GitHub
parent 4880e33217
commit 821e332d7e
2 changed files with 10 additions and 19 deletions

View File

@@ -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

View File

@@ -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