# HG changeset patch # User RhodeCode Admin # Date 2023-03-07 08:57:01 # Node ID 08819a6d1f373290730880094818f7e95ee551de # Parent 0d6cd34491e650e71feb43e391f40b83519402d4 appenligth: make it optional if library is not installed diff --git a/rhodecode/lib/middleware/appenlight.py b/rhodecode/lib/middleware/appenlight.py --- a/rhodecode/lib/middleware/appenlight.py +++ b/rhodecode/lib/middleware/appenlight.py @@ -25,18 +25,10 @@ import logging log = logging.getLogger(__name__) -appenlight_installed = False - -try: - from appenlight_client import make_appenlight_middleware - from appenlight_client.exceptions import get_current_traceback - from appenlight_client.wsgi import AppenlightWSGIWrapper - appenlight_installed = True -except ImportError: - log.info('Appenlight packages not present, skipping appenlight setup') - def track_exception(environ): + from appenlight_client.exceptions import get_current_traceback + if 'appenlight.client' not in environ: return @@ -44,7 +36,8 @@ def track_exception(environ): environ['appenlight.__traceback'] = get_current_traceback( skip=1, show_hidden_frames=True, - ignore_system_exceptions=True) + ignore_system_exceptions=True + ) def track_extra_information(environ, section, value): @@ -72,13 +65,21 @@ def wrap_in_appenlight_if_enabled(app, s This is in use to support our setup of the vcs related middlewares. """ - if appenlight_installed and settings['appenlight']: + if settings['appenlight']: + try: + from appenlight_client import make_appenlight_middleware + from appenlight_client.wsgi import AppenlightWSGIWrapper + except ImportError: + log.info('Appenlight packages not present, skipping appenlight setup') + return app, appenlight_client + app = RemoteTracebackTracker(app) if not appenlight_client: app = make_appenlight_middleware(app, settings) appenlight_client = app.appenlight_client else: app = AppenlightWSGIWrapper(app, appenlight_client) + return app, appenlight_client