opencode-posthog-observabilityOpenCode plugin that sends AI observability telemetry to PostHog.
0
50
近 7 天 9
28.5
生态多维模型
1 个月前
2026-07-08
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability@0.1.5"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-posthog-observability@0.1.5"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-posthog-observabilityopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
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-observability
Add 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_token
For EU projects, set:
export OPENCODE_POSTHOG_HOST=https://eu.i.posthog.com
Configuration
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=false
The 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 test
For local OpenCode tests before publishing:
npm pack
npm install ./opencode-posthog-observability-0.1.0.tgz --prefix .opencode
Then point local .opencode/opencode.json at the installed artifact:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["./node_modules/opencode-posthog-observability/dist/index.js"]
}