Class: ActionAgent::Api::TraceReportsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ActionAgent::ApplicationController
- BaseController
- ActionAgent::Api::TraceReportsController
- Defined in:
- app/controllers/action_agent/api/trace_reports_controller.rb
Overview
Read API for telemetry traces, backing the dashboard's Traces view.
Query logic mirrors the server-rendered TracesController (same scopes on ActionAgent.trace_model), scoped to the caller's tenant. Named apart from Api::TracesController because that one is the ingest endpoint: same /api/traces path, different verb and different auth.
Constant Summary collapse
- DEFAULT_WINDOW_MINUTES =
60- MAX_WINDOW_MINUTES =
60 * 24 * 90
- DEFAULT_LIMIT =
500
Instance Method Summary collapse
-
#index ⇒ Object
GET /api/traces.
-
#show ⇒ Object
GET /api/traces/:id — accepts the record id or the OTel trace_id (full or 8-char short form), so generation refs can deep-link.
Methods inherited from ActionAgent::ApplicationController
Instance Method Details
#index ⇒ Object
GET /api/traces
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/action_agent/api/trace_reports_controller.rb', line 19 def index window = params.fetch(:minutes, DEFAULT_WINDOW_MINUTES).to_i.clamp(1, MAX_WINDOW_MINUTES) window_scope = traces_scope.for_date_range(window.minutes.ago, Time.current) scope = window_scope scope = scope.for_agent(params[:agent]) if params[:agent].present? scope = scope.for_service(params[:service]) if params[:service].present? scope = scope.with_errors if params[:status] == "error" limit = params.fetch(:limit, DEFAULT_LIMIT).to_i.clamp(1, 1000) traces = scope.recent.limit(limit) render json: { traces: traces.map { |trace| TelemetryTraceSerializer.summary(trace) }, agents: window_scope.distinct.pluck(:agent_class).compact.sort, # agent_class => platform Agent id, so the Traces view can link a # trace back to the agent it belongs to (AgentRegistrar attributes # SDK-reported traces to an Agent record on ingest). agent_ids: agent_ids_by_class(window_scope), window_minutes: window } end |
#show ⇒ Object
GET /api/traces/:id — accepts the record id or the OTel trace_id (full or 8-char short form), so generation refs can deep-link.
44 45 46 47 48 49 |
# File 'app/controllers/action_agent/api/trace_reports_controller.rb', line 44 def show trace = traces_scope.find_by(trace_id: params[:id]) || traces_scope.where("trace_id LIKE ?", "#{ActionAgent.trace_model.sanitize_sql_like(params[:id].to_s)}%").first || traces_scope.find(params[:id]) render json: { trace: TelemetryTraceSerializer.detail(trace) } end |