Class: LangfuseContext
- Inherits:
-
Object
- Object
- LangfuseContext
- Defined in:
- lib/langfuse_context.rb
Class Method Summary collapse
- .current ⇒ Object
- .current_span_id ⇒ Object
- .current_trace_id ⇒ Object
- .with_span(span) ⇒ Object
- .with_trace(trace) ⇒ Object
Class Method Details
.current ⇒ Object
2 3 4 |
# File 'lib/langfuse_context.rb', line 2 def self.current Thread.current[:langfuse_context] ||= {} end |
.current_span_id ⇒ Object
10 11 12 |
# File 'lib/langfuse_context.rb', line 10 def self.current_span_id current[:span_id] end |
.current_trace_id ⇒ Object
6 7 8 |
# File 'lib/langfuse_context.rb', line 6 def self.current_trace_id current[:trace_id] end |
.with_span(span) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/langfuse_context.rb', line 24 def self.with_span(span) old_context = current.dup begin Thread.current[:langfuse_context] = current.merge({ span_id: span.id }) yield ensure Thread.current[:langfuse_context] = old_context end end |
.with_trace(trace) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/langfuse_context.rb', line 14 def self.with_trace(trace) old_context = current.dup begin Thread.current[:langfuse_context] = { trace_id: trace.id } yield ensure Thread.current[:langfuse_context] = old_context end end |