Skip to content

Commit 821e332

Browse files
srikaaviyaemdnetoxrmx
authored
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>
1 parent 4880e33 commit 821e332

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
121121
([#4078](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4171))
122122
- `opentelemetry-instrumentation-aiohttp-server`: fix HTTP error inconsistencies
123123
([#4175](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4175))
124+
- `opentelemetry-instrumentation-falcon`: Refactor `_handle_exception` to remove pylint disables
125+
([#4207](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4207))
124126
- `opentelemetry-docker-tests` Fix docker-tests assumption by Postgres-Sqlalchemy case about scope of metrics
125127
([#4258](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4258))
126128
- `opentelemetry-instrumentation-threading`: fix AttributeError when Thread is run without starting

instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,33 +328,22 @@ def __del__(self):
328328
if self in _InstrumentedFalconAPI._instrumented_falcon_apps:
329329
_InstrumentedFalconAPI._instrumented_falcon_apps.remove(self)
330330

331-
def _handle_exception(self, arg1, arg2, arg3, arg4): # pylint: disable=C0103,W0237
332-
# Falcon 3 does not execute middleware within the context of the exception
333-
# so we capture the exception here and save it into the env dict
334-
335-
# Translation layer for handling the changed arg position of "ex" in Falcon > 2 vs
336-
# Falcon < 2
331+
def _handle_exception(self, *args):
332+
# Falcon 3 does not execute middleware within the context
333+
# of the exception so we capture the exception here and
334+
# save it into the env dict
337335
if not self._is_instrumented_by_opentelemetry:
338-
return super()._handle_exception(arg1, arg2, arg3, arg4)
336+
return super()._handle_exception(*args)
339337

340338
if _falcon_version == 1:
341-
ex = arg1
342-
req = arg2
343-
resp = arg3
344-
params = arg4
339+
_, req, _, _ = args # ex, req, resp, params
345340
else:
346-
req = arg1
347-
resp = arg2
348-
ex = arg3
349-
params = arg4
341+
req, _, _, _ = args # req, resp, ex, params
350342

351343
_, exc, _ = exc_info()
352344
req.env[_ENVIRON_EXC] = exc
353345

354-
if _falcon_version == 1:
355-
return super()._handle_exception(ex, req, resp, params) # pylint: disable=W1114
356-
357-
return super()._handle_exception(req, resp, ex, params)
346+
return super()._handle_exception(*args)
358347

359348
def __call__(self, env, start_response):
360349
# pylint: disable=E1101

0 commit comments

Comments
 (0)