Class: Trace::HttpApiClient

Inherits:
Object
  • Object
show all
Includes:
SuckerPunch::Job
Defined in:
lib/zipkin-tracer/zipkin_http_sender.rb

Constant Summary collapse

SPANS_PATH =
'/api/v2/spans'

Instance Method Summary collapse

Instance Method Details

#perform(json_api_host, spans) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zipkin-tracer/zipkin_http_sender.rb', line 11

def perform(json_api_host, spans)
  spans_with_ips =
    ::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans, ZipkinHttpSender::IP_FORMAT).map(&:to_h)

  resp = Faraday.new(json_api_host).post do |req|
    req.url SPANS_PATH
    req.headers['Content-Type'] = 'application/json'
    req.body = JSON.generate(spans_with_ips)
  end
rescue Net::ReadTimeout, Faraday::ConnectionFailed => e
  error_message = "Error while connecting to #{json_api_host}: #{e.class.inspect} with message '#{e.message}'. " \
                  "Please make sure the URL / port are properly specified for the Zipkin server."
  SuckerPunch.logger.error(error_message)
rescue => e
  SuckerPunch.logger.error(e)
end