marcelomazza/first_app

Setup Airbrake for your Ruby application

Closed this issue · 0 comments

Installation

Using bundler

Add the Airbrake Ruby gem to your Gemfile:

gem 'airbrake-ruby', '~> 2.0'

Manual

Invoke the following command from your terminal:

gem install airbrake-ruby

Example

This is the minimal example that you can use to test Airbrake Ruby with your project (You can find your project ID and API KEY with your project's settings):

require 'airbrake-ruby'

# Every Airbrake notifier must configure
# two options: `project_id` and `project_key`.
Airbrake.configure do |c|
  c.project_id = <Your project ID>
  c.project_key = '<Your project API KEY>'
end

# Asynchronous error delivery.
begin
  1/0
rescue ZeroDivisionError => ex
  # Return value is always `nil`.
  Airbrake.notify(ex)
end

puts 'A ZeroDivisionError was sent to Airbrake asynchronously!',
     "Find it at your project's dashboard on https://airbrake.io"

# Synchronous error delivery.
begin
  1/0
rescue ZeroDivisionError => ex
  # Return value is a Hash.
  response = Airbrake.notify_sync(ex)
end

puts "\nAnother ZeroDivisionError was sent to Airbrake, but this time synchronously.",
     "See it at #{response['url']}"

Configuration

For advanced configuration options like error filtering or custom parameters, please visit our official GitHub repo.