Class: Zipkin::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin/endpoint.rb

Defined Under Namespace

Modules: PeerInfo, SpanKind

Constant Summary collapse

LOCAL_IP =
(
  Socket.ip_address_list.detect(&:ipv4_private?) ||
  Socket.ip_address_list.reverse.detect(&:ipv4?)
).ip_address

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name: nil, ipv4: nil, ipv6: nil, port: nil) ⇒ Endpoint

Returns a new instance of Endpoint.



56
57
58
59
60
61
# File 'lib/zipkin/endpoint.rb', line 56

def initialize(service_name: nil, ipv4: nil, ipv6: nil, port: nil)
  @service_name = service_name
  @ipv4 = ipv4
  @ipv6 = ipv6
  @port = port
end

Instance Attribute Details

#ipv4Object (readonly)

Returns the value of attribute ipv4.



63
64
65
# File 'lib/zipkin/endpoint.rb', line 63

def ipv4
  @ipv4
end

#ipv6Object (readonly)

Returns the value of attribute ipv6.



63
64
65
# File 'lib/zipkin/endpoint.rb', line 63

def ipv6
  @ipv6
end

#portObject (readonly)

Returns the value of attribute port.



63
64
65
# File 'lib/zipkin/endpoint.rb', line 63

def port
  @port
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



63
64
65
# File 'lib/zipkin/endpoint.rb', line 63

def service_name
  @service_name
end

Class Method Details

.local_endpoint(service_name) ⇒ Object



30
31
32
# File 'lib/zipkin/endpoint.rb', line 30

def self.local_endpoint(service_name)
  new(service_name: service_name, ipv4: LOCAL_IP)
end

.remote_endpoint(span) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zipkin/endpoint.rb', line 34

def self.remote_endpoint(span)
  tags = span.tags
  kind = tags['span.kind'] || SpanKind::SERVER

  case kind
  when SpanKind::SERVER, SpanKind::CLIENT
    return nil if (tags.keys & PeerInfo.keys).empty?

    new(
      service_name: tags[PeerInfo::SERVICE],
      ipv4: tags[PeerInfo::IPV4],
      ipv6: tags[PeerInfo::IPV6],
      port: tags[PeerInfo::PORT]
    )
  when SpanKind::PRODUCER, SpanKind::CONSUMER
    new(service_name: 'broker')
  else
    warn "Unkown span kind: #{kind}"
    nil
  end
end