From 0f4d3ff3d2d77ab48b99230f0e1413e12090a906 Mon Sep 17 00:00:00 2001 From: Ryan Park Date: Fri, 16 Jan 2015 13:13:29 -0800 Subject: [PATCH] Initialize Bugsnag exception handler, when desired. At Runscope we use Bugsnag to track application exceptions. This commit allows you to use Bugsnag to track httpbin exceptions. If you want to do this, you'll need to set the environment variable BUGSNAG_API_KEY and optionally set the variable BUGSNAG_RELEASE_STAGE. You'll also need to install the Python client for Bugsnag, with `pip install bugsnag`. --- httpbin/core.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/httpbin/core.py b/httpbin/core.py index e60e90d..23c1220 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -50,6 +50,23 @@ tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask(__name__, template_folder=tmpl_dir) +# Set up Bugsnag exception tracking, if desired. To use Bugsnag, install the +# Bugsnag Python client with the command "pip install bugsnag", and set the +# environment variable BUGSNAG_API_KEY. You can also optionally set +# BUGSNAG_RELEASE_STAGE. +if os.environ.get("BUGSNAG_API_KEY") is not None: + try: + import bugsnag + import bugsnag.flask + release_stage = os.environ.get("BUGSNAG_RELEASE_STAGE") or "production" + bugsnag.configure(api_key=os.environ.get("BUGSNAG_API_KEY"), + project_root=os.path.dirname(os.path.abspath(__file__)), + use_ssl=True, release_stage=release_stage, + ignore_classes=['werkzeug.exceptions.NotFound']) + bugsnag.flask.handle_exceptions(app) + except: + app.logger.warning("Unable to initialize Bugsnag exception handling.") + # ----------- # Middlewares # -----------