feat(observability): structured logging, metrics wiring, graceful degradation

- Item 5: Convert remaining printf-style logger call to structured logging
  (key=value format) in x402_middleware.py
- Item 6: Wire CACHE_HITS counter into cache get() and per-tier SCRAPE_LATENCY
  histogram into UltimateScraper scrape loop
- Item 7: Add circuit-breaker checks in extractor.py (Ollama) and
  routers/vision.py (OpenRouter) to fail fast and record success/failure
  when external services are down; attach recovery results to resilience
  registry for per-service circuit state

560 tests passing, ruff clean
This commit is contained in:
Crypto Rug Munch 2026-07-03 12:13:03 +02:00
parent 2970c15dbb
commit 5a21133b1d
5 changed files with 20 additions and 1 deletions

View file

@ -12,6 +12,8 @@ import json
import time
from collections import OrderedDict
from observability import CACHE_HITS
class ResponseCache:
"""Two-tier cache: local LRU + optional Redis persistence.
@ -44,6 +46,8 @@ class ResponseCache:
if entry["expires"] > now:
self._hits += 1
self._cache.move_to_end(key)
if CACHE_HITS:
CACHE_HITS.labels(cache_type="local").inc()
return entry["data"]
else:
del self._cache[key]