Skip to content
    ↑↓ select↵ openesc close
    English中文
    KlimentP

    Posthog Observability

    v0.1.5Observability
    opencode-posthog-observability

    OpenCode plugin that sends AI observability telemetry to PostHog.

    GitHub stars

    0

    Monthly installs

    50

    9 in 7 days

    Composite scoreSCORE

    28.5

    Multi-signal model

    Last commit

    1 month ago

    2026-07-08

    Install and configure

    opencode.json

    Writes to this project's opencode.json — applies to this repository only.

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-posthog-observability@0.1.5"]
    }

    opencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.

    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_TOKEN or POSTHOG_PROJECT_TOKEN
    • OPENCODE_POSTHOG_HOST
    • OPENCODE_POSTHOG_DISTINCT_ID
    • OPENCODE_POSTHOG_AGENT_NAME
    • OPENCODE_POSTHOG_PROJECT_NAME
    • OPENCODE_POSTHOG_CAPTURE_INPUTS
    • OPENCODE_POSTHOG_CAPTURE_OUTPUTS
    • OPENCODE_POSTHOG_CAPTURE_METADATA
    • OPENCODE_POSTHOG_MAX_TEXT_LENGTH
    • OPENCODE_POSTHOG_DIAGNOSTICS
    • OPENCODE_POSTHOG_FLUSH_TIMEOUT_MS
    • OPENCODE_POSTHOG_TAGS as key=value,team=ai or 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"]
    }