[RUBY] Track Rails app errors with Sentry


Contract from the following https://sentry.io/signup/

You will create a project at the time of contract, and the setup method is written on the screen after creating the project, so there should be no problem if you proceed according to the procedure. Just in case, I will reorganize it like myself.

Basic usage


gem "sentry-raven"
$ bundle install


module AppName
  class Application < Rails::Application
    Raven.configure do |config|
      config.dsn = "https://#{ENV['SENTRY_KEY']}@#{ENV['SENTRY_SECRET']}.sentry.io/#{ENV['SENTRY_ID']}"

In the setup method displayed on the Sentry site, all the IDs etc. are written directly, so I put it in an environment variable.

Be able to pick up parameters and session information


class ApplicationController < ActionController::Base
  before_action :set_raven_context


  def set_raven_context
    Raven.user_context(id: session[:current_user_id]) # or anything else in session
    Raven.extra_context(params: params.to_unsafe_h, url: request.url)

Do not record password in clear text

$ touch config/initializers/sentry.rb


Raven.configure do |config|
  config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)

See only errors in production

By default, all development environment errors will be displayed in a list, so correct the settings.

Settings> Projects> Project name> Environments> hide non-production environments  2020-09-24 14.42.26.png


--Introducing Sentry to Rails application --Qiita


UI is really Slack lol  2020-09-18 16.23.44.png

Recommended Posts

Track Rails app errors with Sentry
[Rails6] Create a new app with Rails [Beginner]
[Rails 5] Create a new app with Rails [Beginner]
[AWS] Publish rails app with nginx + puma
Downgrade an existing app created with rails 5.2.4 to 5.1.6
Publish the app made with ruby on rails
rails new app is not created with app name
How to push an app developed with Rails to Github
[Heroku] Associate AWS S3 with the deployed Rails app
Rails deploy with Docker
[Rails 6] RuntimeError with $ rails s
Handle devise with Rails
[Rails] Learning with Rails tutorial
[Rails] Test with RSpec
[Rails] Development with MySQL
Supports multilingualization with Rails!
How to get started with creating a Rails app
Double polymorphic with Rails
Rough procedure verbalized output when creating an app with Rails
[Rails] I tried to create a mini app with FullCalendar
I want to push an app made with Rails 6 to GitHub
How to specify db when creating an app with rails
Get Youtube channel information with Rails app (using Yt gem)
[Rails] Upload videos with Rails (ActiveStorage)
Try using view_component with rails
[Vue Rails] "Hello Vue!" Displayed with Vue + Rails
Japaneseize using i18n with Rails
API creation with Rails + GraphQL
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
[Rails] Specify format with link_to
Login function implementation with rails
[Rails] New app creation --Notes--
Incorporate circleCI into CircleCI Rails app
How to use Rails Current Attributes to track nginx (web server) and unicorn (app server) logs with X-Request-ID
[Docker] Use whenever with Docker + Rails
The story of the first Rails app refactored with a self-made helper
[Rails] I made a simple calendar mini app with customized specifications.