From 9adcefce02285d682f6b660da50e78df8036d435 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 29 Nov 2018 19:57:40 +0500 Subject: [PATCH] Configure Sentry error logger --- Gemfile | 3 +++ Gemfile.lock | 6 ++++++ app/controllers/application_controller.rb | 6 ++++++ config/credentials.yml.enc | 2 +- config/initializers/raven.rb | 7 +++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 config/initializers/raven.rb diff --git a/Gemfile b/Gemfile index f128be8..b06e898 100644 --- a/Gemfile +++ b/Gemfile @@ -71,6 +71,9 @@ gem 'simple_form', '~> 4.1' # get, put, post, delete. gem 'rest-client', '~> 2.0' +# A gem that provides a client interface for the Sentry error logger. +gem 'sentry-raven' + group :development, :test do # factory_bot provides a framework and DSL for defining and using factories. gem 'factory_bot_rails', '~> 4.10' diff --git a/Gemfile.lock b/Gemfile.lock index 9d79592..9e5c8e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,6 +91,8 @@ GEM railties (>= 3.0.0) faker (1.9.1) i18n (>= 0.7) + faraday (0.15.4) + multipart-post (>= 1.2, < 3) ffi (1.9.25) font-awesome-sass (5.5.0.1) sassc (>= 1.11) @@ -130,6 +132,7 @@ GEM minitest (5.11.3) msgpack (1.2.4) multi_json (1.13.1) + multipart-post (2.0.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (5.0.2) @@ -229,6 +232,8 @@ GEM sassc (2.0.0) ffi (~> 1.9.6) rake + sentry-raven (2.7.4) + faraday (>= 0.7.6, < 1.0) shoulda-matchers (4.0.0.rc1) activesupport (>= 4.2.0) simple_form (4.1.0) @@ -306,6 +311,7 @@ DEPENDENCIES rspec-rails (~> 3.8) rubocop (~> 0.60.0) sass-rails (~> 5.0) + sentry-raven shoulda-matchers (= 4.0.0.rc1) simple_form (~> 4.1) simplecov (~> 0.16) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 95714cb..a378cfd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base class NotAuthorizedError < RuntimeError; end + before_action :set_raven_context + skip_before_action :verify_authenticity_token, if: :json_request? rescue_from ActiveRecord::RecordNotFound, with: :not_found @@ -10,6 +12,10 @@ class ApplicationController < ActionController::Base private + def set_raven_context + Raven.extra_context params: params.to_unsafe_h, url: request.url + end + def json_request? request.format.json? end diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index f90e8d4..6c612cb 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -QtBlpQuGa0BjUXzdXxBXqXTp1qUF9xc4ULh4fJgAjWsShLAU62TwOmjiLw6gKeIGIZd9n1/hV6LcQRi8lPzq6kOHeLoBbKXub8+9lAZ/zsi+2LMvlgvlacZWw02BEpQMIoZuXrEojpzFSj+2b6Gx6ucC8ArSg6u64i+B7vl8i+MReQ7aKYn48J9TQ1NM4wwnpsSLC4VLlQ==--FuMPDqLpq9qRARv0--m/DxSG1WI+CMj/K3rtJAFw== \ No newline at end of file +i9dq5b23/WWVOHGT0oGn4az0IUsiiVxaKgALjdbjioR6mhG1jCbAgbLlM4B9RBD81bD9Ej6C1fP/09el7UqRHXF/2tDSUajqSshcJPw+IoyHqv75QC3DS8q/g8b8/C8Lq/Hdvf0tf1aL4/WWWPGx17QKnZ4pWIwS5Uwv3DW9Eu9L/4kF9aRrqIklu5BeAgbzkmJLCMWW1ibeMoqmQivzWtpgQB6dFuLTagSzNLnjBhS9115L7io39tpgHxB1OMagucUAD4HzDNlbbVxlMHjpdUm/1lGrdOmlO5KtVimk7Re35zzCGVWSwvZUD4hU2uxDpsj1h9wnlE0A4CnEOgc=--8xj8CLI7TZtxNsNg--FqcFVtzsNWWfQk7BnZg/oQ== \ No newline at end of file diff --git a/config/initializers/raven.rb b/config/initializers/raven.rb new file mode 100644 index 0000000..37cc8b0 --- /dev/null +++ b/config/initializers/raven.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +Raven.configure do |config| + config.dsn = Rails.application.secrets.raven_dsn +end