Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

sentry: Allow reporting errors to sentry.io.

Alex Vandiverbfa809181a33
diff --git a/zproject/computed_settings.py b/zproject/computed_settings.py
index 01d1a45e207..26fd987416d 100644
--- a/zproject/computed_settings.py
+++ b/zproject/computed_settings.py
@@ -46,6 +46,7 @@ from .configured_settings import (
REMOTE_POSTGRES_PORT,
REMOTE_POSTGRES_SSLMODE,
SENDFILE_BACKEND,
+ SENTRY_DSN,
SOCIAL_AUTH_APPLE_SERVICES_ID,
SOCIAL_AUTH_GITHUB_KEY,
SOCIAL_AUTH_GITHUB_ORG_NAME,
@@ -1123,3 +1124,7 @@ CROSS_REALM_BOT_EMAILS = {
THUMBOR_KEY = get_secret('thumbor_key')
TWO_FACTOR_PATCH_ADMIN = False
+
+if SENTRY_DSN:
+ from .sentry import setup_sentry
+ setup_sentry(SENTRY_DSN)
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index 2d3272ee422..4c76eaf7672 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -108,6 +108,9 @@ BROWSER_ERROR_REPORTING = False
LOGGING_SHOW_MODULE = False
LOGGING_SHOW_PID = False
+# Sentry.io error defaults to off
+SENTRY_DSN: Optional[str] = None
+
# File uploads and avatars
DEFAULT_AVATAR_URI = '/static/images/default-avatar.png'
DEFAULT_LOGO_URI = '/static/images/logo/zulip-org-logo.svg'
diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py
index 986405d22b1..e01ba022af3 100644
--- a/zproject/prod_settings_template.py
+++ b/zproject/prod_settings_template.py
@@ -366,6 +366,9 @@ SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # 2 weeks
# For frontend (JavaScript) tracebacks
#BROWSER_ERROR_REPORTING = False
+# Controls the DSN used to report erors to Sentry.io
+#SENTRY_DSN = 'https://[email protected]/1235'
+
# If True, each log message in the server logs will identify the
# Python module where it came from. Useful for tracking down a
# mysterious log message, but a little verbose.
diff --git a/zproject/sentry.py b/zproject/sentry.py
new file mode 100644
index 00000000000..54ff572b600
--- /dev/null
+++ b/zproject/sentry.py
@@ -0,0 +1,22 @@
+import sentry_sdk
+from sentry_sdk.integrations import Integration
+from sentry_sdk.integrations.django import DjangoIntegration
+from sentry_sdk.integrations.redis import RedisIntegration
+from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
+
+from .config import PRODUCTION
+
+
+def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None:
+ if not dsn:
+ return
+ sentry_sdk.init(
+ dsn=dsn,
+ environment="production" if PRODUCTION else "development",
+ integrations=[
+ DjangoIntegration(),
+ RedisIntegration(),
+ SqlalchemyIntegration(),
+ *integrations,
+ ],
+ )