Send the Git revision to Bugsnag

This allows us to use the "ignore until a new version is deployed" feature.
This commit is contained in:
Sybren A. Stüvel 2016-07-05 13:01:19 +02:00
parent dda0e2c868
commit def1a3d080

View File

@ -1,6 +1,6 @@
import logging
import logging.config import logging.config
import os import os
import subprocess
import tempfile import tempfile
from bson import ObjectId from bson import ObjectId
from datetime import datetime from datetime import datetime
@ -118,6 +118,16 @@ log = logging.getLogger(__name__)
if app.config['DEBUG']: if app.config['DEBUG']:
log.info('Pillar starting, debug=%s', app.config['DEBUG']) log.info('Pillar starting, debug=%s', app.config['DEBUG'])
# Get the Git hash
try:
git_cmd = ['git', 'describe', '--always']
description = subprocess.check_output(git_cmd)
app.config['GIT_REVISION'] = description.strip()
except (subprocess.CalledProcessError, OSError) as ex:
log.warning('Unable to run "git describe" to get git revision: %s', ex)
app.config['GIT_REVISION'] = 'unknown'
log.info('Git revision %r', app.config['GIT_REVISION'])
# Configure Bugsnag # Configure Bugsnag
if not app.config.get('TESTING') and app.config.get('BUGSNAG_API_KEY'): if not app.config.get('TESTING') and app.config.get('BUGSNAG_API_KEY'):
import bugsnag import bugsnag
@ -127,6 +137,7 @@ if not app.config.get('TESTING') and app.config.get('BUGSNAG_API_KEY'):
bugsnag.configure( bugsnag.configure(
api_key=app.config['BUGSNAG_API_KEY'], api_key=app.config['BUGSNAG_API_KEY'],
project_root="/data/git/pillar/pillar", project_root="/data/git/pillar/pillar",
revision=app.config['GIT_REVISION'],
) )
bugsnag.flask.handle_exceptions(app) bugsnag.flask.handle_exceptions(app)