Class: Skywalking::Tracing::Carrier

Inherits:
CarrierItem show all
Defined in:
lib/skywalking/tracing/carrier.rb

Instance Attribute Summary collapse

Attributes inherited from CarrierItem

#key

Instance Method Summary collapse

Constructor Details

#initialize(trace_id: '', segment_id: '', span_id: '', service: '', service_instance: '', endpoint: '', peer: '', correlation: nil) ⇒ Carrier

Returns a new instance of Carrier.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/skywalking/tracing/carrier.rb', line 26

def initialize(
  trace_id: '',
  segment_id: '',
  span_id: '',
  service: '',
  service_instance: '',
  endpoint: '',
  peer: '',
  correlation: nil
)
  super(key: 'sw8')

  @trace_id = trace_id
  @segment_id = segment_id
  @span_id = span_id
  @service = service
  @service_instance = service_instance
  @endpoint = endpoint
  @peer = peer
  @correlation_carrier = SW8CorrelationCarrier.new
  @items = [@correlation_carrier, self]
  @iter_index = 0
  @correlation_carrier.correlation = correlation unless correlation.nil?
end

Instance Attribute Details

#correlation_carrierObject (readonly)

Returns the value of attribute correlation_carrier.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def correlation_carrier
  @correlation_carrier
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def endpoint
  @endpoint
end

#itemsObject (readonly)

Returns the value of attribute items.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def items
  @items
end

#iter_indexObject (readonly)

Returns the value of attribute iter_index.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def iter_index
  @iter_index
end

#peerObject (readonly)

Returns the value of attribute peer.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def peer
  @peer
end

#segment_idObject (readonly)

Returns the value of attribute segment_id.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def segment_id
  @segment_id
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def service
  @service
end

#service_instanceObject (readonly)

Returns the value of attribute service_instance.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def service_instance
  @service_instance
end

#span_idObject (readonly)

Returns the value of attribute span_id.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def span_id
  @span_id
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



22
23
24
# File 'lib/skywalking/tracing/carrier.rb', line 22

def trace_id
  @trace_id
end

Instance Method Details

#eachObject



90
91
92
# File 'lib/skywalking/tracing/carrier.rb', line 90

def each
  @items.each { |item| yield item }
end

#suppressed?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/skywalking/tracing/carrier.rb', line 86

def suppressed?
  @val && !valid?
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  !@trace_id.empty? && !@segment_id.empty? && !@service.empty? &&
    !@service_instance.empty? && !@endpoint.empty? &&
    !@peer.empty? && @span_id.match?(/^\d+$/)
end

#valueObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/skywalking/tracing/carrier.rb', line 51

def value
  [
    '1',
    Base64.strict_encode64(@trace_id),
    Base64.strict_encode64(@segment_id),
    @span_id,
    Base64.strict_encode64(@service),
    Base64.strict_encode64(@service_instance),
    Base64.strict_encode64(@endpoint),
    Base64.strict_encode64(@peer)
  ].join('-')
end

#value=(val) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/skywalking/tracing/carrier.rb', line 64

def value=(val)
  @val = val
  return if val.nil? || val.empty?

  parts = val.split('-')
  return if parts.size != 8

  @trace_id = Base64.strict_decode64(parts[1])
  @segment_id = Base64.strict_decode64(parts[2])
  @span_id = parts[3]
  @service = Base64.strict_decode64(parts[4])
  @service_instance = Base64.strict_decode64(parts[5])
  @endpoint = Base64.strict_decode64(parts[6])
  @peer = Base64.strict_decode64(parts[7])
end