fix(sentry): initialize Sentry after DB settings are loaded in lifespan

Move init_sentry() from module level into the FastAPI lifespan context
manager, immediately after load_settings_from_db() completes. This
ensures that SENTRY_DSN and other Sentry settings configured via the
database admin UI are picked up on every restart.

Also update tests and docs accordingly.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-08 22:17:18 +00:00
parent 034876afbb
commit 5864a4ed06
3 changed files with 39 additions and 7 deletions
+4 -4
View File
@@ -48,10 +48,6 @@ SESSION_SECRET = (
settings.session_secret or "INSECURE_DEFAULT_FOR_DEVELOPMENT_ONLY_DO_NOT_USE_IN_PRODUCTION_MINIMUM_32_CHARS"
)
# Initialise Sentry as early as possible so that any startup errors are captured
init_sentry()
@asynccontextmanager
async def lifespan(app: FastAPI):
"""
@@ -74,6 +70,10 @@ async def lifespan(app: FastAPI):
finally:
db.close()
# Initialize Sentry after DB settings are loaded so that values configured
# via the database UI (e.g. SENTRY_DSN) are respected in addition to env vars.
init_sentry()
# Ensure OCR language data is available (background download, non-blocking)
from app.utils.ocr_language_manager import ensure_ocr_languages_async