Files
MABEA/backend/app/main.py
T
patrickandClaude Sonnet 5 e5dc80c3a6
CI / backend-tests (push) Successful in 3m14s
CI / frontend-build (push) Successful in 21s
feat(foundation): FOUND-013 optionales Error-Tracking (GlitchTip)
Zielserver-Entscheidung durch optionales Install-Script aufgelöst statt
festgeschrieben: deploy/glitchtip-install.sh installiert GlitchTip per
Docker Compose auf einem beliebigen, selbst gewählten Host - nichts
automatisch/ungefragt.

DSN wird zur Laufzeit über eine neue Admin-GUI-Seite ein-/ausschaltbar
(Systemeinstellung-Singleton, GET/PATCH /einstellungen/sentry), statt
nur per .env - kein Redeploy zum Umschalten nötig. Frontend lädt
@sentry/react nur dynamisch nach, wenn tatsächlich aktiv.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
2026-09-10 19:35:47 +02:00

51 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from contextlib import asynccontextmanager
import sentry_sdk
from fastapi import FastAPI
from slowapi import _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
import app.models # noqa: F401 (alle ORM-Modelle vollständig an Base.metadata
# registrieren, unabhängig davon, welche Endpunkte tatsächlich verdrahtet sind -
# sonst schlägt FK-Auflösung zwischen Modellen fehl, siehe tests/conftest.py)
from app.api.v1.api import api_router
from app.core.app_settings import settings
from app.core.logging_config import konfiguriere_logging
from app.core.rate_limit import limiter
from app.db.session import SessionLocal, engine
from app.services.systemeinstellung import hole_einstellung
konfiguriere_logging()
_PLACEHOLDER_JWT_SECRET = "change-me-to-a-long-random-value"
@asynccontextmanager
async def lifespan(app: FastAPI):
if not settings.jwt_secret_key or settings.jwt_secret_key == _PLACEHOLDER_JWT_SECRET:
raise RuntimeError(
"JWT_SECRET_KEY ist leer oder noch der Platzhalter aus example.env – "
"in .env auf dem Zielsystem einen echten zufälligen Wert setzen."
)
# FOUND-013: per Admin-GUI gesetzter DSN (DB) hat Vorrang vor der
# .env-Variable (Bootstrap-Fallback, z.B. beim allerersten Start ohne
# bereits existierende Systemeinstellung-Zeile).
async with SessionLocal() as db:
einstellung = await hole_einstellung(db)
await db.commit()
dsn = einstellung.sentry_dsn or settings.sentry_dsn
if dsn:
# send_default_pii bewusst False (DSGVO, Art.-9-Bezug bei
# Rettungsdienst) - keine IP-Adressen/Nutzerdaten automatisch mitschicken.
sentry_sdk.init(dsn=dsn, send_default_pii=False, traces_sample_rate=0.0)
yield
await engine.dispose()
app = FastAPI(title="MABEA", version="0.1.0", lifespan=lifespan)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
app.include_router(api_router, prefix="/api/v1")