The New Relic Ruby agent has opt-in support for instrumenting Rake tasks. This requires:
- Rake version 10.0.0 or higher
- Ruby agent version 3.13.0 or higher
To instrument Rake tasks, specify the tasks by name in your newrelic.yml
file.
Enable Rake support
To instrument your app's Rake tasks, add the names of the target tasks to the rake.tasks
element in your newrelic.yml
file. The Ruby agent matches these names against your active tasks using string regex.
Example: Instrumenting two Rake tasks
For example, to instrument the Rake tasks deploy
and deploy:all
, add the following to your newrelic.yml
file:
rake: tasks: ["deploy", "deploy:all"]
Since task name matching is with regex, you can instrument all of your app's Rake tasks by using a wildcard regex like [".+"]
. However, this will not include Rake tasks that are in your deny list by default from the autostart.blacklisted_rake_tasks
configuration setting, such as db:migrate
.
- To include any Rake tasks that are in your deny list by default, include them in your customized deny list.
- To ensure the tasks are instrumented before they run if you are using Rails but your Rake task does not require the Rails environment, add
require 'tasks/newrelic'
to the top of the Rake tasks.
Remove newrelic-rake when appropriate
The newrelic-rake
third-party gem provides Rake instrumentation support as an add-on to the Ruby agent. If the agent detects newrelic-rake
, it will not install the built-in Rake instrumentation, but it will record a log message like this at startup:
INFO : Not installing New Relic supported Rake instrumentation because the third party newrelic-rake gem is present
Caution
Removing the newrelic-rake
gem in favor of the built-in instrumentation will change your transaction names. To preserve your existing transaction names, ignore the log message and do not uninstall the gem.
To switch to New Relic's built-in Rake instrumentation and change your transaction names:
- Remove the
newrelic-rake
gem. - Specify the tasks you want to instrument in your config file.
Capture Rake job arguments
By default Rake job arguments are not captured. To capture Rake job arguments, use:
attributes.include: job.rake.*
For more help
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.