Update Raven references to use Sentry

This commit is contained in:
Paul Chavard 2021-01-28 14:49:22 +01:00
parent 6ea44eefa9
commit 41c3a98d7d
8 changed files with 17 additions and 18 deletions

View file

@ -61,7 +61,7 @@ class API::V2::GraphqlController < API::V2::BaseController
def handle_error_in_production(exception) def handle_error_in_production(exception)
id = SecureRandom.uuid id = SecureRandom.uuid
Raven.capture_exception(exception, extra: { exception_id: id }) Sentry.capture_exception(exception, extra: { exception_id: id })
render json: { render json: {
errors: [ errors: [

View file

@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception, if: -> { !Rails.env.test? } protect_from_forgery with: :exception, if: -> { !Rails.env.test? }
before_action :set_current_roles before_action :set_current_roles
before_action :load_navbar_left_pannel_partial_url before_action :load_navbar_left_pannel_partial_url
before_action :set_raven_context before_action :set_sentry_user
before_action :redirect_if_untrusted before_action :redirect_if_untrusted
before_action :reject, if: -> { feature_enabled?(:maintenance_mode) } before_action :reject, if: -> { feature_enabled?(:maintenance_mode) }
before_action :configure_permitted_parameters, if: :devise_controller? before_action :configure_permitted_parameters, if: :devise_controller?
@ -149,8 +149,8 @@ class ApplicationController < ActionController::Base
end end
end end
def set_raven_context def set_sentry_user
Raven.user_context(sentry_user) Sentry.set_user(sentry_user)
end end
# private method called by rails fwk # private method called by rails fwk

View file

@ -12,7 +12,7 @@ class ApplicationJob < ActiveJob::Base
end end
def error(job, exception) def error(job, exception)
Raven.capture_exception(exception) Sentry.capture_exception(exception)
end end
def max_attempts def max_attempts

View file

@ -13,7 +13,7 @@ class Cron::AutoArchiveProcedureJob < Cron::CronJob
procedure.close! procedure.close!
rescue StandardError => e rescue StandardError => e
Raven.capture_exception(e, extra: { procedure_id: procedure.id }) Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
end end
end end
end end

View file

@ -25,8 +25,7 @@ class ApplicationMailer < ActionMailer::Base
rescue StandardError => e rescue StandardError => e
# A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ? # A problem occured when reading logo, maybe the logo is missing and we should clean the procedure to remove logo reference ?
Raven.extra_context(procedure_id: procedure.id) Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
Raven.capture_exception(e)
nil nil
end end
end end

View file

@ -35,7 +35,7 @@ class AssignTo < ApplicationRecord
# a bug somewhere else that we need to fix. # a bug somewhere else that we need to fix.
errors = procedure_presentation.errors errors = procedure_presentation.errors
Raven.capture_message( Sentry.capture_message(
"Destroying invalid ProcedurePresentation", "Destroying invalid ProcedurePresentation",
extra: { procedure_presentation: procedure_presentation.as_json } extra: { procedure_presentation: procedure_presentation.as_json }
) )

View file

@ -1,17 +1,17 @@
describe ApplicationController, type: :controller do describe ApplicationController, type: :controller do
describe 'before_action: set_raven_context' do describe 'before_action: set_sentry_user' do
it 'is present' do it 'is present' do
before_actions = ApplicationController before_actions = ApplicationController
._process_action_callbacks ._process_action_callbacks
.filter { |process_action_callbacks| process_action_callbacks.kind == :before } .filter { |process_action_callbacks| process_action_callbacks.kind == :before }
.map(&:filter) .map(&:filter)
expect(before_actions).to include(:set_raven_context) expect(before_actions).to include(:set_sentry_user)
expect(before_actions).to include(:redirect_if_untrusted) expect(before_actions).to include(:redirect_if_untrusted)
end end
end end
describe 'set_raven_context and append_info_to_payload' do describe 'set_sentry_user and append_info_to_payload' do
let(:current_user) { nil } let(:current_user) { nil }
let(:current_instructeur) { nil } let(:current_instructeur) { nil }
let(:current_administrateur) { nil } let(:current_administrateur) { nil }
@ -24,15 +24,15 @@ describe ApplicationController, type: :controller do
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur) expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur) expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
expect(@controller).to receive(:current_super_admin).and_return(current_super_admin) expect(@controller).to receive(:current_super_admin).and_return(current_super_admin)
allow(Raven).to receive(:user_context) allow(Sentry).to receive(:set_user)
@controller.send(:set_raven_context) @controller.send(:set_sentry_user)
@controller.send(:append_info_to_payload, payload) @controller.send(:append_info_to_payload, payload)
end end
context 'when no one is logged in' do context 'when no one is logged in' do
it do it do
expect(Raven).to have_received(:user_context) expect(Sentry).to have_received(:set_user)
.with({ id: 'Guest' }) .with({ id: 'Guest' })
end end
@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do
let(:current_user) { create(:user) } let(:current_user) { create(:user) }
it do it do
expect(Raven).to have_received(:user_context) expect(Sentry).to have_received(:set_user)
.with({ id: "User##{current_user.id}" }) .with({ id: "User##{current_user.id}" })
end end
@ -79,7 +79,7 @@ describe ApplicationController, type: :controller do
let(:current_super_admin) { create(:super_admin) } let(:current_super_admin) { create(:super_admin) }
it do it do
expect(Raven).to have_received(:user_context) expect(Sentry).to have_received(:set_user)
.with({ id: "User##{current_user.id}" }) .with({ id: "User##{current_user.id}" })
end end

View file

@ -72,7 +72,7 @@ RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
error = StandardError.new('nop') error = StandardError.new('nop')
expect(buggy_procedure).to receive(:close!).and_raise(error) expect(buggy_procedure).to receive(:close!).and_raise(error)
expect(job).to receive(:procedures_to_close).and_return([buggy_procedure, procedure_hier]) expect(job).to receive(:procedures_to_close).and_return([buggy_procedure, procedure_hier])
expect(Raven).to receive(:capture_exception).with(error, extra: { procedure_id: buggy_procedure.id }) expect(Sentry).to receive(:capture_exception).with(error, extra: { procedure_id: buggy_procedure.id })
subject subject
end end