class Aws::Xray::Trace
Imutable
Attributes
parent[R]
root[R]
Public Class Methods
build_from_header_value(header_value, now = Time.now)
click to toggle source
# File lib/aws/xray/trace.rb, line 13 def build_from_header_value(header_value, now = Time.now) h = HeaderParser.parse(header_value) root = h['Root'] || generate_root(now) rest = h.dup.tap {|e| %w[Root Sampled Parent].each {|k| e.delete(k) } } new(root: root, sampled: decide_sampling(h['Sampled']), parent: h['Parent'], rest: rest) end
generate(now = Time.now)
click to toggle source
# File lib/aws/xray/trace.rb, line 9 def generate(now = Time.now) new(root: generate_root(now), sampled: decide_sampling(nil)) end
new(root:, sampled:, parent: nil, rest: {})
click to toggle source
# File lib/aws/xray/trace.rb, line 45 def initialize(root:, sampled:, parent: nil, rest: {}) @root = root @sampled = sampled @parent = parent @rest = rest end
Private Class Methods
decide_sampling(value)
click to toggle source
Decide sample this request or not. At first, check parent's sampled and follow the value if it exists. Then decide sampled or not according to configured sampling_rate. @param [String,nil] value @return [Bloolean]
# File lib/aws/xray/trace.rb, line 27 def decide_sampling(value) case value when '0' false when '1' true else rand < Aws::Xray.config.sampling_rate end end
generate_root(now)
click to toggle source
# File lib/aws/xray/trace.rb, line 38 def generate_root(now) "1-#{now.to_i.to_s(16)}-#{SecureRandom.hex(12)}" end
Public Instance Methods
copy(parent: @parent)
click to toggle source
# File lib/aws/xray/trace.rb, line 64 def copy(parent: @parent) self.class.new(root: @root.dup, sampled: @sampled, parent: parent ? parent.dup : nil) end
has_parent?()
click to toggle source
# File lib/aws/xray/trace.rb, line 60 def has_parent? !!@parent end
sampled?()
click to toggle source
# File lib/aws/xray/trace.rb, line 56 def sampled? @sampled end
to_header_value()
click to toggle source
# File lib/aws/xray/trace.rb, line 52 def to_header_value to_header_hash.map {|k, v| "#{k}=#{v}" }.join(';') end
Private Instance Methods
to_header_hash()
click to toggle source
# File lib/aws/xray/trace.rb, line 70 def to_header_hash h = {'Root' => @root, 'Sampled' => sampled? ? '1' : '0' } h['Parent'] = @parent if has_parent? h.merge!(@rest) h end