lib/new_relic/agent/agent.rb in newrelic_rpm-3.6.3.111 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.6.4.113.beta

- old
+ new

@@ -43,12 +43,13 @@ @transaction_rules = NewRelic::Agent::RulesEngine.new @metric_rules = NewRelic::Agent::RulesEngine.new @request_sampler = NewRelic::Agent::RequestSampler.new(@events) @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events) - @connect_state = :pending - @connect_attempts = 0 + @connect_state = :pending + @connect_attempts = 0 + @environment_report = nil @last_harvest_time = Time.now @obfuscator = lambda {|sql| NewRelic::Agent::Database.default_sql_obfuscator(sql) } # FIXME: temporary work around for RUBY-839 @@ -201,12 +202,11 @@ reset_objects_with_locks # Clear out stats that are left over from parent process reset_stats - # Don't ever check to see if this is a spawner. If we're in a forked process - # I'm pretty sure we're not also forking new instances. + generate_environment_report start_worker_thread(options) end # True if we have initialized and completed 'start' def started? @@ -461,10 +461,11 @@ # setting up the worker thread and the exit handler to shut # down the agent def check_config_and_start_agent return unless monitoring? && has_correct_license_key? return if using_forking_dispatcher? + generate_environment_report connect_in_foreground if Agent.config[:sync_startup] start_worker_thread install_exit_handler end end @@ -709,12 +710,19 @@ ::NewRelic::Agent.logger.error(error.message) disconnect shutdown end + def generate_environment_report + @environment_report = environment_for_connect + end + # Checks whether we should send environment info, and if so, - # returns the snapshot from the local environment + # returns the snapshot from the local environment. + # Generating the EnvironmentReport has the potential to trigger + # require calls in Rails environments, so this method should only + # be called synchronously from on the main thread. def environment_for_connect Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : [] end # Initializes the hash of settings that we send to the @@ -724,10 +732,10 @@ :pid => $$, :host => @local_host, :app_name => Agent.config.app_names, :language => 'ruby', :agent_version => NewRelic::VERSION::STRING, - :environment => environment_for_connect, + :environment => @environment_report, :settings => Agent.config.to_collector_hash, } end # Returns connect data passed back from the server