Fix metric imports: use module-level access instead of name imports

Type-annotated metric variables (e.g. `geojson_cache_operations: Counter`)
don't exist as importable names until init_metrics() runs.  Switch all
`from api.metrics import <metric>` to `import api.metrics as m` and
access instruments as attributes at runtime to avoid ImportError.
This commit is contained in:
Viktor Barzin 2026-02-14 11:21:49 +00:00
parent d6edb747d2
commit 25912eac0c
No known key found for this signature in database
GPG key ID: 0EB088298288D958
5 changed files with 22 additions and 28 deletions

View file

@ -159,8 +159,8 @@ def reset_throttle_metrics() -> None:
def _increment_throttle_metric(event_type: str) -> None:
"""Safely increment the OTel throttle counter if metrics are initialised."""
try:
from api.metrics import throttle_events_total
throttle_events_total.add(1, {"type": event_type})
import api.metrics as m
m.throttle_events_total.add(1, {"type": event_type})
except Exception:
pass # Metrics not yet initialised (e.g. during tests)