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`.
This commit is contained in:
Ryan Park
2015-01-16 13:13:29 -08:00
parent 681553d691
commit 0f4d3ff3d2
+17
View File
@@ -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
# -----------