lib/instana/agent.rb in instana-1.7.5 vs lib/instana/agent.rb in instana-1.7.6

- old
+ new

@@ -1,14 +1,16 @@ -require 'json' +require 'oj' require 'net/http' require 'socket' require 'sys/proctable' require 'timers' require 'uri' require 'thread' include Sys +Oj.default_options = {:mode => :strict} + module Instana class Agent attr_accessor :state attr_accessor :agent_uuid attr_accessor :process @@ -203,18 +205,18 @@ announce_payload[:inode] = File.readlink("/proc/#{Process.pid}/fd/#{socket.fileno}") end uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}") req = Net::HTTP::Put.new(uri) - req.body = announce_payload.to_json + req.body = Oj.dump(announce_payload) ::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}" response = make_host_agent_request(req) if response && (response.code.to_i == 200) - data = JSON.parse(response.body) + data = Oj.load(response.body) @process[:report_pid] = data['pid'] @agent_uuid = data['agentUuid'] true else false @@ -241,11 +243,11 @@ path = "com.instana.plugin.ruby.#{@process[:report_pid]}" uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}") req = Net::HTTP::Post.new(uri) - req.body = payload.to_json + req.body = Oj.dump(payload) response = make_host_agent_request(req) if response if response.body && response.body.length > 2 # The host agent returned something indicating that is has a request for us that we @@ -269,11 +271,11 @@ # from processing and response. # # @param json_string [String] the request from the host agent # def handle_response(json_string) - their_request = JSON.parse(json_string).first + their_request = Oj.load(json_string) if their_request.key?("action") if their_request["action"] == "ruby.source" payload = ::Instana::Util.get_rb_source(their_request["args"]["file"]) else @@ -284,11 +286,11 @@ end path = "com.instana.plugin.ruby/response.#{@process[:report_pid]}?messageId=#{URI.encode(their_request['messageId'])}" uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}") req = Net::HTTP::Post.new(uri) - req.body = payload.to_json + req.body = Oj.dump(payload) ::Instana.logger.debug "Responding to agent request: #{req.inspect}" make_host_agent_request(req) end # Accept and report spans to the host agent. @@ -306,10 +308,10 @@ path = "com.instana.plugin.ruby/traces.#{@process[:report_pid]}" uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}") req = Net::HTTP::Post.new(uri) - req.body = spans.to_json + req.body = Oj.dump(spans) response = make_host_agent_request(req) if response last_trace_response = response.code.to_i