lib/zipkin/json_client.rb in zipkin-1.0.0 vs lib/zipkin/json_client.rb in zipkin-1.1.0

- old
+ new

@@ -2,14 +2,15 @@ require 'uri' require 'json' module Zipkin class JsonClient - def initialize(url:, collector:, flush_interval:) + def initialize(url:, collector:, flush_interval:, logger: Logger.new(STDOUT)) @collector = collector @flush_interval = flush_interval @spans_uri = URI.parse("#{url}/api/v1/spans") + @logger = logger end def start @thread = Thread.new do loop do @@ -29,19 +30,20 @@ def emit_batch(spans) return if spans.empty? 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, { + request = Net::HTTP::Post.new( + @spans_uri.request_uri, 'Content-Type' => 'application/json' - }) + ) request.body = JSON.dump(spans) response = http.request(request) - if response.code != 202 - STDERR.puts(response.body) + if response.code != '202' + @logger.error("Received bad response from Zipkin. status: #{response.code}, body: #{response.body.inspect}") end - rescue => e - STDERR.puts("Error emitting spans batch: #{e.message}\n#{e.backtrace.join("\n")}") + rescue StandardError => e + @logger.error("Error emitting spans batch: #{e.message}\n#{e.backtrace.join("\n")}") end end end