opencode-posthog-observability
v0.1.5
Published
OpenCode plugin that sends AI observability telemetry to PostHog.
Downloads
310
Maintainers
Readme
opencode-posthog-observability
OpenCode plugin that sends AI generation telemetry to PostHog AI Observability.
Each completed OpenCode assistant message is captured as one PostHog $ai_generation event. Completed and failed OpenCode tool calls are captured as child $ai_span events. The plugin keeps each generation as its own trace while grouping related turns with the OpenCode session ID.
Install
npm install opencode-posthog-observabilityAdd the plugin to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability"]
}Set your PostHog project token:
export OPENCODE_POSTHOG_PROJECT_TOKEN=phc_your_project_tokenFor EU projects, set:
export OPENCODE_POSTHOG_HOST=https://eu.i.posthog.comConfiguration
The plugin reads config from the first file it finds:
OPENCODE_POSTHOG_CONFIG.opencode/posthog-observability.json.opencode/posthog-observability.jsonc.opencode/opencode-posthog-observability.json.opencode/opencode-posthog-observability.jsonc- matching files in your global OpenCode config directory
Example:
{
"projectToken": "phc_your_project_token",
"host": "https://us.i.posthog.com",
"distinctId": "opencode",
"projectName": "my-project",
"agentName": "opencode",
"captureInputs": true,
"captureOutputs": true,
"captureMetadata": true,
"maxTextLength": 12000,
"diagnostics": false,
"tags": {
"env": "local"
}
}Environment variables override file config:
OPENCODE_POSTHOG_PROJECT_TOKENorPOSTHOG_PROJECT_TOKENOPENCODE_POSTHOG_HOSTOPENCODE_POSTHOG_DISTINCT_IDOPENCODE_POSTHOG_AGENT_NAMEOPENCODE_POSTHOG_PROJECT_NAMEOPENCODE_POSTHOG_CAPTURE_INPUTSOPENCODE_POSTHOG_CAPTURE_OUTPUTSOPENCODE_POSTHOG_CAPTURE_METADATAOPENCODE_POSTHOG_MAX_TEXT_LENGTHOPENCODE_POSTHOG_DIAGNOSTICSOPENCODE_POSTHOG_FLUSH_TIMEOUT_MSOPENCODE_POSTHOG_TAGSaskey=value,team=aior JSON
Privacy
By default, the plugin captures prompt input, assistant output, tool input/output, model/provider metadata, token counts, latency, OpenCode session/message/tool IDs, and configured tags.
When OpenCode exposes reasoning separately from the final answer, reasoning is sent as its own output entry before the assistant response. This keeps PostHog's conversation view readable without discarding reasoning content.
Disable sensitive content capture when needed:
export OPENCODE_POSTHOG_CAPTURE_INPUTS=false
export OPENCODE_POSTHOG_CAPTURE_OUTPUTS=falseThe plugin redacts common secret-looking object keys before sending metadata or prompt inputs: token, secret, password, authorization, cookie, apiKey, and bearer.
Development
npm install
npm testFor local OpenCode tests before publishing:
npm pack
npm install ./opencode-posthog-observability-0.1.0.tgz --prefix .opencodeThen point local .opencode/opencode.json at the installed artifact:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["./node_modules/opencode-posthog-observability/dist/index.js"]
}