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:
parent
d6edb747d2
commit
25912eac0c
5 changed files with 22 additions and 28 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue