Class: Bitfab::CurrentSpan

Inherits:
Object
  • Object
show all
Defined in:
lib/bitfab/span_context.rb

Overview

Handle to the current active span, allowing context to be added.

Instance Method Summary collapse

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.

Parameters:

  • context (Hash)

    key-value pairs to add as a single context entry



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.

Parameters:

  • prompt (String)

    the prompt string to store



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_idObject

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