From 1a505bb0a2665bbc12a0114905845ec1d30e64c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 13 Sep 2017 16:36:29 +0200 Subject: [PATCH] Work around bugsnag issue 3263f0a551b663f93d1f2ec8087ef43302752f8b didn't fix it in production. --- pillar/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pillar/__init__.py b/pillar/__init__.py index 3cdc3eef..75ebd4c8 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -175,28 +175,38 @@ class PillarServer(Eve): self.log.info('Git revision %r', self.config['GIT_REVISION']) def _config_bugsnag(self): - # Configure Bugsnag bugsnag_api_key = self.config.get('BUGSNAG_API_KEY') if self.config.get('TESTING') or not bugsnag_api_key: self.log.info('Bugsnag NOT configured.') return import bugsnag - from bugsnag.flask import handle_exceptions from bugsnag.handlers import BugsnagHandler bugsnag.configure( api_key=bugsnag_api_key, project_root="/data/git/pillar/pillar", ) - handle_exceptions(self) bs_handler = BugsnagHandler() bs_handler.setLevel(logging.ERROR) self.log.addHandler(bs_handler) + # This is what bugsnag.flask.handle_exceptions also tries to do, + # but it passes the app to the connect() call, which causes an + # error. Since we only have one app, we can do without. + from flask import got_request_exception + from bugsnag.flask import add_flask_request_to_notification + + bugsnag.before_notify(add_flask_request_to_notification) + got_request_exception.connect(self.__notify_bugsnag) + self.log.info('Bugsnag setup complete') + def __notify_bugsnag(self, sender, exception, **extra): + import bugsnag + bugsnag.auto_notify(exception) + def _config_google_cloud_storage(self): # Google Cloud project try: