opencode
opencode copied to clipboard
feat(analytics): add Prometheus metrics plugin
Summary
Adds @opencode-ai/analytics plugin that provides Prometheus-compatible metrics for OpenCode observability.
Changes
- New
packages/analyticspackage with:-
tool.execute.before/tool.execute.afterhooks for timing tool executions -
eventhooks for session tracking - Prometheus exposition format output
-
metricstool to retrieve current metrics
-
Metrics Exposed
Counters
-
opencode_tool_calls_total{tool, status}- Tool calls by name and status -
opencode_messages_total{type}- Messages by type -
opencode_errors_total{type}- Errors by type
Histograms
-
opencode_tool_duration_ms{tool}- Tool execution duration
Gauges
-
opencode_sessions_active- Active session count -
opencode_tool_calls_inflight{tool}- In-flight tool calls
Usage
{
"plugin": ["@opencode-ai/analytics"]
}
Then use the metrics tool to get Prometheus-format output.
Motivation
Enables observability for OpenCode deployments - track tool performance, identify slow tools, monitor session activity, and integrate with existing Prometheus/Grafana infrastructure.