For rake tasks specifically, you can install the newrelic-rake
gem. This gem should allow you to record errors that happen in any rake tasks (though it will not capture errors in 'rails runner' invocations).
For rails runner invocations, you can define a simple trace wrapper, and wrap each 'runner' invocation in your schedule.rb
file in that wrapper.
For example, if you have the following in config/initializers/trace_wrapper.rb
:
require 'newrelic_rpm'
module TraceWrapper
extend NewRelic::Agent::Instrumentation::ControllerInstrumentation
def self.trace(task_name)
perform_action_with_newrelic_trace(name: task_name, category: :task) do
yield
end
end
end
...then you can change your 'runner' invocations in schedule.rb
to be wrapped in this call as follows:
every 1.minutes do
runner "TraceWrapper.trace('compile models') { MyModel.compile }"
end
You'll need to do this for every rails runner
invocation in your schedule.rb
file.