File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ dependencies = [
3131 ' python-json-logger>=4.0' ,
3232 ' celery[sqlalchemy]' ,
3333 ' asgiref' ,
34+ ' sentry-sdk' ,
3435]
3536
3637[tool .setuptools ]
Original file line number Diff line number Diff line change 66from importlib .resources import files
77from typing import Any , Literal
88
9+ import sentry_sdk
910from alembic import command
1011from alembic .config import Config
1112from fastapi import FastAPI
1213from fastapi .middleware .cors import CORSMiddleware
1314from fastapi .routing import APIRoute
1415from pydantic import BaseModel
16+ from sentry_sdk .integrations .fastapi import FastApiIntegration
17+ from sentry_sdk .integrations .starlette import StarletteIntegration
1518
1619from ..deployment .monitors .health import vm_monitor
1720from .backup import router as backup_router
@@ -89,6 +92,13 @@ def _logging_config() -> dict[str, Any]:
8992logging .config .dictConfig (_logging_config ())
9093logger = logging .getLogger (__name__ )
9194
95+ _sentry_dsn = get_settings ().sentry_dsn
96+ if _sentry_dsn :
97+ sentry_sdk .init (
98+ dsn = _sentry_dsn ,
99+ integrations = [StarletteIntegration (), FastApiIntegration ()],
100+ )
101+
92102
93103class _FastAPI (FastAPI ):
94104 def openapi (self ) -> dict [str , Any ]:
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class Settings(BaseSettings):
2828 )
2929 pitr_wal_retention_days : int = 7
3030 deployment_password_secret : SecretBytes
31+ sentry_dsn : str | None = None
3132
3233
3334@lru_cache
Original file line number Diff line number Diff line change 1+ import sentry_sdk
12from celery import Celery
23from pydantic_settings import BaseSettings , SettingsConfigDict
4+ from sentry_sdk .integrations .celery import CeleryIntegration
35
46
57class Settings (BaseSettings ):
68 model_config = SettingsConfigDict (env_prefix = "vela_" , case_sensitive = False )
79 broker_url : str
810 result_backend : str
11+ sentry_dsn : str | None = None
912
1013
1114_settings = Settings () # type: ignore[call-arg]
1215
16+ if _settings .sentry_dsn :
17+ sentry_sdk .init (dsn = _settings .sentry_dsn , integrations = [CeleryIntegration ()])
18+
1319app = Celery ("vela" , broker = _settings .broker_url , backend = _settings .result_backend )
1420
1521# Persist task name, args, and kwargs in celery_taskmeta so AsyncResult can
You can’t perform that action at this time.
0 commit comments