from __future__ import annotations from fastapi import FastAPI from prometheus_fastapi_instrumentator import Instrumentator from app.core.config import settings def setup_metrics(app: FastAPI) -> None: """Configure Prometheus metrics instrumentation.""" if not settings.prometheus_enabled: return instrumentator = Instrumentator( should_group_status_codes=True, should_ignore_untemplated=True, should_respect_env_var=False, excluded_handlers=["/metrics", "/api/v1/health", "/docs", "/openapi.json"], env_var_name="PROMETHEUS_ENABLED", inprogress_name="docengine_inprogress_requests", inprogress_labels=True, ) instrumentator.instrument(app).expose( app, endpoint="/metrics", include_in_schema=False, should_gzip=True, )