Class: LlmLogs::Span
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LlmLogs::Span
- Defined in:
- app/models/llm_logs/span.rb
Instance Method Summary collapse
- #finish ⇒ Object
- #record_error(exception) ⇒ Object
- #record_response(message) ⇒ Object
- #set_attribute(key, value) ⇒ Object
Instance Method Details
#finish ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/models/llm_logs/span.rb', line 12 def finish update!( completed_at: Time.current, duration_ms: (Time.current - started_at) * 1000 ) # Restore parent span as current Thread.current[:llm_logs_span] = parent_span end |
#record_error(exception) ⇒ Object
29 30 31 32 |
# File 'app/models/llm_logs/span.rb', line 29 def record_error(exception) self.status = "error" self. = "#{exception.class}: #{exception.}" end |
#record_response(message) ⇒ Object
22 23 24 25 26 27 |
# File 'app/models/llm_logs/span.rb', line 22 def record_response() self.output = { content: .content.to_s } self.input_tokens = .input_tokens self.output_tokens = .output_tokens self.cached_tokens = .cached_tokens end |
#set_attribute(key, value) ⇒ Object
34 35 36 |
# File 'app/models/llm_logs/span.rb', line 34 def set_attribute(key, value) self. = ( || {}).merge(key => value) end |