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.
This commit is contained in:
Corry Haines 2023-01-07 16:21:41 -08:00 committed by GitHub
parent d8cee4097f
commit 20edb20563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -41,7 +41,7 @@ def as_bool(v: str | list[str] | None):
return v[0].lower() in ("true", "yes", "t", "1") 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 = os.environ.get(
"TAKAHE_ENV_FILE", "test.env" if "pytest" in sys.modules else ".env" "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_SAMPLE_RATE: float = 1.0
SENTRY_TRACES_SAMPLE_RATE: float = 0.01 SENTRY_TRACES_SAMPLE_RATE: float = 0.01
SENTRY_CAPTURE_MESSAGES: bool = False SENTRY_CAPTURE_MESSAGES: bool = False
SENTRY_EXPERIMENTAL_PROFILES_TRACES_SAMPLE_RATE: float = 0.0
#: Fallback domain for links. #: Fallback domain for links.
MAIN_DOMAIN: str = "example.com" MAIN_DOMAIN: str = "example.com"
@ -337,6 +338,13 @@ if SETUP.USE_PROXY_HEADERS:
if SETUP.SENTRY_DSN: if SETUP.SENTRY_DSN:
from sentry_sdk.integrations.httpx import HttpxIntegration 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( sentry_sdk.init(
dsn=SETUP.SENTRY_DSN, dsn=SETUP.SENTRY_DSN,
integrations=[ integrations=[
@ -347,6 +355,7 @@ if SETUP.SENTRY_DSN:
sample_rate=SETUP.SENTRY_SAMPLE_RATE, sample_rate=SETUP.SENTRY_SAMPLE_RATE,
send_default_pii=True, send_default_pii=True,
environment=SETUP.ENVIRONMENT, environment=SETUP.ENVIRONMENT,
_experiments=sentry_experiments,
) )
sentry_sdk.set_tag("takahe.version", __version__) sentry_sdk.set_tag("takahe.version", __version__)