Tracking Errors with Sentry

Episode #108 by Teacher's Avatar David Kimura

Summary

Sentry is an Open Source error tracking that helps developers monitor and fix crashes in real time. Learn how to add and configure Sentry to your application.
rails error 7:44

Resources

Summary

# Gemfile
gem 'sentry-raven'

# config/initializers/sentry.rb
Raven.configure do |config|
  config.dsn = 'https://7e4ed0cd459a4368bcf12f319bdde289:e844943f3c994a6392f73959bc6866e6@sentry.io/253803'
  config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
  config.release = APP_VERSION
end

# application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :set_raven_context

  private

  def set_raven_context
    Raven.user_context(id: session[:current_user_id], foo: :bar)
    Raven.extra_context(params: params.to_unsafe_h, url: request.url)
  end
end

# config/application.rb
require_relative 'boot'

require 'rails/all'
require_relative 'version'

...