Class: ActionAgent::TelemetryTraceSerializer
- Inherits:
-
Object
- Object
- ActionAgent::TelemetryTraceSerializer
- Defined in:
- app/serializers/action_agent/telemetry_trace_serializer.rb
Overview
Serializes TelemetryTrace records (gem span payloads) into the view-model consumed by the dashboard's TracesView: relative span offsets for the waterfall timeline, nesting depth, and token totals.
Constant Summary collapse
- KNOWN_SPAN_TYPES =
Span types understood by the dashboard timeline (superset of the gem's ActiveAgent::Telemetry::Span::TYPES).
%w[root prompt generate llm tool thinking embedding response error].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #detail ⇒ Object
-
#initialize(trace) ⇒ TelemetryTraceSerializer
constructor
A new instance of TelemetryTraceSerializer.
- #summary ⇒ Object
Constructor Details
#initialize(trace) ⇒ TelemetryTraceSerializer
Returns a new instance of TelemetryTraceSerializer.
20 21 22 |
# File 'app/serializers/action_agent/telemetry_trace_serializer.rb', line 20 def initialize(trace) @trace = trace end |
Class Method Details
.detail(trace) ⇒ Object
16 17 18 |
# File 'app/serializers/action_agent/telemetry_trace_serializer.rb', line 16 def self.detail(trace) new(trace).detail end |
.summary(trace) ⇒ Object
12 13 14 |
# File 'app/serializers/action_agent/telemetry_trace_serializer.rb', line 12 def self.summary(trace) new(trace).summary end |
Instance Method Details
#detail ⇒ Object
56 57 58 59 60 61 |
# File 'app/serializers/action_agent/telemetry_trace_serializer.rb', line 56 def detail summary.merge( resource_attributes: @trace.resource_attributes, sdk_info: @trace.sdk_info ) end |
#summary ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/serializers/action_agent/telemetry_trace_serializer.rb', line 24 def summary { id: @trace.id, trace_id: @trace.trace_id, short_id: @trace.trace_id&.first(8), agent: @trace.agent_class, action: @trace.agent_action, display_name: @trace.display_name, service_name: @trace.service_name, environment: @trace.environment, provider: @trace.provider, model: @trace.model, status: @trace.status, error: @trace., duration_ms: @trace.total_duration_ms&.to_f&.round(2), timestamp: @trace.&.iso8601(3), timestamp_ms: @trace.&.to_f&.*(1000)&.round, tokens: { input: @trace.total_input_tokens || 0, output: @trace.total_output_tokens || 0, thinking: @trace.total_thinking_tokens || 0, total: @trace.total_tokens }, estimated_cost: ModelPricing.estimate( model: @trace.model, input_tokens: @trace.total_input_tokens, output_tokens: @trace.total_output_tokens ), spans: serialized_spans } end |