Skip to content

feat(analytics): add Prometheus metrics plugin#8315

Closed
androolloyd wants to merge 1 commit intoanomalyco:devfrom
androolloyd:feat/analytics-plugin
Closed

feat(analytics): add Prometheus metrics plugin#8315
androolloyd wants to merge 1 commit intoanomalyco:devfrom
androolloyd:feat/analytics-plugin

Conversation

@androolloyd
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor

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

No duplicate PRs found

@github-actions
Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions bot closed this Mar 15, 2026
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