Sentry

Setup Sentry
Icons/chart bar
Used 10 times
Created by
D Dale Zak

Usage
Add your environment variable:
  • SENTRY_DSN

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zOvsol"
Template Source

Review the code before running this template on your machine.

run 'bundle add sentry-raven'

run 'bundle install'

file 'config/initializers/sentry.rb', <<-CODE
if ENV['SENTRY_DSN'].present?
  Raven.configure do |config|
    config.dsn = ENV['SENTRY_DSN']
    config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
  end
end  
CODE

inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do
  "	before_action :set_raven_context

  def set_raven_context
    if user_signed_in?
      Raven.user_context(id: current_user.id, email: current_user.email, ip_address: request.ip)    
    else 
      Raven.user_context(id: session.id, ip_address: request.ip)
    end
    Raven.extra_context(params: params.to_unsafe_h, url: request.url, ip_address: request.ip)
  end

  def log_exception(request, params, exception)
    Raven.extra_context(url: request.url, params: params.to_unsafe_h)
    Raven.capture_exception(exception)
  end\n"
end
Comments

Sign up or Login to leave a comment.

© 2023 GoRails, LLC