diff --git a/ip_listener/__init__.py b/ip_listener/__init__.py index 13bb1c6..4484714 100644 --- a/ip_listener/__init__.py +++ b/ip_listener/__init__.py @@ -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 diff --git a/poetry.lock b/poetry.lock index 0bdb514..9758464 100644 --- a/poetry.lock +++ b/poetry.lock @@ -156,6 +156,34 @@ chardet = ">=3.0.2,<5" idna = ">=2.5,<3" urllib3 = ">=1.21.1,<1.27" +[[package]] +name = "sentry-sdk" +version = "0.19.5" +description = "Python client for Sentry (https://sentry.io)" +category = "main" +optional = true +python-versions = "*" + +[package.extras] +aiohttp = ["aiohttp (>=3.5)"] +beam = ["apache-beam (>=2.12)"] +bottle = ["bottle (>=0.12.13)"] +celery = ["celery (>=3)"] +chalice = ["chalice (>=1.16.0)"] +django = ["django (>=1.8)"] +falcon = ["falcon (>=1.4)"] +flask = ["flask (>=0.11)", "blinker (>=1.1)"] +pure_eval = ["pure-eval", "executing", "asttokens"] +pyspark = ["pyspark (>=2.4.4)"] +rq = ["rq (>=0.6)"] +sanic = ["sanic (>=0.8)"] +sqlalchemy = ["sqlalchemy (>=1.2)"] +tornado = ["tornado (>=5)"] + +[package.dependencies] +certifi = "*" +urllib3 = ">=1.10.0" + [[package]] name = "toml" version = "0.10.2" @@ -193,10 +221,13 @@ brotli = ["brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"] +[extras] +sentry = ["sentry_sdk"] + [metadata] lock-version = "1.0" python-versions = "^3.7" -content-hash = "a8f83243d2b8049116c8132c25bbb91eb0150322dd71b458c5355df637982634" +content-hash = "c068a970d2c0953cbb7ec9a46be718dc83ebac533aea3ac6687014638ee5b1fd" [metadata.files] appdirs = [ @@ -343,6 +374,10 @@ requests = [ {file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"}, {file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"}, ] +sentry-sdk = [ + {file = "sentry-sdk-0.19.5.tar.gz", hash = "sha256:737a094e49a529dd0fdcaafa9e97cf7c3d5eb964bd229821d640bc77f3502b3f"}, + {file = "sentry_sdk-0.19.5-py2.py3-none-any.whl", hash = "sha256:0a711ec952441c2ec89b8f5d226c33bc697914f46e876b44a4edd3e7864cf4d0"}, +] toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, diff --git a/pyproject.toml b/pyproject.toml index 8b60aa9..ab4ac69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,10 @@ python = "^3.7" click = "^7.1.2" python-dotenv = "^0.15.0" requests = "^2.25.1" +sentry_sdk = {version = "^0.19.5", optional = true} + +[tool.poetry.extras] +sentry = ["sentry_sdk"] [tool.poetry.dev-dependencies] black = "^20.8b1"