opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(analytics): add Prometheus metrics plugin

Open androolloyd opened this issue 1 day ago • 2 comments

Summary

Adds @opencode-ai/analytics plugin that provides Prometheus-compatible metrics for OpenCode observability.

Changes

  • New packages/analytics package with:
    • tool.execute.before / tool.execute.after hooks for timing tool executions
    • event hooks for session tracking
    • Prometheus exposition format output
    • metrics tool 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.

androolloyd avatar Jan 14 '26 00:01 androolloyd