diff --git a/Gemfile b/Gemfile index ceb730e..b9c0461 100644 --- a/Gemfile +++ b/Gemfile @@ -45,9 +45,13 @@ group :production do gem 'dalli' gem 'sendgrid-ruby' gem 'lograge' + gem "sentry-rails" gem 'sentry-raven' + gem "sentry-ruby" + gem "sentry-sidekiq" gem 'sidekiq' gem 'rails_autoscale_agent' gem 'scout_apm' + gem "stackprof" gem 'rexml' end diff --git a/Gemfile.lock b/Gemfile.lock index bc15fd3..67ed2a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -776,8 +776,17 @@ GEM semantic_range (3.0.0) sendgrid-ruby (6.7.0) ruby_http_client (~> 3.4) + sentry-rails (5.19.0) + railties (>= 5.0) + sentry-ruby (~> 5.19.0) sentry-raven (3.1.2) faraday (>= 1.0) + sentry-ruby (5.19.0) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + sentry-sidekiq (5.19.0) + sentry-ruby (~> 5.19.0) + sidekiq (>= 3.0) shakapacker (7.1.0) activesupport (>= 5.2) rack-proxy (>= 0.6.1) @@ -806,6 +815,7 @@ GEM spring-watcher-listen (2.1.0) listen (>= 2.7, < 4.0) spring (>= 4) + stackprof (0.2.26) statsd-ruby (1.5.0) stringio (3.1.1) temple (0.10.3) @@ -898,8 +908,12 @@ DEPENDENCIES rspec-rails scout_apm sendgrid-ruby + sentry-rails sentry-raven + sentry-ruby + sentry-sidekiq sidekiq + stackprof web-console wkhtmltopdf-binary (= 0.12.6.6) diff --git a/app/controllers/decidim_controller.rb b/app/controllers/decidim_controller.rb index 2b9e908..d126615 100644 --- a/app/controllers/decidim_controller.rb +++ b/app/controllers/decidim_controller.rb @@ -7,7 +7,7 @@ class DecidimController < ApplicationController private def set_raven_context - return unless Rails.application.secrets.sentry_enabled? + return unless Rails.application.secrets.sentry_enabled Raven.user_context({id: try(:current_user).try(:id)}.merge(session)) Raven.extra_context(params: params.to_unsafe_h, url: request.url) end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb new file mode 100644 index 0000000..59a1703 --- /dev/null +++ b/config/initializers/sentry.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +if Rails.application.secrets.sentry_enabled + Sentry.init do |config| + config.dsn = ENV.fetch("SENTRY_DSN", nil) + config.traces_sample_rate = ENV.fetch("SENTRY_TRACES_SAMPLE_RATE", "0.5").to_f + config.profiles_sample_rate = ENV.fetch("SENTRY_PROFILES_SAMPLE_RATE", "0.5").to_f + config.environment = ENV["HEROKU_APP_NAME"].presence || "production" + end +end