Registry / devops / opencode-otel

opencode-otel

JSON →
library1.2.1jsnpmunverified

OpenCode plugin that forwards runtime stderr logs to any OTLP-compatible log collector via gRPC or HTTP. Current stable version is 1.2.1. It integrates with the OpenCode agent by monkey-patching process.stderr.write, parsing each line for severity, and emitting it as an OTLP LogRecord. Key differentiators include tight integration with BAT/Captain environment variable contracts, automatic backfilling of service identity from runtime metadata, and safe ignoring of unsupported signals (metrics). Peer dependency on @opencode-ai/plugin >=1.1.0.

npm install opencode-otel
INSTALL
IMPORT
SIG · OPENCODE-OTEL
O
opencode-otel
devopsjavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpencodeOtelPlugin
import { OpencodeOtelPlugin } from 'opencode-otel'
The plugin class is exported as a named export. No default export.
package (CommonJS require)
const { OpencodeOtelPlugin } = require('opencode-otel')
const OpencodeOtelPlugin = require('opencode-otel')
The package does not have a default export; must destructure from CommonJS require.
OpencodeOtelPlugin (type import)
import type { OpencodeOtelPlugin } from 'opencode-otel'
import { OpencodeOtelPlugin } from 'opencode-otel' // when only type is needed
For TypeScript type-only imports, use import type to avoid runtime side effects. This package ships types.

Demonstrates importing the plugin class and manual configuration with environment variable defaults.

// Ensure @opencode-ai/plugin is installed (peer dep) // Add to ~/.config/opencode/opencode.json: {"plugin": ["opencode-otel"]} // Then set OTLP environment variables before starting OpenCode import { OpencodeOtelPlugin } from 'opencode-otel'; // The plugin is automatically loaded through OpenCode's plugin system. // Manual instantiation example: const plugin = new OpencodeOtelPlugin(); // Custom configuration (optional, uses OTEL env vars by default) // plugin.configure({ // logsEndpoint: process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT ?? 'http://localhost:4318', // protocol: 'grpc', // serviceName: 'my-agent', // resourceAttributes: { 'service.name': 'my-agent' } // });
Debug
Known issues
breakingPeer dependency @opencode-ai/plugin must be >=1.1.0. Older versions may not support this plugin.
fix
Update @opencode-ai/plugin to >=1.1.0
affects: >=1.0.0 <1.1.0 of @opencode-ai/plugin
gotchaThe plugin monkey-patches process.stderr.write at initialization. If another package also patches stderr, order of plugin loading may cause conflicts or loss of logs.
fix
Ensure opencode-otel is loaded before other stderr patching plugins, or avoid multiple stderr monkeys.
affects: >=1.0.0
deprecatedOTEL_EXPORTER_OTLP_METRICS_ENDPOINT and related metrics env vars are tolerated but ignored; setting them may cause confusion.
fix
Do not rely on metrics being forwarded; use a dedicated metrics plugin if needed.
affects: >=1.0.0
gotchaIf no logs endpoint is configured (OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is not set), the plugin remains inactive and does not install the stderr interceptor. This may cause silent log loss.
fix
Ensure OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is set for the plugin to activate.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module '@opencode-ai/plugin' or its corresponding type declarations.
Missing or outdated peer dependency @opencode-ai/plugin
fix
npm install @opencode-ai/plugin@^1.1.0
TypeError: OpencodeOtelPlugin is not a constructor
CommonJS require without destructuring; package has no default export
fix
const { OpencodeOtelPlugin } = require('opencode-otel');
Cannot read properties of undefined (reading 'write')
Plugin attempted to patch process.stderr before initialization or in an environment without a standard stderr (e.g., certain test runners or headless environments)
fix
Ensure the plugin is loaded after process is fully initialized, or check if stderr is available.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
@opencode-ai/pluginoptionalRequired peer dependency for OpenCode plugin compatibility
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
2
Amazon
1
Resources
opencode-otel — npm install opencode-otel · libregistry