Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
118 lines (80 sloc) 4.01 KB
Rake task monitoring

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.

(To manually integrate performance monitoring in select Rake tasks please see our integration guide and custom instrumentation guide.)

Depending on what version of the AppSignal gem you use and in what context some manual steps are required.

Table of Contents


Rails applications

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.

# lib/tasks/my_task.rb

task :my_task => :environment do
  # do stuff


Your Rails application's Rakefile should look something like the example below. This should already be the case, no need to change it.

# Rakefile
require File.expand_path("../config/application", __FILE__)

# Only require this file for gem version < 1.0
# require "appsignal/integrations/rake"


(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.)

Ruby applications

For pure Ruby applications some extra steps are required to load AppSignal. AppSignal needs to be required, configured and loaded. See also our integration guide.

# Rakefile
require "appsignal"

Appsignal.config =, "development")

task :foo do
  raise "bar"

Appsignal.stop requirement

To send data that's collected in your Rake tasks to the AppSignal servers, Appsignal.stop needs to be called. This is done for you when an error is raised in a task.

# Rakefile
task :foo do
  # Is automatically sent to AppSignal
  raise "My error"

Tasks that do not raise an error, but do call Appsignal.send_error or any of the custom metrics helper methods, need to call Appsignal.stop before the task is finished.

# Rakefile
task :foo do
  # Helper methods that require an `Appsignal.stop` call if no error is raised
  # Custom metrics helpers:
  Appsignal.increment_counter "my_custom_counter"

  # "rake" is the parent process name which is being stopped and the reason why
  # AppSignal is stopping.
  Appsignal.stop "rake"

Rake tasks and containers

When running a single Rake task in a container (e.g. with Kubernetes) there are two requirements:

For some containers running_in_container is automatically set to true when detected, for others manual configuration is required.

These two options guarantee that the extension has time to push the data to the agent and the agent has time to send the data to our API before shutting (the container) down.


Rake application

See our example repository for a Ruby + Rake + AppSignal example application.

You can’t perform that action at this time.