-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry_setup.py
More file actions
36 lines (28 loc) · 1.11 KB
/
Copy pathsentry_setup.py
File metadata and controls
36 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Sentry initialization helpers for Flask app."""
from __future__ import annotations
import logging
logger = logging.getLogger(__name__)
def init_sentry(app) -> bool:
"""Initialize Sentry from app config.
Returns True when initialization succeeds and False otherwise.
"""
dsn = str(app.config.get("SENTRY_DSN", "") or "").strip()
if not dsn:
logger.info("Sentry disabled: SENTRY_DSN is empty")
return False
try:
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
except Exception as exc: # pragma: no cover - import failure is deployment issue
logger.warning("Sentry SDK not available: %s", exc)
return False
sentry_sdk.init(
dsn=dsn,
integrations=[FlaskIntegration()],
environment=app.config.get("SENTRY_ENVIRONMENT"),
release=app.config.get("SENTRY_RELEASE"),
send_default_pii=bool(app.config.get("SENTRY_SEND_DEFAULT_PII", False)),
traces_sample_rate=float(app.config.get("SENTRY_TRACES_SAMPLE_RATE", 0.0)),
)
logger.info("Sentry initialized")
return True