Module NewRelic::Agent::Agent::InstanceMethods::Start
In: lib/new_relic/agent/agent.rb

Herein lies the corpse of the former ‘start’ method. May its unmatched flog score rest in pieces.

Methods

Public Instance methods

Check whether we have already started, which is an error condition

Logs the configured application names

Sanity-check the agent configuration and start the agent, setting up the worker thread and the exit handler to shut down the agent

Connecting in the foreground blocks further startup of the agent until we have a connection - useful in cases where you‘re trying to log a very-short-running process and want to get statistics from before a server connection (typically 20 seconds) exists

A license key is an arbitrary 40 character string, usually looks something like a SHA1 hash

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)

The agent is disabled when it is not force enabled by the ‘agent_enabled’ option (e.g. in a manual start), or enabled normally through the configuration file

A correct license key exists and is of the proper length

Tell the user when the license key is missing so they can fix it by adding it to the file

Logs the dispatcher to the log file to assist with debugging. When no debugger is present, logs this fact to assist with proper dispatcher detection

Log the environment the app thinks it‘s running in. Useful in debugging, as this is the key for config YAML lookups.

Log startup information that we almost always want to know

Classy logging of the agent version and the current pid, so we can disambiguate processes in the log file and make sure they‘re running a reasonable version

Warn the user if they have configured their agent not to send data, that way we can see this clearly in the log file

There‘s an MRI 1.9 bug that loses exit codes in at_exit blocks. A workaround is necessary to get correct exit codes for the agent‘s test suites. bugs.ruby-lang.org/issues/5218

This is the shared method between the main agent startup and the after_fork call restarting the thread in deferred dispatchers.

Treatment of @started and env report is important to get right.

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.

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

[Validate]