Skip to content

feat(telemetry): add OpenTelemetry integration for AI SDK monitoring#10652

Open
junmediatek wants to merge 2 commits intoanomalyco:devfrom
junmediatek:feat/opentelemetry-integration
Open

feat(telemetry): add OpenTelemetry integration for AI SDK monitoring#10652
junmediatek wants to merge 2 commits intoanomalyco:devfrom
junmediatek:feat/opentelemetry-integration

Conversation

@junmediatek
Copy link
Contributor

@junmediatek junmediatek commented Jan 26, 2026

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)

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found potential duplicate PRs related to OpenTelemetry integration:

Related PRs:

  1. PR feat: integrate OpenTelemetry #5245 - feat: integrate OpenTelemetry

    • General OpenTelemetry integration work that may overlap with the current monitoring implementation
  2. PR feat(telemetry): add OpenTelemetry instrumentation with Aspire Dashboard support #6629 - feat(telemetry): add OpenTelemetry instrumentation with Aspire Dashboard support

    • Similar telemetry feature with OpenTelemetry but targeting Aspire Dashboard instead of Jaeger/Tempo. May have overlapping implementation or configuration logic.

These PRs should be reviewed to determine if they:

  • Cover the same functionality (OTLP endpoint configuration, trace initialization, etc.)
  • Have been merged already and this is a duplicate effort
  • Address different deployment targets that should be consolidated

@junmediatek
Copy link
Contributor Author

hi Hi @thdxr, @adamdotdevin, and @rekram1-node
Could help to review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant