-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsentry.py
40 lines (34 loc) · 1.46 KB
/
sentry.py
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
37
38
39
40
import os
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.httpx import HttpxIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from shared.config import get_config
from helpers.version import get_current_version
def is_sentry_enabled() -> bool:
return bool(get_config("services", "sentry", "server_dsn"))
def initialize_sentry() -> None:
version = get_current_version()
version_str = f"worker-{version}"
sentry_dsn = get_config("services", "sentry", "server_dsn")
sentry_sdk.init(
sentry_dsn,
sample_rate=float(os.getenv("SENTRY_PERCENTAGE", 1.0)),
environment=os.getenv("DD_ENV", "production"),
traces_sample_rate=float(os.environ.get("SERVICES__SENTRY__SAMPLE_RATE", 1)),
profiles_sample_rate=float(
os.environ.get("SERVICES__SENTRY__PROFILES_SAMPLE_RATE", 1)
),
integrations=[
CeleryIntegration(monitor_beat_tasks=True),
DjangoIntegration(signals_spans=False),
SqlalchemyIntegration(),
RedisIntegration(cache_prefixes=["cache:"]),
HttpxIntegration(),
],
release=os.getenv("SENTRY_RELEASE", version_str),
)
if os.getenv("CLUSTER_ENV"):
sentry_sdk.set_tag("cluster", os.getenv("CLUSTER_ENV"))