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: synchronous processing; unauthenticated unless ActiveAgent::Dashboard.ingest_api_key is set (set it whenever the mount is reachable beyond your own machine)
  • Multi-tenant mode: per-account Bearer token auth, async processing via job

Examples:

Local mode request

POST <mount>/api/traces  (e.g. /activeagents/api/traces)
Content-Type: application/json

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

Multi-tenant mode request

POST <mount>/api/traces  (e.g. /activeagents/api/traces)
Authorization: Bearer <api_key>
Content-Type: application/json

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

Constant Summary collapse

MAX_TRACES_PER_REQUEST =

Maximum traces accepted per request (mirrors ProcessTelemetryTracesJob::MAX_TRACES_PER_JOB).

100

Instance Method Summary collapse

Instance Method Details

#createObject

POST /api/traces (e.g. /activeagents/api/traces)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_agent/dashboard/app/controllers/active_agent/dashboard/api/traces_controller.rb', line 46

def create
  traces = Array(params[:traces]).take(MAX_TRACES_PER_REQUEST)
  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