forked from elementsinteractive/lightman-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry.py
More file actions
32 lines (26 loc) · 1.04 KB
/
sentry.py
File metadata and controls
32 lines (26 loc) · 1.04 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
import logging
import os
from importlib import metadata
logger = logging.getLogger("lightman")
def configure_sentry(log_level: int) -> None:
"""Configure Sentry for error tracking."""
try:
import sentry_sdk # noqa: PLC0415
from sentry_sdk.integrations.logging import LoggingIntegration # noqa: PLC0415
except ImportError:
if os.getenv("SENTRY_DSN"):
logger.warning(
"Could not initialize sentry, it is not installed! Add it by installing the project with `lightman-ai[sentry]`."
)
return
if not os.getenv("SENTRY_DSN"):
logger.warning("SENTRY_DSN not configured, skipping Sentry initialization")
return
try:
sentry_logging = LoggingIntegration(level=logging.INFO, event_level=log_level)
sentry_sdk.init(
release=metadata.version("lightman-ai"),
integrations=[sentry_logging],
)
except Exception as e:
logger.warning("Could not instantiate Sentry! %s.\nContinuing with the execution.", e)