Class: Skywalking::Tracing::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/skywalking/tracing/span.rb

Direct Known Subclasses

EntrySpan, ExitSpan, NoopSpan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, span_id: -1,, parent_id: -1,, operation: nil, peer: nil, kind: nil, component: nil, layer: nil) ⇒ Span

Returns a new instance of Span.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/skywalking/tracing/span.rb', line 29

def initialize(
  context:,
  span_id: -1,
  parent_id: -1,
  operation: nil,
  peer: nil,
  kind: nil,
  component: nil,
  layer: nil
)
  @context = context
  @operation = operation
  @span_id = span_id
  @parent_id = parent_id
  @peer = peer
  @layer = layer || Layer::Unknown
  @kind = kind || nil
  @component = component || Component::Unknown

  @stack_depth = 0
  @inherit = Component::Unknown
  @tags = Hash.new { |hash, key| hash[key] = [] }
  @logs = []
  @refs = []
  @start_time = 0
  @end_time = 0
  @error_occurred = false
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def component
  @component
end

#contextObject

Returns the value of attribute context.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def context
  @context
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def end_time
  @end_time
end

#error_occurredObject

Returns the value of attribute error_occurred.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def error_occurred
  @error_occurred
end

#inheritObject

Returns the value of attribute inherit.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def inherit
  @inherit
end

#kindObject (readonly)

Returns the value of attribute kind.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def kind
  @kind
end

#layerObject

Returns the value of attribute layer.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def layer
  @layer
end

#operationObject

Returns the value of attribute operation.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def operation
  @operation
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def parent_id
  @parent_id
end

#peerObject

Returns the value of attribute peer.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def peer
  @peer
end

#refsObject (readonly)

Returns the value of attribute refs.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def refs
  @refs
end

#span_idObject (readonly)

Returns the value of attribute span_id.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def span_id
  @span_id
end

#stack_depthObject (readonly)

Returns the value of attribute stack_depth.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def stack_depth
  @stack_depth
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



26
27
28
# File 'lib/skywalking/tracing/span.rb', line 26

def start_time
  @start_time
end

#tagsObject

Returns the value of attribute tags.



23
24
25
# File 'lib/skywalking/tracing/span.rb', line 23

def tags
  @tags
end

Instance Method Details

#extract(carrier) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/skywalking/tracing/span.rb', line 97

def extract(carrier)
  return self if carrier.nil?

  @context.segment.relate(carrier.trace_id)
  @context.correlation = carrier.correlation_carrier.correlation

  return self unless carrier.valid?

  ref = SegmentRef.new(carrier)
  @refs << ref unless @refs.include?(ref)

  self
end

#finish?(segment) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/skywalking/tracing/span.rb', line 73

def finish?(segment)
  @end_time = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
  segment.archive(self)

  true
end

#injectObject



92
93
94
95
# File 'lib/skywalking/tracing/span.rb', line 92

def inject
  raise 'can only inject context carrier into ExitSpan, this may be a potential bug in the agent, ' \
        'please report this in https://github.com/apache/skywalking/issues if you encounter this. '
end

#startObject



58
59
60
61
62
63
64
# File 'lib/skywalking/tracing/span.rb', line 58

def start
  @stack_depth += 1
  return if @stack_depth != 1

  @start_time = (Process.clock_gettime(Process::CLOCK_REALTIME) * 1000).to_i
  @context.start(self)
end

#stop?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
# File 'lib/skywalking/tracing/span.rb', line 66

def stop?
  @stack_depth -= 1
  return false unless @stack_depth.zero?

  @context.stop?(self)
end

#tag(tag) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/skywalking/tracing/span.rb', line 80

def tag(tag)
  if tag.insert
    @tags[tag.key] = tag
  else
    @tags[tag.key] << tag
  end
end

#tags_itemObject



88
89
90
# File 'lib/skywalking/tracing/span.rb', line 88

def tags_item
  @tags.values.map { |tag| KeyStringValuePair.new(key: tag.key, value: tag.val) }
end