Class: Trace::Endpoint

Inherits:
Struct
  • Object
show all
Defined in:
lib/zipkin-tracer/trace.rb

Constant Summary collapse

UNKNOWN_URL =
'unknown'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ipv4Object

Returns the value of attribute ipv4

Returns:

  • (Object)

    the current value of ipv4



271
272
273
# File 'lib/zipkin-tracer/trace.rb', line 271

def ipv4
  @ipv4
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



271
272
273
# File 'lib/zipkin-tracer/trace.rb', line 271

def port
  @port
end

#service_nameObject

Returns the value of attribute service_name

Returns:

  • (Object)

    the current value of service_name



271
272
273
# File 'lib/zipkin-tracer/trace.rb', line 271

def service_name
  @service_name
end

Class Method Details

.local_endpoint(service_name) ⇒ Object



274
275
276
277
# File 'lib/zipkin-tracer/trace.rb', line 274

def self.local_endpoint(service_name)
  hostname = Socket.gethostname
  Endpoint.new(hostname, nil, service_name)
end

.remote_endpoint(url, remote_service_name) ⇒ Object



279
280
281
282
# File 'lib/zipkin-tracer/trace.rb', line 279

def self.remote_endpoint(url, remote_service_name)
  service_name = remote_service_name || url&.host&.split('.')&.first || UNKNOWN_URL # default to url-derived service name
  Endpoint.new(url&.host, url&.port, service_name)
end

Instance Method Details

#to_hObject



284
285
286
287
288
289
290
291
# File 'lib/zipkin-tracer/trace.rb', line 284

def to_h
  hsh = {
    ipv4: ipv4,
    serviceName: service_name
  }
  hsh[:port] = port if port
  hsh
end