From a985284b5d41e7c2414c623b007632938fa2308d Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 8 Jul 2021 17:38:46 -0700 Subject: [PATCH] sentry: Set environment to `staging` on staging hosts. Splitting exceptions out between staging and production provides useful filtering. --- zproject/config.py | 1 + zproject/sentry.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zproject/config.py b/zproject/config.py index 42ec637b74..ae7473b150 100644 --- a/zproject/config.py +++ b/zproject/config.py @@ -9,6 +9,7 @@ config_file.read("/etc/zulip/zulip.conf") # Whether this instance of Zulip is running in a production environment. PRODUCTION = config_file.has_option("machine", "deploy_type") +STAGING = config_file.get("machine", "deploy_type", fallback="") == "staging" DEVELOPMENT = not PRODUCTION secrets_file = configparser.RawConfigParser() diff --git a/zproject/sentry.py b/zproject/sentry.py index c334de23b7..a260f6bc42 100644 --- a/zproject/sentry.py +++ b/zproject/sentry.py @@ -11,7 +11,7 @@ from sentry_sdk.utils import capture_internal_exceptions from version import ZULIP_VERSION -from .config import PRODUCTION +from .config import PRODUCTION, STAGING if TYPE_CHECKING: from sentry_sdk._types import Event, Hint @@ -60,9 +60,16 @@ def add_context(event: "Event", hint: "Hint") -> Optional["Event"]: def setup_sentry(dsn: Optional[str], *integrations: Integration) -> None: if not dsn: return + if PRODUCTION: + if STAGING: + environment = "staging" + else: + environment = "production" + else: + environment = "development" sentry_sdk.init( dsn=dsn, - environment="production" if PRODUCTION else "development", + environment=environment, release=ZULIP_VERSION, integrations=[ DjangoIntegration(),