module NewRelic::Agent::AgentHelpers::SpecialStartup

Public Instance Methods

defer_for_delayed_job?() click to toggle source
# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 35
def defer_for_delayed_job?
  NewRelic::Agent.config[:dispatcher] == :delayed_job &&
    !NewRelic::DelayedJobInjection.worker_name
end
defer_for_resque?() click to toggle source

Return true if we’re using resque and it hasn’t had a chance to (potentially) daemonize itself. This avoids hanging when there’s a Thread started before Resque calls Process.daemon (Jira RUBY-857)

# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 25
def defer_for_resque?
  NewRelic::Agent.config[:dispatcher] == :resque &&
    NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job? &&
    !PipeChannelManager.listener.started?
end
in_resque_child_process?() click to toggle source
# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 31
def in_resque_child_process?
  defined?(@service) && @service.is_a?(PipeService)
end
install_exit_handler() click to toggle source
# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 65
def install_exit_handler
  return unless should_install_exit_handler?

  NewRelic::Agent.logger.debug('Installing at_exit handler')
  at_exit { shutdown }
end
should_install_exit_handler?() click to toggle source
# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 59
def should_install_exit_handler?
  return false unless Agent.config[:send_data_on_exit]

  !sinatra_classic_app? || Agent.config[:force_install_exit_handler]
end
sinatra_classic_app?() click to toggle source

This matters when the following three criteria are met:

  1. A Sinatra ‘classic’ application is being run

  2. The app is being run by executing the main file directly, rather than via a config.ru file.

  3. newrelic_rpm is required after sinatra

In this case, the entire application runs from an at_exit handler in Sinatra, and if we were to install ours, it would be executed before the one in Sinatra, meaning that we’d shutdown the agent too early and never collect any data.

# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 51
def sinatra_classic_app?
  (
    defined?(Sinatra::Application) &&
    Sinatra::Application.respond_to?(:run) &&
    Sinatra::Application.run?
  )
end
using_forking_dispatcher?() click to toggle source

If we’re using a dispatcher that forks before serving requests, we need to wait until the children are forked before connecting, otherwise the parent process sends useless data

# File lib/new_relic/agent/agent_helpers/special_startup.rb, line 12
def using_forking_dispatcher?
  if [:puma, :passenger, :unicorn, :falcon].include?(Agent.config[:dispatcher])
    ::NewRelic::Agent.logger.info('Deferring startup of agent reporting thread because ' \
      "#{Agent.config[:dispatcher]} may fork.")
    true
  else
    false
  end
end