Rake integration guide

Add Bugsnag error monitoring to your Rake tasks.


Add the bugsnag Ruby gem to your Gemfile:

gem 'bugsnag'

Don’t forget to run bundle install after updating your Gemfile.

Basic configuration

Rails applications

If you are using Rake as part of Rails application, and have already configured Bugsnag in your Rails application, then Bugsnag will automatically be configured, as long as your Rake tasks depend on the :environment task.

Other applications

To identify your app in the Bugsnag dashboard, you’ll need to configure your Bugsnag API key. You can find your API key when creating a project in your Bugsnag dashboard, or later from your project settings page.

To set your API key in your Rack app, add the following code to your Rakefile:

require 'bugsnag/rake'

Bugsnag.configure do |config|
  config.api_key = 'YOUR_API_KEY_HERE'

Alternatively, you can set the BUGSNAG_API_KEY environment variable.

If you’d like to configure Bugsnag further, check out the configuration options reference.

Reporting unhandled exceptions

Rails applications

If you are using Rake as part of Rails application, then Bugsnag will automatically detect unhandled exceptions, as long as your Rake tasks depend on the :environment task.

Other applications

In your Rakefile, simply require bugsnag:

require 'bugsnag'

At this point, Bugsnag should be installed and configured, and any unhandled exceptions will be automatically detected and should appear in your Bugsnag dashboard.

Reporting handled exceptions

Reporting handled exceptions can be accomplished as follows:

  raise 'Something went wrong!'
rescue => exception

Adding diagnostics or adjusting severity

It can often be helpful to adjust the severity or attach custom diagnostics to handled exceptions. For more information, see reporting handled errors.

Sending diagnostic data

Automatically captured diagnostics

As well as a full stacktrace for every exception, Bugsnag will automatically capture the name, description, and arguments of the running task.

Custom diagnostics

In order to quickly reproduce and fix errors, it is often helpful to send additional application-specific diagnostic data to Bugsnag. This can be accomplished using a before notify callback as follows:

Bugsnag.before_notify_callbacks << lambda {|report|
  report.add_tab(:diagnostics, {
    product: current_product.name

For more information, see the customizing error reports reference.

Tracking deploys

By sending your source revision or application version to us when you deploy a new version of your app, you’ll be able to see which deploy each error was introduced in, or seen in.

Find information on how to track deployment using Capistrano in our how to track deploys using Capistrano

If you are using a deployment system other than Capistrano, see our deploy tracking guide.

Catching JavaScript errors

Catch and report errors in your client-side JavaScript with the Web browser JavaScript guide