The AppSignal gem version supports Rake since version
0.11.13 of the gem.
Every exception recorded in a Rake task will be sent to AppSignal and filed under the "Background" namespace. Note that we only track exceptions in Rake tasks. There is no performance monitoring for Rake tasks.
Depending on what version of the AppSignal gem you use and in what context some manual steps are required.
For Rails applications make sure you depend on the
:environment task. This loads the Rails application into memory and starts AppSignal as part of the application.
1 2 3 4 5
# lib/tasks/my_task.rb task :my_task => :environment do # do stuff end
Your Rails application's
Rakefile should look something like the example below. This should already be the case, no need to change it.
1 2 3 4 5 6 7
# Rakefile require File.expand_path("../config/application", __FILE__) # Only require this file for gem version < 1.0 # require "appsignal/integrations/rake" Rails.application.load_tasks
(For older versions of the AppSignal gem, versions
< 1, you will need to require the Rake integration manually. It is automatically loaded for version
1.x and higher.)
For pure Ruby applications some extra steps are required to load AppSignal. AppSignal needs to be required, configured and loaded. See the example below.
1 2 3 4 5 6 7 8 9 10
# Rakefile require "appsignal" Appsignal.config = Appsignal::Config.new(Dir.pwd, "development") Appsignal.start Appsignal.start_logger task :foo do raise "bar" end
When not relying on our automatic exception handling, and instead using
Appsignal.send_error another step is required. To flush the recorded error to our agent it's necessary to call
Appsignal.stop("rake"). This is normally done for you with the AppSignal exception handling, but is necessary in this scenario.
1 2 3 4 5 6 7 8 9 10 11 12 13
# Rakefile require "appsignal" Appsignal.config = Appsignal::Config.new(Dir.pwd, "development") Appsignal.start Appsignal.start_logger task :foo do Appsignal.send_error StandardError.new("bar") # "rake" is the parent process name which is being stopped and the reason why # AppSignal is stopping. Appsignal.stop "rake" end
For more information on how to integrate AppSignal in a pure Ruby application, see our integration guide.
See our example repository for a Ruby + Rake + AppSignal example application.