Sentry Integration to Rails App
Sep 6, 2017
1 minute read

Integration of Sentry to Rails

Once your Sentry is up and running, let’s look on how to integrate it in your Apps.

As I work on Rails, I am documenting integration of Sentry on Rails App.

Raven for Ruby

sentry-raven is the gem which will act as the client and integration layer for Sentry’s APIs.

gem 'sentry-raven'

Documentation : https://docs.sentry.io/clients/ruby/integrations/rails/

Github project : https://github.com/getsentry/raven-ruby

Configuration inside Project

Adding gem to the Gemfile

Inside your Gemfile, include the sentry-raven gem.

Making a Sentry initializer file.

Make a new file sentry.rb under the rails folder /config/initializers, and save it with following details


Raven.configure do |config|
  config.dsn = '< INSERT DSN key from SENTRY UI -> PROJECT SETTINGS -> Client DSN>'
end

Testing the configuration

Add the following code to any of your methods and check the error on Sentry UI

# inside a method
  Raven.capture do
    # capture any exceptions which happen during execution of this block
    1 / 0
  end

The method containing the above block when called, will result and error and the error should go to Sentry.

![alt text][error_img]

error_img

Once you receive the line

Sending event XXXXXXXXX to Sentry

Check the Sentry UI whether you received the error entry or not. Sentry is integrated at this point !



comments powered by Disqus