npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-sentry-monitor

v0.1.7

Published

Sentry AI Monitoring plugin for OpenCode sessions and tool calls

Downloads

2,542

Readme

opencode-sentry-monitor

Sentry AI Monitoring plugin for OpenCode.

This plugin captures OpenCode session lifecycle, tool execution spans, and assistant token usage into Sentry using AI Monitoring span conventions.

Sentry Project Setup

Before using this plugin, create (or reuse) a Sentry project configured for Node SDK ingestion.

  • Project type: JavaScript -> Node.js
  • Why this type: OpenCode plugins run in a Node runtime, and this plugin uses @sentry/node
  • Required: tracing enabled (tracesSampleRate > 0) so AI Monitoring spans are stored
  • DSN source: Project Settings -> Client Keys (DSN)

You can use an existing Node project if you already have one.

Features

  • Session-level gen_ai.invoke_agent spans
  • Tool-level gen_ai.execute_tool spans (inputs/outputs optional)
  • Assistant token usage spans via message.updated events
  • Model request/response attributes on gen_ai.request and gen_ai.invoke_agent spans (gen_ai.request.messages, gen_ai.response.text)
  • Custom tags on all spans and error reports
  • Unsampled metrics for token usage, response timing, and tool executions
  • Sidecar config file support (no hardcoded DSN required)
  • JSON and JSONC config support
  • Redaction and truncation for large/sensitive payload attributes

Install

  1. Add plugin package to OpenCode config:
{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-sentry-monitor"]
}
  1. Create a plugin config file with your DSN:
{
  "dsn": "https://<public-key>@o<org>.ingest.sentry.io/<project-id>",
  "tracesSampleRate": 1,
  "recordInputs": true,
  "recordOutputs": true
}
  1. Save that file as one of:
  • .opencode/sentry-monitor.json
  • .opencode/sentry-monitor.jsonc
  • ~/.config/opencode/sentry-monitor.json
  • ~/.config/opencode/sentry-monitor.jsonc

Restart OpenCode after installation.

Config Resolution Order

The plugin looks for config in this order:

  1. OPENCODE_SENTRY_CONFIG (explicit file path)
  2. Project .opencode/
  3. OPENCODE_CONFIG_DIR
  4. Directory of OPENCODE_CONFIG
  5. Platform defaults:
    • ~/.config/opencode
    • ~/Library/Application Support/opencode
    • ~/AppData/Roaming/opencode

If no config file exists, environment overrides are still supported:

  • OPENCODE_SENTRY_DSN (or SENTRY_DSN)
  • OPENCODE_SENTRY_TRACES_SAMPLE_RATE
  • OPENCODE_SENTRY_RECORD_INPUTS
  • OPENCODE_SENTRY_RECORD_OUTPUTS
  • OPENCODE_SENTRY_MAX_ATTRIBUTE_LENGTH
  • OPENCODE_SENTRY_DIAGNOSTICS
  • OPENCODE_SENTRY_FLUSH_TIMEOUT_MS
  • OPENCODE_SENTRY_DEBUG
  • OPENCODE_SENTRY_ENABLE_METRICS
  • OPENCODE_SENTRY_TAGS (format: key:value,key:value)
  • SENTRY_ENVIRONMENT
  • SENTRY_RELEASE

Config Reference

type PluginConfig = {
  dsn: string;
  tracesSampleRate?: number; // 0..1, default 1
  environment?: string;
  release?: string;
  debug?: boolean;
  diagnostics?: boolean; // default false
  flushTimeoutMs?: number; // default 5000, 1000..60000
  agentName?: string;
  projectName?: string;
  recordInputs?: boolean; // default true (tool input + model request messages)
  recordOutputs?: boolean; // default true (tool output + model response text)
  maxAttributeLength?: number; // default 12000
  includeMessageUsageSpans?: boolean; // default true
  includeSessionEvents?: boolean; // default true
  enableMetrics?: boolean; // default false
  tags?: Record<string, string>; // custom tags on all spans/metrics
};

Metrics

When enableMetrics: true, the plugin emits Sentry metrics (unsampled, 100% accurate) for usage attribution:

| Metric | Type | Unit | Emitted | |--------|------|------|---------| | gen_ai.client.token.usage | distribution | token | Per assistant message, tagged by token type (input/output/reasoning/cached_input) | | gen_ai.client.response.duration | distribution | millisecond | Per assistant message response time | | gen_ai.client.tool.execution | counter | — | Per tool execution, tagged with status (ok/error) |

All metrics include gen_ai.agent.name, opencode.project.name, gen_ai.request.model, opencode.model.provider, plus any custom tags.

Example config for team attribution:

{
  "dsn": "https://...",
  "enableMetrics": true,
  "agentName": "my-agent",
  "tags": {
    "team": "platform",
    "developer": "sergiy"
  }
}

Local Development

npm install
npm run typecheck
npm run build

Publish

npm publish

Notes

  • DSN is not a secret, but this plugin does not require hardcoding it.
  • If recordInputs/recordOutputs are enabled, payloads are redacted and truncated before being attached as span attributes.
  • AI spans are flushed on session.idle and session.deleted.

License

MIT