Skip to content

feat: add telemetry engine for distributed tracing#326

Open
TonsOfFun wants to merge 3 commits intomainfrom
feat/telemetry-engine
Open

feat: add telemetry engine for distributed tracing#326
TonsOfFun wants to merge 3 commits intomainfrom
feat/telemetry-engine

Conversation

@TonsOfFun
Copy link
Copy Markdown
Contributor

Summary

Adds a comprehensive telemetry system for collecting and reporting agent traces to hosted or self-hosted observability endpoints. This is competitive with Phoenix Arize but built natively for Rails.

Features:

  • Trace collection with spans for generation lifecycle (prompt, llm, tool, error)
  • Token usage tracking (input, output, thinking tokens)
  • Tool call tracing with timing and results
  • Error recording with backtraces
  • Async HTTP reporting with batching and background flush
  • Configurable sampling rate for production traffic
  • Auto-instrumentation via railtie when enabled

Configuration via YAML:

telemetry:
  enabled: true
  endpoint: https://api.activeagents.ai/v1/traces
  api_key: your-api-key
  sample_rate: 1.0
  batch_size: 100
  flush_interval: 5

Or programmatically:

ActiveAgent::Telemetry.configure do |config|
  config.enabled = true
  config.endpoint = "https://api.activeagents.ai/v1/traces"
  config.api_key = Rails.application.credentials.dig(:activeagents, :api_key)
end

Files added:

  • lib/active_agent/telemetry.rb - Main module with NullSpan for disabled state
  • lib/active_agent/telemetry/configuration.rb - Configuration options
  • lib/active_agent/telemetry/span.rb - Span with attributes, tokens, events
  • lib/active_agent/telemetry/tracer.rb - Trace management with thread-local context
  • lib/active_agent/telemetry/reporter.rb - Async HTTP reporter with batching
  • lib/active_agent/telemetry/instrumentation.rb - Auto-instrumentation module
  • docs/framework/telemetry.md - Comprehensive documentation

Test plan

  • Test telemetry disabled by default (no impact on existing behavior)
  • Test YAML configuration loading
  • Test programmatic configuration
  • Test span creation and hierarchy
  • Test token tracking
  • Test error recording
  • Test async reporting doesn't block generation
  • Test sampling rate works correctly

🤖 Generated with Claude Code

TonsOfFun and others added 3 commits March 29, 2026 10:03
Adds a comprehensive telemetry system for collecting and reporting agent traces
to hosted or self-hosted observability endpoints.

Features:
- Trace collection with spans for generation lifecycle
- Token usage tracking (input, output, thinking)
- Tool call tracing with timing
- Error recording with backtraces
- Async HTTP reporting with batching
- Configurable sampling rate
- Auto-instrumentation via railtie

Configuration via YAML:
  telemetry:
    enabled: true
    endpoint: https://api.activeagents.ai/v1/traces
    api_key: your-api-key
    sample_rate: 1.0

Or programmatically:
  ActiveAgent::Telemetry.configure do |config|
    config.enabled = true
    config.endpoint = "https://..."
    config.api_key = "..."
  end

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This adds a Rails Engine to the ActiveAgent gem that provides:
- TelemetryTrace model for storing traces
- TracesController for viewing traces in a dashboard
- API::TracesController for ingesting traces
- ProcessTelemetryTracesJob for async trace processing
- ERB views with Tailwind CSS for the dashboard UI
- Install generator for migrations and configuration

The dashboard supports two modes:
- Local mode: Single-tenant, no auth, synchronous processing
- Multi-tenant mode: Account association, API key auth, async processing

Configuration options:
- multi_tenant: Enable multi-tenant mode
- account_class: Class name for Account model
- current_account_method: Controller method to get current account
- trace_model_class: Custom trace model class
- use_inertia: Enable React/Inertia frontend
- authentication_method: Custom auth callback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The method name 'create_migration' conflicts with
ActiveRecord::Generators::Migration module internals.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant