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.
Before using this plugin, create (or reuse) a Sentry project configured for Node SDK ingestion.
JavaScript -> Node.js@sentry/nodetracesSampleRate > 0) so AI Monitoring spans are storedYou can use an existing Node project if you already have one.
gen_ai.invoke_agent spansgen_ai.execute_tool spans (inputs/outputs optional)message.updated eventsgen_ai.request and gen_ai.invoke_agent spans (gen_ai.request.messages, gen_ai.response.text){
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-sentry-monitor"]
}
{
"dsn": "https://<public-key>@o<org>.ingest.sentry.io/<project-id>",
"tracesSampleRate": 1,
"recordInputs": true,
"recordOutputs": true
}
.opencode/sentry-monitor.json.opencode/sentry-monitor.jsonc~/.config/opencode/sentry-monitor.json~/.config/opencode/sentry-monitor.jsoncRestart OpenCode after installation.
The plugin looks for config in this order:
OPENCODE_SENTRY_CONFIG (explicit file path).opencode/OPENCODE_CONFIG_DIROPENCODE_CONFIG~/.config/opencode~/Library/Application Support/opencode~/AppData/Roaming/opencodeIf no config file exists, environment overrides are still supported:
OPENCODE_SENTRY_DSN (or SENTRY_DSN)OPENCODE_SENTRY_TRACES_SAMPLE_RATEOPENCODE_SENTRY_RECORD_INPUTSOPENCODE_SENTRY_RECORD_OUTPUTSOPENCODE_SENTRY_MAX_ATTRIBUTE_LENGTHOPENCODE_SENTRY_DIAGNOSTICSOPENCODE_SENTRY_FLUSH_TIMEOUT_MSOPENCODE_SENTRY_DEBUGOPENCODE_SENTRY_ENABLE_METRICSOPENCODE_SENTRY_TAGS (format: key:value,key:value)SENTRY_ENVIRONMENTSENTRY_RELEASEtype 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
};
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"
}
}
npm install
npm run typecheck
npm run build
npm publish
recordInputs/recordOutputs are enabled, payloads are redacted and truncated before being attached as span attributes.session.idle and session.deleted.MIT
TypeScript
100.0%
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.
Before using this plugin, create (or reuse) a Sentry project configured for Node SDK ingestion.
JavaScript -> Node.js@sentry/nodetracesSampleRate > 0) so AI Monitoring spans are storedYou can use an existing Node project if you already have one.
gen_ai.invoke_agent spansgen_ai.execute_tool spans (inputs/outputs optional)message.updated eventsgen_ai.request and gen_ai.invoke_agent spans (gen_ai.request.messages, gen_ai.response.text){
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-sentry-monitor"]
}
{
"dsn": "https://<public-key>@o<org>.ingest.sentry.io/<project-id>",
"tracesSampleRate": 1,
"recordInputs": true,
"recordOutputs": true
}
.opencode/sentry-monitor.json.opencode/sentry-monitor.jsonc~/.config/opencode/sentry-monitor.json~/.config/opencode/sentry-monitor.jsoncRestart OpenCode after installation.
The plugin looks for config in this order:
OPENCODE_SENTRY_CONFIG (explicit file path).opencode/OPENCODE_CONFIG_DIROPENCODE_CONFIG~/.config/opencode~/Library/Application Support/opencode~/AppData/Roaming/opencodeIf no config file exists, environment overrides are still supported:
OPENCODE_SENTRY_DSN (or SENTRY_DSN)OPENCODE_SENTRY_TRACES_SAMPLE_RATEOPENCODE_SENTRY_RECORD_INPUTSOPENCODE_SENTRY_RECORD_OUTPUTSOPENCODE_SENTRY_MAX_ATTRIBUTE_LENGTHOPENCODE_SENTRY_DIAGNOSTICSOPENCODE_SENTRY_FLUSH_TIMEOUT_MSOPENCODE_SENTRY_DEBUGOPENCODE_SENTRY_ENABLE_METRICSOPENCODE_SENTRY_TAGS (format: key:value,key:value)SENTRY_ENVIRONMENTSENTRY_RELEASEtype 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
};
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"
}
}
npm install
npm run typecheck
npm run build
npm publish
recordInputs/recordOutputs are enabled, payloads are redacted and truncated before being attached as span attributes.session.idle and session.deleted.MIT
TypeScript
100.0%