Class: Aws::Xray::Trace

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

Overview

Imutable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, sampled: true, parent: nil) ⇒ Trace

Returns a new instance of Trace.



28
29
30
31
32
# File 'lib/aws/xray/trace.rb', line 28

def initialize(root:, sampled: true, parent: nil)
  @root = root
  @sampled = sampled
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



26
27
28
# File 'lib/aws/xray/trace.rb', line 26

def parent
  @parent
end

#rootObject (readonly)

Returns the value of attribute root.



26
27
28
# File 'lib/aws/xray/trace.rb', line 26

def root
  @root
end

Class Method Details

.build_from_header_value(header_value, now = Time.now) ⇒ Object



13
14
15
16
17
# 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)
  new(root: root, sampled: h['Sampled'] != '0', parent: h['Parent'])
end

.generate(now = Time.now) ⇒ Object



9
10
11
# File 'lib/aws/xray/trace.rb', line 9

def generate(now = Time.now)
  new(root: generate_root(now))
end

Instance Method Details

#copy(parent: @parent) ⇒ Object



49
50
51
# File 'lib/aws/xray/trace.rb', line 49

def copy(parent: @parent)
  self.class.new(root: @root.dup, sampled: @sampled, parent: parent ? parent.dup : nil)
end

#has_parent?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/aws/xray/trace.rb', line 45

def has_parent?
  !!@parent
end

#sampled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/aws/xray/trace.rb', line 41

def sampled?
  @sampled
end

#to_header_valueObject



34
35
36
37
38
39
# File 'lib/aws/xray/trace.rb', line 34

def to_header_value
  v = "Root=#{@root};"
  sampled? ? v << 'Sampled=1' : v << 'Sampled=0'
  v << ";Parent=#{@parent}" if has_parent?
  v
end