Class: Bitfab::CurrentSpan
- Inherits:
-
Object
- Object
- Bitfab::CurrentSpan
- Defined in:
- lib/bitfab/span_context.rb
Overview
Handle to the current active span, allowing context to be added.
Instance Method Summary collapse
-
#add_context(context) ⇒ Object
Add a context entry to this span.
-
#id ⇒ Object
The Bitfab ID for the current span.
-
#initialize(span_state) ⇒ CurrentSpan
constructor
A new instance of CurrentSpan.
-
#set_prompt(prompt) ⇒ Object
Set the prompt for this span.
-
#trace_id ⇒ Object
The trace ID for the current span.
Constructor Details
#initialize(span_state) ⇒ CurrentSpan
Returns a new instance of CurrentSpan.
8 9 10 |
# File 'lib/bitfab/span_context.rb', line 8 def initialize(span_state) @span_state = span_state end |
Instance Method Details
#add_context(context) ⇒ Object
Add a context entry to this span. The entire hash is pushed as a single entry in the contexts array. Context entries are accumulated - multiple calls add to the list.
27 28 29 30 31 32 33 34 |
# File 'lib/bitfab/span_context.rb', line 27 def add_context(context) return unless context.is_a?(Hash) @span_state[:contexts] ||= [] @span_state[:contexts] << context rescue # Silently ignore - never crash the host app end |
#id ⇒ Object
The Bitfab ID for the current span.
13 14 15 |
# File 'lib/bitfab/span_context.rb', line 13 def id @span_state[:span_id] end |
#set_prompt(prompt) ⇒ Object
Set the prompt for this span. The prompt is stored in span_data.prompt. Calling multiple times overwrites the previous value.
41 42 43 44 45 46 47 |
# File 'lib/bitfab/span_context.rb', line 41 def set_prompt(prompt) return unless prompt.is_a?(String) @span_state[:prompt] = prompt rescue # Silently ignore - never crash the host app end |
#trace_id ⇒ Object
The trace ID for the current span.
18 19 20 |
# File 'lib/bitfab/span_context.rb', line 18 def trace_id @span_state[:trace_id] end |