also send environment and release to Sentry

This commit is contained in:
Changaco 2018-01-14 18:32:10 +01:00
parent f437a511dc
commit a77ff2e20f
4 changed files with 65 additions and 3 deletions

2
.gitattributes vendored
View File

@ -1,3 +1,5 @@
# Inject version number into archives
liberapay/version.py export-subst
# Tell Git not to attempt any end-of-line conversions upon checkin or checkout
* -text
*.pdf filter=lfs diff=lfs merge=lfs -text

View File

@ -42,3 +42,5 @@ AWS_SECRET_ACCESS_KEY=
GRATIPAY_BASE_URL=http://localhost:8537
SECRET_FOR_GRATIPAY=fake
INSTANCE_TYPE=development

45
liberapay/version.py Normal file
View File

@ -0,0 +1,45 @@
# Source: https://github.com/Changaco/version.py
from os.path import dirname, isdir, join
import re
from subprocess import CalledProcessError, check_output
PREFIX = ''
tag_re = re.compile(r'\btag: %s([0-9][^,]*)\b' % PREFIX)
version_re = re.compile('^Version: (.+)$', re.M)
def get_version():
# Return the version if it has been injected into the file by git-archive
version = tag_re.search('$Format:%D$')
if version:
return version.group(1)
d = dirname(dirname(__file__))
if isdir(join(d, '.git')):
# Get the version using "git describe".
cmd = 'git describe --tags --match %s[0-9]* --dirty' % PREFIX
try:
version = check_output(cmd.split()).decode().strip()[len(PREFIX):]
except CalledProcessError:
raise RuntimeError('Unable to get version number from git tags')
# PEP 440 compatibility
if '-' in version:
if version.endswith('-dirty'):
raise RuntimeError('The working tree is dirty')
version = '.post'.join(version.split('-')[:2])
else:
# Extract the version from the PKG-INFO file.
with open(join(d, 'PKG-INFO')) as f:
version = version_re.search(f.read()).group(1)
return version
if __name__ == '__main__':
print(get_version())

View File

@ -50,6 +50,7 @@ from liberapay.utils.i18n import (
get_function_from_rule, make_sorted_dict
)
from liberapay.utils.query_cache import QueryCache
from liberapay.version import get_version
def canonical(env):
@ -330,9 +331,20 @@ def username_restrictions(www_root):
def make_sentry_teller(env):
sentry = raven.Client(env.sentry_dsn) if env.sentry_dsn else None
if not sentry:
if env.sentry_dsn:
try:
release = get_version()
if '-' in release:
release = None
except:
release = None
sentry = raven.Client(
env.sentry_dsn,
environment=env.instance_type,
release=release,
)
else:
sentry = None
print("Won't log to Sentry (SENTRY_DSN is empty).")
def tell_sentry(exception, state, allow_reraise=True):
@ -624,6 +636,7 @@ def env():
OVERRIDE_QUERY_CACHE=is_yesish,
GRATIPAY_BASE_URL=str,
SECRET_FOR_GRATIPAY=str,
INSTANCE_TYPE=str,
)
logging.basicConfig(level=getattr(logging, env.logging_level.upper()))