Class: ActiveAgent::Dashboard::Api::TracesController

Inherits:
ActionController::API
  • Object
show all
Defined in:
lib/active_agent/dashboard/app/controllers/active_agent/dashboard/api/traces_controller.rb

Overview

Telemetry ingestion endpoint.

Receives traces from ActiveAgent::Telemetry::Reporter and stores them for analysis and visualization in the dashboard.

Supports two modes:

  • Local mode: No authentication, synchronous processing

  • Multi-tenant mode: Bearer token auth, async processing via job

Examples:

Local mode request

POST /active_agent/api/traces
Content-Type: application/json

{
  "traces": [...],
  "sdk": { "name": "activeagent", "version": "0.5.0" }
}

Multi-tenant mode request

POST /active_agent/api/traces
Authorization: Bearer <api_key>
Content-Type: application/json

{
  "traces": [...],
  "sdk": { "name": "activeagent", "version": "0.5.0" }
}

Instance Method Summary collapse

Instance Method Details

#createObject

POST /active_agent/api/traces



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_agent/dashboard/app/controllers/active_agent/dashboard/api/traces_controller.rb', line 38

def create
  traces = params[:traces] || []
  sdk_info = params[:sdk] || {}

  return head :accepted if traces.empty?

  if ActiveAgent::Dashboard.multi_tenant?
    # Multi-tenant mode: process in background
    ActiveAgent::ProcessTelemetryTracesJob.perform_later(
      account_id: @account&.id,
      traces: traces.as_json,
      sdk_info: sdk_info.as_json,
      received_at: Time.current.iso8601(6)
    )
  else
    # Local mode: process synchronously
    process_traces_synchronously(traces, sdk_info)
  end

  head :accepted
rescue ActionController::ParameterMissing => e
  render json: { error: e.message }, status: :bad_request
rescue StandardError => e
  Rails.logger.error("[ActiveAgent::Dashboard] Trace ingestion error: #{e.message}")
  render json: { error: "Internal server error" }, status: :internal_server_error
end