feat(metrics): add Prometheus per-tool metrics and ServiceMonitor#39
Open
feat(metrics): add Prometheus per-tool metrics and ServiceMonitor#39
Conversation
- Add chatbot_tool_calls_total, chatbot_tool_duration_seconds, chatbot_tool_errors_total - Instrument tool handler in claude_service._build_sdk_tools - Expose GET /api/metrics endpoint for Prometheus scraping - Add ServiceMonitor manifest for Prometheus Operator - Add prometheus-client dependency and tests Fixes SC-41316 Co-authored-by: Cursor <cursoragent@cursor.com>
|
This pull request has been linked to Shortcut Story #41316: MCP: add per-tool time-series metrics. |
|
The preview deployment for sefaria/ai-chatbot:client is ready. 🟢 Open Preview | Open Build Logs | Open Application Logs Last updated at: 2026-02-22 09:45:01 CET |
- Introduced a new document outlining Prometheus metrics for tracking chatbot tool usage. - Detailed metrics include `chatbot_tool_calls_total`, `chatbot_tool_duration_seconds`, and `chatbot_tool_errors_total`. - Discussed implementation options and potential gaps in current observability. - Aimed to support time-series queries for better monitoring and analysis. Relates to SC-41316
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
Implements SC-41316: Add per-tool time-series metrics for the chatbot agent so usage can be graphed over time in Prometheus/Grafana.
Changes
server/chat/metrics.py):chatbot_tool_calls_total,chatbot_tool_duration_seconds,chatbot_tool_errors_totalclaude_service._build_sdk_toolsrecords metrics on each tool invocationGET /api/metricsexposes Prometheus text formatmanifests/servicemonitor.yamlfor Prometheus Operator (scrapes/api/metrics)server/chat/tests/test_metrics.pydocs/plans/metrics-for-chatbot-agent-tools.md,manifests/README.mdServiceMonitor requirements
The target Service must have:
app.kubernetes.io/name: ai-chatbothttpSee
manifests/README.mdfor details.Fixes SC-41316