Sha256: c2b1456be4b0bb309eb86fed5eb61640d7b96fcc86f7df85c67f13cff32f2f33

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

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'
      IPV4 = :'peer.ipv4'
      IPV6 = :'peer.ipv6'
      PORT = :'peer.port'

      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

5 entries across 5 versions & 1 rubygems

Version Path
zipkin-1.6.0 lib/zipkin/endpoint.rb
zipkin-1.5.2 lib/zipkin/endpoint.rb
zipkin-1.5.1 lib/zipkin/endpoint.rb
zipkin-1.5.0 lib/zipkin/endpoint.rb
zipkin-1.4.0 lib/zipkin/endpoint.rb