Class: Phronomy::Tracing::Base
- Inherits:
-
Object
- Object
- Phronomy::Tracing::Base
- Defined in:
- lib/phronomy/tracing/base.rb
Overview
Abstract tracer.
To integrate a tracing backend (OpenTelemetry, Langfuse, etc.), subclass this and override #start_span and #finish_span. Then assign your tracer in the Phronomy configuration:
Phronomy.configure do |c| c.tracer = MyTracer.new end
The tracer is then automatically used by Chain and Agent components via the #trace helper.
Direct Known Subclasses
Instance Method Summary collapse
-
#finish_span(span, output: nil, usage: nil, error: nil) ⇒ Object
Finish a span after execution completes.
-
#start_span(name, **attributes) ⇒ Object
Start a new span.
-
#trace(name, input: nil, **meta) {|span| ... } ⇒ Object
Wraps a block in a span.
Instance Method Details
#finish_span(span, output: nil, usage: nil, error: nil) ⇒ Object
Finish a span after execution completes.
53 54 55 |
# File 'lib/phronomy/tracing/base.rb', line 53 def finish_span(span, output: nil, usage: nil, error: nil) raise NotImplementedError, "#{self.class}#finish_span is not implemented" end |
#start_span(name, **attributes) ⇒ Object
Start a new span. Must return an object that will be passed to #finish_span.
43 44 45 |
# File 'lib/phronomy/tracing/base.rb', line 43 def start_span(name, **attributes) raise NotImplementedError, "#{self.class}#start_span is not implemented" end |
#trace(name, input: nil, **meta) {|span| ... } ⇒ Object
Wraps a block in a span. Yields the span to the block. Calls #finish_span with the output on success or with the error on failure.
28 29 30 31 32 33 34 35 36 |
# File 'lib/phronomy/tracing/base.rb', line 28 def trace(name, input: nil, **) span = start_span(name, input: input, **) result, usage = yield span finish_span(span, output: result, usage: usage) result rescue => e finish_span(span, error: e) raise end |