From 3bed3486884cbd8ac55b363ccaf77399691793a7 Mon Sep 17 00:00:00 2001 From: Jorai Geertsema Date: Mon, 17 Feb 2025 11:45:15 +0100 Subject: [PATCH] intial commit --- Gemfile | 4 +++- Gemfile.lock | 22 ++++++++++++++-------- app/controllers/application_controller.rb | 9 ++++----- app/jobs/sentry_job.rb | 8 -------- config/initializers/sentry.rb | 12 ++++-------- spec/jobs/sentry_job_spec.rb | 14 -------------- 6 files changed, 25 insertions(+), 44 deletions(-) delete mode 100644 app/jobs/sentry_job.rb delete mode 100644 spec/jobs/sentry_job_spec.rb diff --git a/Gemfile b/Gemfile index 70e44b44..9b62fb51 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,9 @@ gem 'redis', '~> 5.3' gem 'roo', '~> 2.10', '>= 2.10.1' gem 'ruby-filemagic', '~> 0.7', '>= 0.7.3' gem 'rubyzip', '~> 2.4', '>= 2.4.1' -gem 'sentry-raven', '~> 3.1', '>= 3.1.2' +gem 'sentry-rails', '~> 5.5' +gem 'sentry-ruby', '~> 5.5' +gem 'sentry-sidekiq', '~> 5.5' gem 'sepa_king', '~> 0.14' gem 'sidekiq', '~> 7.3', '>= 7.3.8' gem 'sidekiq-scheduler', '~> 5.0', '>= 5.0.6' diff --git a/Gemfile.lock b/Gemfile.lock index 275d3843..9090d0c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,6 +93,8 @@ GEM coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) + bigdecimal (3.1.9) + bigdecimal (3.1.9-java) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) bootsnap (1.18.4) @@ -161,10 +163,6 @@ GEM railties (>= 5.0.0) faker (3.5.1) i18n (>= 1.8.11, < 2) - faraday (2.2.0) - faraday-net_http (~> 2.0) - ruby2_keywords (>= 0.0.4) - faraday-net_http (2.0.1) fastimage (2.2.6) ffi (1.17.1) ffi-compiler (1.3.2) @@ -444,12 +442,18 @@ GEM ruby-vips (2.2.2) ffi (~> 1.12) logger - ruby2_keywords (0.0.5) rubyzip (2.4.1) rufus-scheduler (3.9.2) fugit (~> 1.1, >= 1.11.1) - sentry-raven (3.1.2) - faraday (>= 1.0) + sentry-rails (5.22.4) + railties (>= 5.0) + sentry-ruby (~> 5.22.4) + sentry-ruby (5.22.4) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + sentry-sidekiq (5.22.4) + sentry-ruby (~> 5.22.4) + sidekiq (>= 3.0) sepa_king (0.14.0) activemodel (>= 4.2) iban-tools @@ -592,7 +596,9 @@ DEPENDENCIES rubocop-rspec ruby-filemagic (~> 0.7, >= 0.7.3) rubyzip (~> 2.4, >= 2.4.1) - sentry-raven (~> 3.1, >= 3.1.2) + sentry-rails (~> 5.5) + sentry-ruby (~> 5.5) + sentry-sidekiq (~> 5.5) sepa_king (~> 0.14) sidekiq (~> 7.3, >= 7.3.8) sidekiq-scheduler (~> 5.0, >= 5.0.6) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f710b923..356ee7a4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < JSONAPI::ResourceController include Pundit::Authorization before_action :set_paper_trail_whodunnit - before_action :set_raven_context + before_action :set_sentry_context protect_from_forgery with: :null_session rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized @@ -27,12 +27,11 @@ def current_application private - # See https://github.com/getsentry/raven-ruby/blob/master/docs/integrations/rails.rst - def set_raven_context - Raven.user_context( + def set_sentry_context + Sentry.set_user( id: current_user.try(:id) ) - Raven.extra_context( + Sentry.set_extras( params: params.to_unsafe_h, url: request.url ) diff --git a/app/jobs/sentry_job.rb b/app/jobs/sentry_job.rb deleted file mode 100644 index defc7b22..00000000 --- a/app/jobs/sentry_job.rb +++ /dev/null @@ -1,8 +0,0 @@ -# See https://github.com/getsentry/raven-ruby#async -class SentryJob < ApplicationJob - queue_as :default - - def perform(event) - Raven.send_event(event) - end -end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 3d962ea4..2cf0ec2a 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,10 +1,6 @@ -Raven.configure do |config| +Sentry.init do |config| config.dsn = Rails.application.config.x.sentry_dsn - config.environments = %w[production staging] - config.release = ENV['BUILD_HASH'] - config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s) - - config.async = lambda { |event| - SentryJob.perform_later(event.to_hash) - } + config.enabled_environments = %w[production staging] + config.environment = Rails.env + config.release = ENV.fetch('BUILD_HASH', nil) end diff --git a/spec/jobs/sentry_job_spec.rb b/spec/jobs/sentry_job_spec.rb deleted file mode 100644 index bafb9f00..00000000 --- a/spec/jobs/sentry_job_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe SentryJob, type: :job do - describe '#perform' do - let(:job) { described_class.new } - - before do - allow(Raven).to receive(:send_event) - job.perform('Example event') - end - - it { expect(Raven).to have_received(:send_event).with('Example event') } - end -end