Repository navigation
feat: backend metrics collection and request logging - #138
Merged
neuromechanist merged 4 commits intoFeb 2, 2026
Merged
neuromechanist merged 4 commits into
neuromechanist merged 4 commits into
Conversation
- Add src/metrics/ package with SQLite storage (WAL mode),
aggregation queries, and request timing middleware
- Add global /metrics/overview and /metrics/tokens endpoints
- Add per-community /{id}/metrics and /{id}/metrics/usage
- Log token usage, model, key_source, tools for ask/chat
- Streaming handlers log metrics at end of generator
- Middleware captures timing for all requests
- All metrics endpoints require admin auth
Closes #134
- Wrap middleware dispatch in try/except so metrics never crash requests - Wrap init_metrics_db() in try/except for graceful degradation - Always return AssistantWithMetrics (remove return_metrics flag) - Narrow log_request except to sqlite3.Error - Add try/except to _log_streaming_metrics - Log metrics on streaming error paths (400/500) - Add sqlite3 error handling to all metrics endpoints (503) - Add logger + warning for malformed JSON in queries.py - Fix middleware ordering comment - Remove redundant inline import uuid - Move get_metrics_connection to top-level import
Member
Author
PR Review Summary6 specialized review agents analyzed this PR. All critical and important issues have been addressed in commit 0a5dab7. Critical Issues Fixed (4)
Important Issues Fixed (8)
Issues Deferred to Follow-up
Test Results
|
Remove branch filter from pull_request trigger in tests.yml so lint and unit tests run on PRs targeting any branch, not just main/develop. This ensures feature branch PRs to epic branches still get CI coverage.
Skip test_documentation_urls_accessible; HED docs URL returns 404 due to upstream repo change. See #139.
neuromechanist
merged commit Feb 2, 2026
652ba1d
into
feature/issue-132-epic-community-dashboard
3 checks passed
This was referenced Feb 2, 2026
4 tasks
Merged
13 of 14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/metrics/package with SQLite storage (WAL mode), aggregation queries, and request timing middleware/metrics/overviewand/metrics/tokensendpoints (admin auth)/{id}/metricsand/{id}/metrics/usageendpoints (admin auth)Changes
New files
src/metrics/__init__.py- Package initsrc/metrics/db.py- SQLite storage layer (RequestLogEntry,init_metrics_db,log_request,extract_token_usage)src/metrics/queries.py- Aggregation queries (get_community_summary,get_usage_stats,get_overview,get_token_breakdown)src/metrics/middleware.py-MetricsMiddleware(request timing, request_id generation)src/api/routers/metrics.py- Global metrics endpointsModified files
src/api/main.py- Register middleware, init DB in lifespan, include metrics_routersrc/api/routers/__init__.py- Export metrics_routersrc/api/routers/community.py- AddAssistantWithMetrics, metrics logging in handlers, per-community metrics endpointsTests
tests/test_metrics/test_db.py- Storage layer tests (schema, inserts, token extraction)tests/test_metrics/test_queries.py- Aggregation query tests (summaries, bucketing, breakdowns)tests/test_metrics/test_middleware.py- Middleware integration teststests/test_api/test_metrics_endpoints.py- API endpoint tests with authTest plan
Closes #134