Skip to content

feat(observability): add Prometheus /metrics endpoint (Phase 10) - #511

Open
JesseJohn7 wants to merge 1 commit into
AyinkxLab:mainfrom
JesseJohn7:feat/prometheus-metrics-476
Open

JesseJohn7 wants to merge 1 commit into
AyinkxLab:mainfrom
JesseJohn7:feat/prometheus-metrics-476

Conversation

@JesseJohn7

Copy link
Copy Markdown

Summary

Adds a Prometheus-compatible /metrics endpoint publishing request, token and cost counters in the text exposition format.

Changes

  • New app/observability/ package:
    • metrics.py: small thread-safe counter registry and text exposition renderer (no new dependencies).
    • routes.py: GET /metrics (text/plain; version=0.0.4, Cache-Control: no-store), disabled with 404 when METRICS_ENABLED is false.
    • __init__.py: init_observability(app) registers the route and counts requests in after_request.
  • Metrics exposed:
    • http_requests_total{method,endpoint,status}
    • llm_tokens_total{provider,model,direction}
    • llm_cost_usd_total{provider,model}
  • Token and cost usage is recorded via record_usage(...) where assistant messages are saved.
  • docs/observability.md updated to reflect what is now implemented.

Bounded and fast

  • Scrapes only read in-memory counters; no database queries.
  • endpoint label is the Flask route pattern (unmatched paths share one unmatched series), and status is grouped (2xx, 4xx).
  • Each metric is capped at 500 label combinations; extra series fold into an other label.

Tests

tests/test_metrics.py covers HELP/TYPE lines, sample lines, label escaping, negative increments, the cardinality cap, content type, validity of every line, route-pattern labeling, token/cost counters, and the disabled switch.

ruff check ., black --check . and pytest all pass locally.

Closes #476

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@JesseJohn7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 10: Prometheus metrics endpoint

1 participant