Class: Trace::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/trace/context.rb

Overview

A generic representation of the current span. We follow the <github.com/openzipkin/b3-propagation> model.

Constant Summary collapse

SAMPLED =
0x01

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace_id, parent_id, flags, state = nil, remote: false) ⇒ Context

Returns a new instance of Context.



47
48
49
50
51
52
53
# File 'lib/trace/context.rb', line 47

def initialize(trace_id, parent_id, flags, state = nil, remote: false)
	@trace_id = trace_id
	@parent_id = span_id
	@flags = flags
	@state = state
	@remote = remote
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



57
58
59
# File 'lib/trace/context.rb', line 57

def flags
  @flags
end

#span_idObject (readonly)

Returns the value of attribute span_id.



56
57
58
# File 'lib/trace/context.rb', line 56

def span_id
  @span_id
end

#stateObject (readonly)

Returns the value of attribute state.



58
59
60
# File 'lib/trace/context.rb', line 58

def state
  @state
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



55
56
57
# File 'lib/trace/context.rb', line 55

def trace_id
  @trace_id
end

Class Method Details

.parse(parent, state = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trace/context.rb', line 27

def self.parse(parent, state = nil)
	version, trace_id, parent_id, flags = parent.split('-')
	
	if version = '00'
		flags = Integer(trace_flags, 16)
		
		if state.is_a?(String)
			state = state.split(',')
		end
		
		if state
			state = state.map{|item| item.split('=')}
		end
		
		self.new(trace_id, parent_id, flags, state)
	end
end

Instance Method Details

#remote?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/trace/context.rb', line 64

def remote?
	@remote
end

#sampled?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/trace/context.rb', line 60

def sampled?
	@flags & SAMPLED
end

#to_sObject



68
69
70
# File 'lib/trace/context.rb', line 68

def to_s
	"00-#{@trace_id}-#{@parent_id}-#{@flags.to_s(16)}"
end