Skip to content

Commit

Permalink
feat: Initial Sentry support
Browse files Browse the repository at this point in the history
This change initializes the Sentry SDK, which enables error tracking
when the `SENTRY_DSN` environment variable is set.

Drop-in alternatives to Sentry are also supported, like GlitchTip.
  • Loading branch information
adamantike committed Dec 27, 2024
1 parent 48f3a09 commit 24b9b91
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 3 deletions.
3 changes: 3 additions & 0 deletions backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@ def str_to_bool(value: str) -> bool:
FORCE_COLOR: Final = str_to_bool(os.environ.get("FORCE_COLOR", "false"))
NO_COLOR: Final = str_to_bool(os.environ.get("NO_COLOR", "false"))

# SENTRY
SENTRY_DSN: Final = os.environ.get("SENTRY_DSN", None)

# TESTING
IS_PYTEST_RUN: Final = bool(os.environ.get("PYTEST_VERSION", False))
7 changes: 7 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import alembic.config
import endpoints.sockets.scan # noqa
import sentry_sdk
import uvicorn
from config import (
DEV_HOST,
DEV_PORT,
DISABLE_CSRF_PROTECTION,
IS_PYTEST_RUN,
ROMM_AUTH_SECRET_KEY,
SENTRY_DSN,
)
from endpoints import (
auth,
Expand Down Expand Up @@ -48,6 +50,11 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
yield


sentry_sdk.init(
dsn=SENTRY_DSN,
release="romm@" + get_version(),
)

app = FastAPI(
title="RomM API",
version=get_version(),
Expand Down
8 changes: 8 additions & 0 deletions backend/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import sentry_sdk
from config import SENTRY_DSN
from logger.logger import log
from tasks.scan_library import scan_library_task
from tasks.tasks import tasks_scheduler
from tasks.update_switch_titledb import update_switch_titledb_task
from utils import get_version

sentry_sdk.init(
dsn=SENTRY_DSN,
release="romm@" + get_version(),
)

if __name__ == "__main__":
# Initialize the tasks
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def get_version() -> str:
"""Returns current version tag"""
if not __version__ == "<version>":
if __version__ != "<version>":
return __version__

return "development"
8 changes: 8 additions & 0 deletions backend/watcher.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import os
from datetime import timedelta

import sentry_sdk
from config import (
ENABLE_RESCAN_ON_FILESYSTEM_CHANGE,
LIBRARY_BASE_PATH,
RESCAN_ON_FILESYSTEM_CHANGE_DELAY,
SENTRY_DSN,
)
from config.config_manager import config_manager as cm
from endpoints.sockets.scan import scan_platforms
from handler.database import db_platform_handler
from handler.scan_handler import ScanType
from logger.logger import log
from tasks.tasks import tasks_scheduler
from utils import get_version
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer

sentry_sdk.init(
dsn=SENTRY_DSN,
release="romm@" + get_version(),
)

path = (
cm.get_config().HIGH_PRIO_STRUCTURE_PATH
if os.path.exists(cm.get_config().HIGH_PRIO_STRUCTURE_PATH)
Expand Down
9 changes: 9 additions & 0 deletions backend/worker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import sentry_sdk
from config import SENTRY_DSN
from handler.redis_handler import redis_client
from rq import Connection, Queue, Worker
from utils import get_version

listen = ["high", "default", "low"]

sentry_sdk.init(
dsn=SENTRY_DSN,
release="romm@" + get_version(),
)


if __name__ == "__main__":
# Start the worker
with Connection(redis_client):
Expand Down
58 changes: 56 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ python-magic = "^0.4.27"
# TODO: Move back to `py7zr` official releases, once the following PR is merged and released:
# https://github.com/miurahr/py7zr/pull/620
py7zr = { git = "https://github.com/adamantike/py7zr.git", rev = "54b68426" }
sentry-sdk = "^2.19"
streaming-form-data = "^1.16.0"
zipfile-deflate64 = "^0.2.0"
colorama = "^0.4.6"
Expand Down

0 comments on commit 24b9b91

Please sign in to comment.