The New Relic Ruby agent has opt-in support for instrumenting Rake tasks (Rake version 10.0.0 or higher). To instrument Rake tasks, specify the tasks by name in your newrelic.yml.
Rake instrumentation requires Ruby agent version 3.13.0 or higher.
Enabling 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. 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:all, add the following to your newrelic.yml file:
rake: tasks: ["deploy", "deploy:all"]
If you are using Rails but your Rake task does not require the Rails environment, to ensure the tasks are instrumented before they run, add
require 'tasks/newrelic' to the top of the Rake tasks.
Interaction with newrelic-rake
newrelic-rake third-party gem provides Rake instrumentation support as an add-on to the Ruby agent. If the agent detects
newrelic-rake, it won't install the built-in Rake instrumentation and 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
To switch to New Relic's built-in Rake instrumentation, remove the
newrelic-rake gem and specify the tasks you want to instrument in your config file.
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.
Capture Rake job arguments
By default Rake job arguments are not captured. To capture Rake job arguments, use the configuration below:
For more help
Additional documentation resources include: