lib/instana/agent.rb in instana-1.7.7 vs lib/instana/agent.rb in instana-1.7.8
- old
+ new
@@ -250,11 +250,11 @@
if response
if response.body && response.body.length > 2
# The host agent returned something indicating that is has a request for us that we
# need to process.
- handle_response(response.body)
+ handle_agent_tasks(response.body)
end
if response.code.to_i == 200
@entity_last_seen = Time.now
return true
@@ -265,33 +265,51 @@
rescue => e
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end
- # When a request is received by the host agent, it is sent here
- # from processing and response.
+ # When request(s) are received by the host agent, it is sent here
+ # for handling & processing.
#
- # @param json_string [String] the request from the host agent
+ # @param json_string [String] the requests from the host agent
#
- def handle_response(json_string)
- their_request = Oj.load(json_string)
+ def handle_agent_tasks(json_string)
+ tasks = 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"])
+ if tasks.is_a?(Hash)
+ process_agent_task(tasks)
+ elsif tasks.is_a?(Array)
+ tasks.each do |t|
+ process_agent_task(t)
+ end
+ end
+ end
+
+ # Process a task sent from the host agent.
+ #
+ # @param task [String] the request json from the host agent
+ #
+ def process_agent_task(task)
+ if task.key?("action")
+ if task["action"] == "ruby.source"
+ payload = ::Instana::Util.get_rb_source(task["args"]["file"])
else
- payload = { :error => "Unrecognized action: #{their_request["action"]}. An newer Instana gem may be required for this. Current version: #{::Instana::VERSION}" }
+ payload = { :error => "Unrecognized action: #{task["action"]}. An newer Instana gem may be required for this. Current version: #{::Instana::VERSION}" }
end
else
payload = { :error => "Instana Ruby: No action specified in request." }
end
- path = "com.instana.plugin.ruby/response.#{@process[:report_pid]}?messageId=#{URI.encode(their_request['messageId'])}"
+ path = "com.instana.plugin.ruby/response.#{@process[:report_pid]}?messageId=#{URI.encode(task['messageId'])}"
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
req = Net::HTTP::Post.new(uri)
req.body = Oj.dump(payload)
::Instana.logger.debug "Responding to agent request: #{req.inspect}"
make_host_agent_request(req)
+
+ rescue StandardError => e
+ Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
+ Instana.logger.debug e.backtrace.join("\r\n")
end
# Accept and report spans to the host agent.
#
# @param traces [Array] An array of [Span]