Sha256: 0efe13d86194a0efbc740d2dd5ef3e7fa1ec393b9c961e377f9a17eb24942386

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'socket'

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

    module SpanKind
      SERVER = 'server'.freeze
      CLIENT = 'client'.freeze
      PRODUCER = 'producer'.freeze
      CONSUMER = 'consumer'.freeze
    end

    module PeerInfo
      SERVICE = 'peer.service'.freeze
      IPV4 = 'peer.ipv4'.freeze
      IPV6 = 'peer.ipv6'.freeze
      PORT = 'peer.port'.freeze

      def self.keys
        [SERVICE, IPV4, IPV6, PORT]
      end
    end

    def self.local_endpoint(service_name)
      {
        serviceName: service_name,
        ipv4: LOCAL_IP
      }
    end

    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?

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zipkin-1.3.0 lib/zipkin/endpoint.rb