Skip to content

stac_auth_proxy.metrics

Optional Prometheus metrics for STAC operations.

classify_operation(method: str, path: str) -> str

Map a request to a low-cardinality STAC operation name.

Source code in src/stac_auth_proxy/metrics.py
37
38
39
40
41
42
def classify_operation(method: str, path: str) -> str:
    """Map a request to a low-cardinality STAC operation name."""
    for pattern, methods in _COMPILED:
        if pattern.match(path):
            return methods.get(method.upper(), "unknown")
    return "unknown"

instrument_app(app: Any, excluded_handlers: Optional[Sequence[str]] = None) -> None

Instrument a FastAPI app and expose Prometheus metrics when available.

Source code in src/stac_auth_proxy/metrics.py
45
46
47
48
49
50
51
52
def instrument_app(
    app: Any,
    excluded_handlers: Optional[Sequence[str]] = None,
) -> None:
    """Instrument a FastAPI app and expose Prometheus metrics when available."""
    if not METRICS_AVAILABLE:
        return
    _instrument_app(app, list(excluded_handlers or []))

record_stac_metrics(info: Info) -> None

Record request count and latency using STAC operation labels.

Source code in src/stac_auth_proxy/metrics.py
72
73
74
75
76
def record_stac_metrics(info: Info) -> None:
    """Record request count and latency using STAC operation labels."""
    operation = classify_operation(info.request.method, info.request.url.path)
    REQUESTS.labels(operation, info.method, info.modified_status).inc()
    LATENCY.labels(operation, info.method).observe(info.modified_duration)