Class: LlmLogs::Span

Inherits:
ApplicationRecord show all
Defined in:
app/models/llm_logs/span.rb

Instance Method Summary collapse

Instance Method Details

#finishObject



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.error_message = "#{exception.class}: #{exception.message}"
end

#record_response(message) ⇒ Object



22
23
24
25
26
27
# File 'app/models/llm_logs/span.rb', line 22

def record_response(message)
  self.output = { content: message.content.to_s }
  self.input_tokens = message.input_tokens
  self.output_tokens = message.output_tokens
  self.cached_tokens = message.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