Problem
The Ruby agent isn't starting or isn't reporting data to New Relic.
Solution
To solve this problem:
Check your Ruby agent version, and update if necessary.
When the newrelic_rpm Ruby gem is required in your application environment, it will attempt to determine whether to start monitoring automatically and begin transmitting metrics to New Relic, or to remain disabled.
Production and staging: The agent typically is configured to monitor automatically in these environments.
Test and development: The agent typically remains disabled in these environments.
To control this logic, set the
monitor_modeconfiguration key totrueorfalsein each environment section ofnewrelic.yml.
To override the agent's auto-start logic, the easiest mechanism is to set a NEW_RELIC_AGENT_ENABLED=true environment variable; for example:
$NEW_RELIC_AGENT_ENABLED=true rake assets:precompileIf you are running Ruby agent version 3.6.1 or higher, there are a few reasons the agent will refuse to start:
The agent detects it is in an interactive session; for example, a
rails consoleorirbsession.The agent detects it is in one of Rails' built-in rake tasks; for example,
assets:precompileordb:migrate.You can use configuration variables in your Ruby agent
newrelic.ymlfile to customize auto-start behavior for constants, script names, and rake tasks.Variable
Description
Constants
- Ruby constants that should prevent the agent from starting. Accepts a comma separated list.
- Defaults to
"Rails::Console". - Set to
""to tell the agent to start whenRails::Consoleis in the environment.
Rake tasks
- Rake tasks you do not want the agent to monitor; for example,
assets:precompile. Accepts a comma-separated list. - We do not disable the Ruby agent in all rake tasks, because tasks like
resque:workgenerally are monitored.
Executables
- A list of script names, such as
irb, that will prevent the agent from starting automatically. Accepts a comma-separated list. - Set this to
"rake"to prevent the agent from starting in rake tasks, or"rake,my_ruby_script.rb"to prevent it from starting in rake and a custom script.
Problem
The Ruby agent starts in contexts where I don't want it to start.
Solution
The Ruby agent makes some assumptions about the contexts most customers want the agent to automatically start.
There are three configuration options available to customize this behavior:
autostart.denylisted_constantsMost of the constants on this list are Rails commands that perform operations that rarely benefit from monitoring.The list doesn't include
Rails::Command::RakeCommand, which powers commands likerails db:*as well asrails solid_queue:start, and other Rails commands related to Rake tasks.autostart.denylisted_executablesThis configuration controls executables, likerspecandirb.autostart.denylisted_rake_tasksPrior to Rails 5.1,rakewas used instead ofthorfor many commands, such asdb:migrate. The default values for this configuration lists many commands from that time. You can also add your ownrakecommands to this list.
The NewRelic::Agent.manual_start API can be used to start the agent in specific contexts. If you set :agent_enabled to false in your configuration file or set the environment variable NEW_RELIC_AGENT_ENABLED=false, you can still manually start the agent using this API.
NewRelic::Agent.manual_start(agent_enabled: true)If you want to stop the agent before the process ends, you can call NewRelic::Agent.shutdown.