Class: RailsErrorDashboard::ValueObjects::LlmCallEvent
- Inherits:
-
Object
- Object
- RailsErrorDashboard::ValueObjects::LlmCallEvent
- Defined in:
- lib/rails_error_dashboard/value_objects/llm_call_event.rb
Overview
Immutable value object representing a single LLM call observed in the host application. One canonical shape that all capture paths (OTel SpanProcessor, Faraday middleware, future native subscribers) normalize to before handing off to BreadcrumbCollector.
Fields are read-only after initialization. Unknown / unavailable fields are nil — never raise, never block, never allocate large strings.
Constant Summary collapse
- STATUSES =
[ :success, :error, :timeout ].freeze
- MAX_TOOL_ARG_LENGTH =
500- MAX_TOOL_RESULT_LENGTH =
500- MAX_ERROR_MESSAGE_LENGTH =
200
Instance Attribute Summary collapse
-
#cost_usd_estimate ⇒ Object
readonly
Returns the value of attribute cost_usd_estimate.
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#error_class ⇒ Object
readonly
Returns the value of attribute error_class.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tool_arguments_truncated ⇒ Object
readonly
Returns the value of attribute tool_arguments_truncated.
-
#tool_name ⇒ Object
readonly
Returns the value of attribute tool_name.
-
#tool_result_truncated ⇒ Object
readonly
Returns the value of attribute tool_result_truncated.
Instance Method Summary collapse
-
#initialize(provider:, model:, status:, input_tokens: nil, output_tokens: nil, duration_ms: nil, error_class: nil, error_message: nil, tool_name: nil, tool_arguments: nil, tool_result: nil, cost_usd_estimate: nil) ⇒ LlmCallEvent
constructor
A new instance of LlmCallEvent.
-
#to_breadcrumb_message ⇒ Object
Short human-readable message for the breadcrumb (rendered in UI).
-
#to_breadcrumb_metadata ⇒ Object
Hash shape passed to BreadcrumbCollector.add(…, metadata:).
- #tool_call? ⇒ Boolean
Constructor Details
#initialize(provider:, model:, status:, input_tokens: nil, output_tokens: nil, duration_ms: nil, error_class: nil, error_message: nil, tool_name: nil, tool_arguments: nil, tool_result: nil, cost_usd_estimate: nil) ⇒ LlmCallEvent
Returns a new instance of LlmCallEvent.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 23 def initialize(provider:, model:, status:, input_tokens: nil, output_tokens: nil, duration_ms: nil, error_class: nil, error_message: nil, tool_name: nil, tool_arguments: nil, tool_result: nil, cost_usd_estimate: nil) @provider = provider.to_s @model = model.to_s @status = STATUSES.include?(status) ? status : :success @input_tokens = input_tokens @output_tokens = output_tokens @duration_ms = duration_ms @error_class = error_class @error_message = truncate(, MAX_ERROR_MESSAGE_LENGTH) @tool_name = tool_name @tool_arguments_truncated = truncate(tool_arguments, MAX_TOOL_ARG_LENGTH) @tool_result_truncated = truncate(tool_result, MAX_TOOL_RESULT_LENGTH) @cost_usd_estimate = cost_usd_estimate freeze end |
Instance Attribute Details
#cost_usd_estimate ⇒ Object (readonly)
Returns the value of attribute cost_usd_estimate.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def cost_usd_estimate @cost_usd_estimate end |
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def duration_ms @duration_ms end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def @error_message end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def input_tokens @input_tokens end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def model @model end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def output_tokens @output_tokens end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def provider @provider end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def status @status end |
#tool_arguments_truncated ⇒ Object (readonly)
Returns the value of attribute tool_arguments_truncated.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def tool_arguments_truncated @tool_arguments_truncated end |
#tool_name ⇒ Object (readonly)
Returns the value of attribute tool_name.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def tool_name @tool_name end |
#tool_result_truncated ⇒ Object (readonly)
Returns the value of attribute tool_result_truncated.
18 19 20 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 18 def tool_result_truncated @tool_result_truncated end |
Instance Method Details
#to_breadcrumb_message ⇒ Object
Short human-readable message for the breadcrumb (rendered in UI).
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 67 def if tool_call? "tool: #{@tool_name}" else parts = [ @provider, @model ] if @input_tokens && @output_tokens parts << "in:#{@input_tokens}/out:#{@output_tokens}" end parts << @status.to_s if @status != :success parts.compact.join(" · ") end end |
#to_breadcrumb_metadata ⇒ Object
Hash shape passed to BreadcrumbCollector.add(…, metadata:). Only includes non-nil keys — keeps the breadcrumb JSON compact.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 49 def { provider: @provider, model: @model, status: @status.to_s, input_tokens: @input_tokens, output_tokens: @output_tokens, duration_ms: @duration_ms, error_class: @error_class, error_message: @error_message, tool_name: @tool_name, tool_arguments: @tool_arguments_truncated, tool_result: @tool_result_truncated, cost_usd: @cost_usd_estimate }.compact end |
#tool_call? ⇒ Boolean
43 44 45 |
# File 'lib/rails_error_dashboard/value_objects/llm_call_event.rb', line 43 def tool_call? !@tool_name.nil? end |