feat(ocr): suppress uvicorn access logs for /metrics and /health
Adds a logging.Filter on uvicorn.access that drops records whose request path is /metrics or /health. Each is hit on a tight schedule (Prometheus scrape interval and Docker healthcheck), so unfiltered they dominate the access log without carrying any information about real traffic. Refs #652 (Nora's recommendation) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,6 +82,23 @@ app = FastAPI(title="Familienarchiv OCR Service", lifespan=lifespan)
|
||||
Instrumentator(excluded_handlers=["/health", "/metrics"]).instrument(app).expose(app)
|
||||
|
||||
|
||||
class MetricsPathFilter(logging.Filter):
|
||||
"""Drop uvicorn.access entries for /metrics and /health to keep logs focused."""
|
||||
|
||||
_SUPPRESSED_PATHS = {"/metrics", "/health"}
|
||||
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
# uvicorn.access formats as: '%s - "%s %s HTTP/%s" %d'
|
||||
if record.args and len(record.args) >= 3:
|
||||
path = record.args[2]
|
||||
if isinstance(path, str) and path in self._SUPPRESSED_PATHS:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
logging.getLogger("uvicorn.access").addFilter(MetricsPathFilter())
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
"""Health endpoint — returns 200 only after models are loaded."""
|
||||
|
||||
Reference in New Issue
Block a user