Skip to content

Conversation

@androolloyd
Copy link

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.

Adds @opencode-ai/analytics plugin that tracks:
- Tool execution counts and timing via tool.execute.before/after hooks
- Session activity via event hooks  
- Prometheus exposition format output

Metrics include counters, histograms, and gauges for observability.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant