Add optional sentry integration

This commit is contained in:
sonny 2021-01-01 11:57:38 +01:00
parent 1d130254c0
commit 0fa8fd2558
3 changed files with 72 additions and 1 deletions

View file

@ -1,7 +1,39 @@
import os
import subprocess
from pathlib import Path
from dotenv import load_dotenv
env_path = Path("..") / ".env"
load_dotenv(dotenv_path=env_path)
def get_current_version():
if "VERSION" in os.environ:
return os.environ["VERSION"]
try:
output = subprocess.check_output(
["git", "describe", "--tags"], universal_newlines=True
)
return output.strip()
except (subprocess.CalledProcessError, OSError):
return ""
VERSION = get_current_version()
# Optionally use sentry integration
try:
from sentry_sdk import init as sentry_init
sentry_init(
dsn=os.environ.get("SENTRY_DSN"),
send_default_pii=False,
release=VERSION,
)
except ImportError:
pass