lib/new_relic/agent/agent.rb in newrelic_rpm-3.5.6.48.beta vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.5.6.55
- old
+ new
@@ -222,12 +222,11 @@
# Attempt a graceful shutdown of the agent, running the worker
# loop if it exists and is running.
#
# Options:
- # :force_send => (true/false) # force the agent to send data
- # before shutting down
+ # :force_send => (true/false) # force the agent to send data
def shutdown(options={})
run_loop_before_exit = Agent.config[:force_send]
return if not started?
if @worker_loop
@worker_loop.run_task if run_loop_before_exit
@@ -236,11 +235,10 @@
::NewRelic::Agent.logger.info "Starting Agent shutdown"
# if litespeed, then ignore all future SIGUSR1 - it's
# litespeed trying to shut us down
-
if Agent.config[:dispatcher] == :litespeed
Signal.trap("SIGUSR1", "IGNORE")
Signal.trap("SIGTERM", "IGNORE")
end
@@ -684,10 +682,16 @@
error.message, \
"Visit NewRelic.com to obtain a valid license key, or to upgrade your account.")
disconnect
end
+ def handle_unrecoverable_agent_error(error)
+ ::NewRelic::Agent.logger.error(error.message)
+ disconnect
+ shutdown
+ end
+
# Checks whether we should send environment info, and if so,
# returns the snapshot from the local environment
def environment_for_connect
Agent.config[:send_environment_info] ? Control.instance.local_env.snapshot : []
end
@@ -798,15 +802,13 @@
@traces += transaction_traces
else
@traces = transaction_traces
end
end
- if errors && errors.respond_to?(:any?) && errors.any?
- if @unsent_errors
- @unsent_errors = @unsent_errors + errors
- else
- @unsent_errors = errors
+ if errors && errors.respond_to?(:each)
+ errors.each do |err|
+ @error_collector.add_to_error_queue(err)
end
end
end
public :merge_data_from
@@ -840,10 +842,12 @@
query_server_for_configuration
@connected_pid = $$
@connect_state = :connected
rescue NewRelic::Agent::LicenseException => e
handle_license_error(e)
+ rescue NewRelic::Agent::UnrecoverableAgentException => e
+ handle_unrecoverable_agent_error(e)
rescue Timeout::Error, StandardError => e
log_error(e)
if opts[:keep_retrying]
note_connect_failure
::NewRelic::Agent.logger.warn "Will re-attempt in #{connect_retry_period} seconds"
@@ -1022,16 +1026,19 @@
end
def transmit_data(disconnecting=false)
now = Time.now
::NewRelic::Agent.logger.debug "Sending data to New Relic Service"
- harvest_and_send_errors
- harvest_and_send_slowest_sample
- harvest_and_send_slowest_sql
- harvest_and_send_timeslice_data
- harvest_and_send_thread_profile(disconnecting)
- check_for_agent_commands
+ @service.session do # use http keep-alive
+ harvest_and_send_errors
+ harvest_and_send_slowest_sample
+ harvest_and_send_slowest_sql
+ harvest_and_send_timeslice_data
+ harvest_and_send_thread_profile(disconnecting)
+
+ check_for_agent_commands
+ end
rescue => e
retry_count ||= 0
retry_count += 1
if retry_count <= 1
::NewRelic::Agent.logger.debug "retrying transmit_data after #{e}"