lib/new_relic/agent/agent.rb in newrelic_rpm-3.1.0.beta1 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.1.0.beta2

- old
+ new

@@ -2,10 +2,11 @@ require 'net/https' require 'net/http' require 'logger' require 'zlib' require 'stringio' +require 'new_relic/data_serialization' module NewRelic module Agent # The Agent is a singleton that is instantiated when the plugin is @@ -71,10 +72,11 @@ def unsent_traces_size @traces.length if @traces end def unsent_timeslice_data + @unsent_timeslice_data ||= {} @unsent_timeslice_data.keys.length end def record_transaction(duration_seconds, options={}) is_error = options['is_error'] || options['error_message'] || options['exception'] @@ -292,11 +294,11 @@ log_sql_transmission_warning? end def log_sql_transmission_warning? - log_if((@record_sql == :raw), :warn, "Agent is configured to send raw SQL to RPM service") + log_if((@record_sql == :raw), :warn, "Agent is configured to send raw SQL to the service") end def sampler_config control.fetch('transaction_tracer', {}) end @@ -350,11 +352,11 @@ log_file = NewRelic::Control.instance.log_file log_if(log_file, :info, "Agent Log found in #{log_file}") end def log_version_and_pid - log.info "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}" + log.info "New Relic Ruby Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}" end def log_if(boolean, level, message) self.log.send(level, message) if boolean boolean @@ -465,11 +467,11 @@ def handle_force_disconnect(error) # when a disconnect is requested, stop the current thread, which # is the worker thread that gathers data and talks to the # server. - log.error "RPM forced this agent to disconnect (#{error.message})" + log.error "New Relic forced this agent to disconnect (#{error.message})" disconnect end def handle_server_connection_problem(error) log.error "Unable to establish connection with the server. Run with log level set to debug for more information." @@ -518,11 +520,11 @@ # Try to launch the worker thread and connect to the server. # # See #connect for a description of connection_options. def start_worker_thread(connection_options = {}) - log.debug "Creating RPM worker thread." + log.debug "Creating Ruby Agent worker thread." @worker_thread = Thread.new do deferred_work!(connection_options) end # thread new @worker_thread['newrelic_label'] = 'Worker Loop' end @@ -568,11 +570,11 @@ false end end def log_error(error) - log.error "Error establishing connection with New Relic RPM Service at #{control.server}: #{error.message}" + log.error "Error establishing connection with New Relic Service at #{control.server}: #{error.message}" log.debug error.backtrace.join("\n") end def handle_license_error(error) log.error error.message @@ -619,11 +621,11 @@ enabled = if error_collector.config_enabled && server_enabled error_collector.enabled = true else error_collector.enabled = false end - log.debug "Errors will #{enabled ? '' : 'not '}be sent to the RPM service." + log.debug "Errors will #{enabled ? '' : 'not '}be sent to the New Relic service." end def enable_random_samples!(sample_rate) sample_rate = 10 unless sample_rate.to_i > 0# a sane default for random sampling @transaction_sampler.random_sampling = true @@ -640,11 +642,11 @@ if @should_send_samples # I don't think this is ever true, but... enable_random_samples!(sample_rate) if @should_send_random_samples log.debug "Transaction tracing threshold is #{@slowest_transaction_threshold} seconds." else - log.debug "Transaction traces will not be sent to the RPM service." + log.debug "Transaction traces will not be sent to the New Relic service." end end def set_collector_host! host = invoke_remote(:get_redirect_host) @@ -721,22 +723,22 @@ # * <tt>:keep_retrying => false</tt> to only try to connect once, and # return with the connection set to nil. This ensures we may try again # later (default true). # * <tt>force_reconnect => true</tt> if you want to establish a new connection # to the server before running the worker loop. This means you get a separate - # agent run and RPM sees it as a separate instance (default is false). + # agent run and New Relic sees it as a separate instance (default is false). def connect(options) # Don't proceed if we already connected (@connected=true) or if we tried # to connect and were rejected with prejudice because of a license issue # (@connected=false), unless we're forced to by force_reconnect. return if tried_to_connect?(options) # wait a few seconds for the web server to boot, necessary in development @connect_retry_period = should_keep_retrying?(options) ? 10 : 0 sleep connect_retry_period - log.debug "Connecting Process to RPM: #$0" + log.debug "Connecting Process to New Relic: #$0" query_server_for_configuration @connected_pid = $$ @connected = true rescue NewRelic::Agent::LicenseException => e handle_license_error(e) @@ -919,11 +921,11 @@ begin NewRelic::TimerLib.timeout(@request_timeout) do response = http.request(request) end rescue Timeout::Error - log.warn "Timed out trying to post data to RPM (timeout = #{@request_timeout} seconds)" unless @request_timeout < 30 + log.warn "Timed out trying to post data to New Relic (timeout = #{@request_timeout} seconds)" unless @request_timeout < 30 raise end if response.is_a? Net::HTTPServiceUnavailable raise NewRelic::Agent::ServerConnectionException, "Service unavailable (#{response.code}): #{response.message}" elsif response.is_a? Net::HTTPGatewayTimeOut @@ -997,10 +999,10 @@ # log.debug "Flushing unsent metric data to server" # harvest_and_send_timeslice_data log.debug "Serializing agent data to disk" NewRelic::Agent.save_data if @connected_pid == $$ - log.debug "Sending RPM service agent run shutdown message" + log.debug "Sending New Relic service agent run shutdown message" invoke_remote :shutdown, @agent_id, Time.now.to_f else log.debug "This agent connected from parent process #{@connected_pid}--not sending shutdown" end log.debug "Graceful disconnect complete"