Class: Trace::Context
- Inherits:
-
Object
- Object
- Trace::Context
- 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
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(trace_id, parent_id, flags, state = nil, remote: false) ⇒ Context
constructor
A new instance of Context.
- #remote? ⇒ Boolean
- #sampled? ⇒ Boolean
- #to_s ⇒ Object
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
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
57 58 59 |
# File 'lib/trace/context.rb', line 57 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
56 57 58 |
# File 'lib/trace/context.rb', line 56 def span_id @span_id end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
58 59 60 |
# File 'lib/trace/context.rb', line 58 def state @state end |
#trace_id ⇒ Object (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
64 65 66 |
# File 'lib/trace/context.rb', line 64 def remote? @remote end |
#sampled? ⇒ Boolean
60 61 62 |
# File 'lib/trace/context.rb', line 60 def sampled? @flags & SAMPLED end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/trace/context.rb', line 68 def to_s "00-#{@trace_id}-#{@parent_id}-#{@flags.to_s(16)}" end |