Module: LlmLogs::Tracer
- Defined in:
- lib/llm_logs/tracer.rb
Class Method Summary collapse
- .auto_create_trace(span_name) ⇒ Object
- .current_span ⇒ Object
- .current_trace ⇒ Object
- .start_span(name:, span_type:, model: nil, provider: nil, input: nil, metadata: {}) ⇒ Object
- .start_trace(name, metadata: {}) ⇒ Object
Class Method Details
.auto_create_trace(span_name) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/llm_logs/tracer.rb', line 57 def self.auto_create_trace(span_name) trace = LlmLogs::Trace.create!( name: "auto:#{span_name}", status: "running", started_at: Time.current ) Thread.current[:llm_logs_trace] = trace trace end |
.current_span ⇒ Object
7 8 9 |
# File 'lib/llm_logs/tracer.rb', line 7 def self.current_span Thread.current[:llm_logs_span] end |
.current_trace ⇒ Object
3 4 5 |
# File 'lib/llm_logs/tracer.rb', line 3 def self.current_trace Thread.current[:llm_logs_trace] end |
.start_span(name:, span_type:, model: nil, provider: nil, input: nil, metadata: {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/llm_logs/tracer.rb', line 36 def self.start_span(name:, span_type:, model: nil, provider: nil, input: nil, metadata: {}) trace = current_trace || auto_create_trace(name) parent = current_span span = LlmLogs::Span.create!( trace: trace, parent_span: parent, name: name, span_type: span_type, model: model, provider: provider, input: input, metadata: , status: "ok", started_at: Time.current ) Thread.current[:llm_logs_span] = span span end |
.start_trace(name, metadata: {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/llm_logs/tracer.rb', line 11 def self.start_trace(name, metadata: {}) trace = LlmLogs::Trace.create!( name: name, status: "running", metadata: , started_at: Time.current ) previous_trace = Thread.current[:llm_logs_trace] previous_span = Thread.current[:llm_logs_span] Thread.current[:llm_logs_trace] = trace Thread.current[:llm_logs_span] = nil begin yield trace rescue => e trace.fail! raise ensure trace.complete! if trace.status == "running" Thread.current[:llm_logs_trace] = previous_trace Thread.current[:llm_logs_span] = previous_span end end |