opti sentry

This commit is contained in:
Zeecka
2025-12-31 15:58:51 +01:00
parent ddce01ec8d
commit 9c37efb403
+10 -14
View File
@@ -12,35 +12,31 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from sentry_sdk.integrations.threading import ThreadingIntegration from sentry_sdk.integrations.threading import ThreadingIntegration
SENTRY_DSN = os.environ.get("SENTRY_DSN") SENTRY_DSN = os.environ.get("SENTRY_DSN")
ENVIRONMENT = os.environ.get("ENVIRONMENT", "development") SENTRY_ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "development")
SENTRY_TRACES_SAMPLE_RATE = float(os.environ.get("SENTRY_TRACES_SAMPLE_RATE", "0.1"))
SENTRY_PROFILES_SAMPLE_RATE = float(os.environ.get("SENTRY_PROFILES_SAMPLE_RATE", "0.1"))
SENTRY_RELEASE = os.environ.get("SENTRY_RELEASE", "1.0.0")
def initialize_sentry() -> None: def initialize_sentry() -> None:
"""Initialize Sentry SDK once, safely.""" """Initialize Sentry SDK once, safely."""
# No DSN → do nothing # No DSN → do nothing
dsn = os.environ.get("SENTRY_DSN")
if not dsn:
return
# Prevent double initialization (Flask + RQ, CLI, tests, etc.) # Prevent double initialization (Flask + RQ, CLI, tests, etc.)
if sentry_sdk.Hub.current.client is not None: if not SENTRY_DSN or sentry_sdk.Hub.current.client is not None:
return return
sentry_sdk.init( sentry_sdk.init(
dsn=dsn, dsn=SENTRY_DSN,
integrations=[ integrations=[
FlaskIntegration(), FlaskIntegration(),
SqlalchemyIntegration(), SqlalchemyIntegration(),
RqIntegration(), RqIntegration(),
ThreadingIntegration(propagate_hub=True), ThreadingIntegration(propagate_hub=True),
], ],
traces_sample_rate=float(os.environ.get("SENTRY_TRACES_SAMPLE_RATE", "0.1")), traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
profiles_sample_rate=float( profiles_sample_rate=SENTRY_PROFILES_SAMPLE_RATE,
os.environ.get("SENTRY_PROFILES_SAMPLE_RATE", "0.1") environment=SENTRY_ENVIRONMENT,
), release=SENTRY_RELEASE,
environment=os.environ.get("ENVIRONMENT", "development"),
release=os.environ.get("SENTRY_RELEASE", "1.0.0"),
send_default_pii=False, send_default_pii=False,
enable_tracing=True, enable_tracing=True,
) )