mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 23:00:18 +00:00
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:
@@ -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
|
||||
# -----------
|
||||
|
||||
Reference in New Issue
Block a user