[PR #10652] feat(telemetry): add OpenTelemetry integration for AI SDK monitoring #13515

Open
opened 2026-02-16 18:18:22 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10652

State: open
Merged: No


Summary

Implement complete OpenTelemetry monitoring integration allowing users to send AI call traces to Jaeger, Grafana Tempo, and other OTLP-compatible backends.

Changes

Core Implementation

  • Add OpenTelemetry SDK dependencies (@opentelemetry/sdk-node, @opentelemetry/exporter-trace-otlp-http, etc.)
  • Create telemetry module (config.ts, provider.ts) for SDK management
  • Initialize telemetry in InstanceBootstrap with automatic shutdown on exit

Configuration

  • Extend experimental.openTelemetry from boolean to full configuration object
  • Support both simple (boolean) and detailed configuration
  • Add environment variable support (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME)
  • Auto-append /v1/traces to endpoint URLs for user convenience

Integration

  • Integrate tracer into LLM stream calls (llm.ts) with session metadata
  • Integrate tracer into Agent generation (agent.ts) with user metadata
  • Pass functionId and metadata to distinguish different call types
  • Add LOC (Lines of Code) statistics tracking for file modification tools

Configuration Example

{
  "experimental": {
    "openTelemetry": {
      "enabled": true,
      "endpoint": "http://localhost:4318",
      "serviceName": "opencode",
      "sampleRate": 1.0,
      "recordInputs": true,
      "recordOutputs": true
    }
  }
}

Tracked Data

AI Operations

  • Model ID, provider, operation type
  • Token usage (prompt/completion)
  • Session ID, agent name, user ID
  • Tool calls with arguments
  • Request duration and spans

File Modifications (LOC Tracking)

  • File path and tool name (edit/write/apply_patch)
  • Lines added, deleted, and net change
  • Change type (add/update/delete/move)
  • Batch operations with aggregated statistics

Test Plan

  • Type checking passes
  • Telemetry initializes correctly
  • Endpoint URL normalization works
  • Configuration parsing handles both boolean and object forms
  • Related tests passed (edit, write, apply_patch)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10652 **State:** open **Merged:** No --- ## Summary Implement complete OpenTelemetry monitoring integration allowing users to send AI call traces to Jaeger, Grafana Tempo, and other OTLP-compatible backends. ## Changes ### Core Implementation - Add OpenTelemetry SDK dependencies (@opentelemetry/sdk-node, @opentelemetry/exporter-trace-otlp-http, etc.) - Create telemetry module (config.ts, provider.ts) for SDK management - Initialize telemetry in InstanceBootstrap with automatic shutdown on exit ### Configuration - Extend `experimental.openTelemetry` from boolean to full configuration object - Support both simple (boolean) and detailed configuration - Add environment variable support (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME) - Auto-append /v1/traces to endpoint URLs for user convenience ### Integration - Integrate tracer into LLM stream calls (llm.ts) with session metadata - Integrate tracer into Agent generation (agent.ts) with user metadata - Pass functionId and metadata to distinguish different call types - **Add LOC (Lines of Code) statistics tracking for file modification tools** ## Configuration Example ```jsonc { "experimental": { "openTelemetry": { "enabled": true, "endpoint": "http://localhost:4318", "serviceName": "opencode", "sampleRate": 1.0, "recordInputs": true, "recordOutputs": true } } } ``` ## Tracked Data ### AI Operations - Model ID, provider, operation type - Token usage (prompt/completion) - Session ID, agent name, user ID - Tool calls with arguments - Request duration and spans ### File Modifications (LOC Tracking) - File path and tool name (edit/write/apply_patch) - Lines added, deleted, and net change - Change type (add/update/delete/move) - Batch operations with aggregated statistics ## Test Plan - [x] Type checking passes - [x] Telemetry initializes correctly - [x] Endpoint URL normalization works - [x] Configuration parsing handles both boolean and object forms - [x] Related tests passed (edit, write, apply_patch)
yindo added the pull-request label 2026-02-16 18:18:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13515