From 20edb20563be124c7e59901faeb7cf0d6354547e Mon Sep 17 00:00:00 2001 From: Corry Haines Date: Sat, 7 Jan 2023 16:21:41 -0800 Subject: [PATCH] Add debug environment and sentry experiment (#372) The "debug" environment allows for an additional label in Sentry. I use this to isolate issues/traces only present on my server with DEBUG enabled, for faster development and tracing. The sentry _experiments is a optional list of beta-grade experiments that Sentry is developing. Profile traces is one of those experiments, to adding it disabled by default. Developers can enable it with the provided setting. --- takahe/settings.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/takahe/settings.py b/takahe/settings.py index 2cd0cc8..178583b 100644 --- a/takahe/settings.py +++ b/takahe/settings.py @@ -41,7 +41,7 @@ def as_bool(v: str | list[str] | None): return v[0].lower() in ("true", "yes", "t", "1") -Environments = Literal["development", "production", "test"] +Environments = Literal["debug", "development", "production", "test"] TAKAHE_ENV_FILE = os.environ.get( "TAKAHE_ENV_FILE", "test.env" if "pytest" in sys.modules else ".env" @@ -95,6 +95,7 @@ class Settings(BaseSettings): SENTRY_SAMPLE_RATE: float = 1.0 SENTRY_TRACES_SAMPLE_RATE: float = 0.01 SENTRY_CAPTURE_MESSAGES: bool = False + SENTRY_EXPERIMENTAL_PROFILES_TRACES_SAMPLE_RATE: float = 0.0 #: Fallback domain for links. MAIN_DOMAIN: str = "example.com" @@ -337,6 +338,13 @@ if SETUP.USE_PROXY_HEADERS: if SETUP.SENTRY_DSN: from sentry_sdk.integrations.httpx import HttpxIntegration + sentry_experiments = {} + + if SETUP.SENTRY_EXPERIMENTAL_PROFILES_TRACES_SAMPLE_RATE > 0: + sentry_experiments[ + "profiles_sample_rate" + ] = SETUP.SENTRY_EXPERIMENTAL_PROFILES_TRACES_SAMPLE_RATE + sentry_sdk.init( dsn=SETUP.SENTRY_DSN, integrations=[ @@ -347,6 +355,7 @@ if SETUP.SENTRY_DSN: sample_rate=SETUP.SENTRY_SAMPLE_RATE, send_default_pii=True, environment=SETUP.ENVIRONMENT, + _experiments=sentry_experiments, ) sentry_sdk.set_tag("takahe.version", __version__)