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.
6 7 8 |
# File 'lib/bitfab/span_context.rb', line 6 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.
25 26 27 28 29 30 31 32 |
# File 'lib/bitfab/span_context.rb', line 25 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.
11 12 13 |
# File 'lib/bitfab/span_context.rb', line 11 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.
39 40 41 42 43 44 45 |
# File 'lib/bitfab/span_context.rb', line 39 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.
16 17 18 |
# File 'lib/bitfab/span_context.rb', line 16 def trace_id @span_state[:trace_id] end |