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.
-
#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.
20 21 22 23 24 25 26 27 |
# File 'lib/bitfab/span_context.rb', line 20 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 |
#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.
34 35 36 37 38 39 40 |
# File 'lib/bitfab/span_context.rb', line 34 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.
11 12 13 |
# File 'lib/bitfab/span_context.rb', line 11 def trace_id @span_state[:trace_id] end |