Skip to content

counters

azure_bootstrap.counters

Best-effort process-local counters.

Used by the alerts dispatcher, tracing decorator, OpenAI tracker, etc. to record observability events without taking a hard dependency on any metrics backend. The values are surfaced via counter_snapshot() and the metrics endpoint in azure_bootstrap.metrics.

Functions:

Name Description
bump_counter

Thread-safe increment. Never raises.

counter_snapshot

Return a copy of the counter map.

bump_counter

bump_counter(name: str, n: int = 1) -> None

Thread-safe increment. Never raises.

Source code in azure_bootstrap/counters/__init__.py
def bump_counter(name: str, n: int = 1) -> None:
    """Thread-safe increment. Never raises."""
    if not isinstance(name, str) or not name:
        return
    try:
        with _lock:
            _counters[name] = _counters.get(name, 0) + int(n)
    except Exception:
        pass

counter_snapshot

counter_snapshot() -> dict[str, int]

Return a copy of the counter map.

Source code in azure_bootstrap/counters/__init__.py
def counter_snapshot() -> dict[str, int]:
    """Return a copy of the counter map."""
    with _lock:
        return dict(_counters)