Class: LLM::Tracer
- Inherits:
-
Object
- Object
- LLM::Tracer
- Defined in:
- lib/llm/tracer.rb
Overview
The LLM::Tracer is the superclass of all LLM tracers. It can be helpful for implementing instrumentation and hooking into the lifecycle of an LLM request. See LLM::Tracer::Telemetry, and LLM::Tracer::Logger for example tracer implementations.
Defined Under Namespace
Classes: Logger, Null, Telemetry
Instance Method Summary collapse
-
#flush! ⇒
nil
Flush the tracer.
-
#on_request_start(operation:,
model: nil) ⇒ void
Called before an LLM provider request is executed.
-
#on_request_finish(operation:,
res:, model: nil, span: nil) ⇒ void
Called after an LLM provider request succeeds.
-
#on_request_error(ex:,
span:) ⇒ void
Called when an LLM provider request fails.
-
#on_tool_start(id:,
name:, arguments:, model:) ⇒ void
Called before a local tool/function executes.
-
#on_tool_finish(result:,
span:) ⇒ void
Called after a local tool/function succeeds.
-
#on_tool_error(ex:,
span:) ⇒ void
Called when a local tool/function raises.
- #inspect ⇒ String
- #spans ⇒ Array
-
#initialize(provider,
options = {}) ⇒ Tracer constructor
A new instance of Tracer.
Constructor Details
#initialize(provider, options = {}) ⇒ Tracer
Returns a new instance of Tracer.
21 22 23 24 |
# File 'lib/llm/tracer.rb', line 21 def initialize(provider, = {}) @provider = provider @options = {} end |
Instance Method Details
#flush! ⇒ nil
This method is only implemented by the Telemetry tracer. It is a noop for other tracers.
Flush the tracer
110 111 112 |
# File 'lib/llm/tracer.rb', line 110 def flush! nil end |
#on_request_start(operation:, model: nil) ⇒ void
This method returns an undefined value.
Called before an LLM provider request is executed.
31 32 33 |
# File 'lib/llm/tracer.rb', line 31 def on_request_start(operation:, model: nil) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#on_request_finish(operation:, res:, model: nil, span: nil) ⇒ void
This method returns an undefined value.
Called after an LLM provider request succeeds.
42 43 44 |
# File 'lib/llm/tracer.rb', line 42 def on_request_finish(operation:, res:, model: nil, span: nil) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#on_request_error(ex:, span:) ⇒ void
This method returns an undefined value.
Called when an LLM provider request fails.
51 52 53 |
# File 'lib/llm/tracer.rb', line 51 def on_request_error(ex:, span:) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#on_tool_start(id:, name:, arguments:, model:) ⇒ void
This method returns an undefined value.
Called before a local tool/function executes.
66 67 68 |
# File 'lib/llm/tracer.rb', line 66 def on_tool_start(id:, name:, arguments:, model:) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#on_tool_finish(result:, span:) ⇒ void
This method returns an undefined value.
Called after a local tool/function succeeds.
77 78 79 |
# File 'lib/llm/tracer.rb', line 77 def on_tool_finish(result:, span:) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#on_tool_error(ex:, span:) ⇒ void
This method returns an undefined value.
Called when a local tool/function raises.
88 89 90 |
# File 'lib/llm/tracer.rb', line 88 def on_tool_error(ex:, span:) raise NotImplementedError, "#{self.class} does not implement '#{__method__}'" end |
#inspect ⇒ String
94 95 96 |
# File 'lib/llm/tracer.rb', line 94 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @provider=#{@provider.class} @tracer=#{@tracer.inspect}>" end |
#spans ⇒ Array
100 101 102 |
# File 'lib/llm/tracer.rb', line 100 def spans [] end |