Class: Zipkin::HTTPClient

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

Instance Method Summary collapse

Constructor Details

#initialize(url:, encoder:, logger:) ⇒ HTTPClient

Returns a new instance of HTTPClient.



8
9
10
11
12
# File 'lib/zipkin/http_client.rb', line 8

def initialize(url:, encoder:, logger:)
  @encoder = encoder
  @spans_uri = URI.parse("#{url}/api/v2/spans")
  @logger = logger
end

Instance Method Details

#send_spans(spans) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zipkin/http_client.rb', line 14

def send_spans(spans)
  http = Net::HTTP.new(@spans_uri.host, @spans_uri.port)
  http.use_ssl = @spans_uri.scheme == 'https'
  request = Net::HTTP::Post.new(
    @spans_uri.request_uri,
    'Content-Type' => @encoder.content_type
  )
  request.body = @encoder.encode(spans)
  response = http.request(request)

  if response.code != '202'
    @logger.error("Received bad response from Zipkin. status: #{response.code}, body: #{response.body.inspect}")
  end
rescue StandardError => e
  @logger.error("Error emitting spans batch: #{e.message}\n#{e.backtrace.join("\n")}")
end