aboutsummaryrefslogtreecommitdiffstats
path: root/snekbox/utils/logging.py
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2022-05-30 20:01:47 -0700
committerGravatar MarkKoz <[email protected]>2022-05-30 20:01:47 -0700
commit812374109a2adef13dd1a810cc69643c33de884f (patch)
treed1932b281961efea883281071633a6e0f36cd73f /snekbox/utils/logging.py
parentMove logging code to separate utility modules (diff)
Make Sentry SDK and gunicorn optional dependencies
Falcon provides a WSGI app which can be used by any server, not just gunicorn. Thus, make gunicorn optional in case the user wants to use a different server. There shouldn't be any import errors since the class is now in an isolated module. The only time that module is imported is when gunicorn loads its config. Sentry is there for Python Discord mainly, so this dependency shouldn't be imposed on others.
Diffstat (limited to '')
-rw-r--r--snekbox/utils/logging.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/snekbox/utils/logging.py b/snekbox/utils/logging.py
index e5afd0c..9a713f8 100644
--- a/snekbox/utils/logging.py
+++ b/snekbox/utils/logging.py
@@ -2,9 +2,6 @@ import logging
import os
import sys
-import sentry_sdk
-from sentry_sdk.integrations.falcon import FalconIntegration
-
__all__ = ("FORMAT", "init_logger", "init_sentry")
FORMAT = "%(asctime)s | %(process)5s | %(name)30s | %(levelname)8s | %(message)s"
@@ -23,7 +20,13 @@ def init_logger(debug: bool) -> None:
def init_sentry() -> None:
- """Initialise the Sentry SDK."""
+ """Initialise the Sentry SDK if it's installed."""
+ try:
+ import sentry_sdk
+ from sentry_sdk.integrations.falcon import FalconIntegration
+ except ImportError:
+ return
+
git_sha = os.environ.get("GIT_SHA", "development")
sentry_sdk.init(
dsn=os.environ.get("SNEKBOX_SENTRY_DSN", ""),