Upgrade to newest Sentry

This commit is contained in:
Sebastian Serth
2021-03-04 14:02:16 +01:00
parent 22adcaddba
commit b10e23dd16
20 changed files with 72 additions and 67 deletions

View File

@ -45,7 +45,8 @@ gem 'whenever', require: false
gem 'concurrent-ruby' gem 'concurrent-ruby'
gem 'mnemosyne-ruby' gem 'mnemosyne-ruby'
gem 'newrelic_rpm' gem 'newrelic_rpm'
gem 'sentry-raven' gem 'sentry-rails'
gem 'sentry-ruby'
group :development, :staging do group :development, :staging do
gem 'better_errors' gem 'better_errors'

View File

@ -228,7 +228,7 @@ GEM
nested_form (0.3.2) nested_form (0.3.2)
netrc (0.11.0) netrc (0.11.0)
newrelic_rpm (6.15.0) newrelic_rpm (6.15.0)
nio4r (2.5.5) nio4r (2.5.7)
nokogiri (1.10.10) nokogiri (1.10.10)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
nyan-cat-formatter (0.12.0) nyan-cat-formatter (0.12.0)
@ -398,8 +398,16 @@ GEM
childprocess (>= 0.5, < 4.0) childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2) rubyzip (>= 1.2.2)
semantic_range (2.3.1) semantic_range (2.3.1)
sentry-raven (3.1.1) sentry-rails (4.2.2)
rails (>= 5.0)
sentry-ruby-core (~> 4.2.0)
sentry-ruby (4.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
faraday (>= 1.0) faraday (>= 1.0)
sentry-ruby-core (= 4.2.2)
sentry-ruby-core (4.2.2)
concurrent-ruby
faraday
shoulda-matchers (4.5.1) shoulda-matchers (4.5.1)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
simplecov (0.21.2) simplecov (0.21.2)
@ -527,7 +535,8 @@ DEPENDENCIES
rubyzip rubyzip
sass-rails sass-rails
selenium-webdriver selenium-webdriver
sentry-raven sentry-rails
sentry-ruby
shoulda-matchers shoulda-matchers
simplecov simplecov
slim-rails slim-rails

View File

@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
MEMBER_ACTIONS = %i[destroy edit show update].freeze MEMBER_ACTIONS = %i[destroy edit show update].freeze
after_action :verify_authorized, except: %i[help welcome] after_action :verify_authorized, except: %i[help welcome]
before_action :set_raven_context, :set_locale, :allow_iframe_requests, :load_embed_options before_action :set_sentry_context, :set_locale, :allow_iframe_requests, :load_embed_options
protect_from_forgery(with: :exception, prepend: true) protect_from_forgery(with: :exception, prepend: true)
rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized
@ -20,17 +20,17 @@ class ApplicationController < ActionController::Base
raise Pundit::NotAuthorizedError unless current_user raise Pundit::NotAuthorizedError unless current_user
end end
def set_raven_context def set_sentry_context
return if current_user.blank? return if current_user.blank?
Raven.user_context( Sentry.set_user(
id: current_user.id, id: current_user.id,
type: current_user.class.name, type: current_user.class.name,
username: current_user.displayname, username: current_user.displayname,
consumer: current_user.consumer.name consumer: current_user.consumer.name
) )
end end
private :set_raven_context private :set_sentry_context
def render_not_authorized def render_not_authorized
respond_to do |format| respond_to do |format|
@ -50,7 +50,7 @@ class ApplicationController < ActionController::Base
def set_locale def set_locale
session[:locale] = params[:custom_locale] || params[:locale] || session[:locale] session[:locale] = params[:custom_locale] || params[:locale] || session[:locale]
I18n.locale = session[:locale] || I18n.default_locale I18n.locale = session[:locale] || I18n.default_locale
Raven.extra_context(locale: I18n.locale) Sentry.set_extras(locale: I18n.locale)
end end
private :set_locale private :set_locale
@ -68,7 +68,7 @@ class ApplicationController < ActionController::Base
else else
{} {}
end end
Raven.extra_context(@embed_options) Sentry.set_extras(@embed_options)
@embed_options @embed_options
end end
private :load_embed_options private :load_embed_options

View File

@ -154,7 +154,7 @@ module Lti
if provider.nil? if provider.nil?
{status: 'error'} {status: 'error'}
elsif provider.outcome_service? elsif provider.outcome_service?
Raven.extra_context({ Sentry.set_extras({
provider: provider.inspect, provider: provider.inspect,
score: submission.normalized_score, score: submission.normalized_score,
lti_parameter: lti_parameter.inspect, lti_parameter: lti_parameter.inspect,

View File

@ -121,7 +121,7 @@ class ExecutionEnvironmentsController < ApplicationController
rescue DockerClient::Error => error rescue DockerClient::Error => error
@docker_images = [] @docker_images = []
flash[:warning] = error.message flash[:warning] = error.message
Raven.capture_exception(error) Sentry.capture_exception(error)
end end
private :set_docker_images private :set_docker_images

View File

@ -188,7 +188,7 @@ class ExercisesController < ApplicationController
rescue Proforma::ProformaError rescue Proforma::ProformaError
render json: t('exercises.import_codeharbor.import_errors.invalid'), status: 400 render json: t('exercises.import_codeharbor.import_errors.invalid'), status: 400
rescue StandardError => e rescue StandardError => e
Raven.capture_exception(e) Sentry.capture_exception(e)
render json: t('exercises.import_codeharbor.import_errors.internal_error'), status: 500 render json: t('exercises.import_codeharbor.import_errors.internal_error'), status: 500
end end
@ -392,7 +392,7 @@ class ExercisesController < ApplicationController
end end
def redirect_to_lti_return_path def redirect_to_lti_return_path
Raven.extra_context( Sentry.set_extras(
consumers_id: @submission.user&.consumer, consumers_id: @submission.user&.consumer,
external_users_id: @submission.user_id, external_users_id: @submission.user_id,
exercises_id: @submission.exercise_id, exercises_id: @submission.exercise_id,

View File

@ -196,7 +196,7 @@ class SubmissionsController < ApplicationController
rescue JSON::ParserError => error rescue JSON::ParserError => error
socket.send data socket.send data
Rails.logger.debug('Rescued parsing error, sent the received client data to docker:' + data) Rails.logger.debug('Rescued parsing error, sent the received client data to docker:' + data)
Raven.extra_context(data: data) Sentry.set_extras(data: data)
end end
end end
@ -417,7 +417,7 @@ class SubmissionsController < ApplicationController
container = Docker::Container.get(params[:container_id]) container = Docker::Container.get(params[:container_id])
DockerClient.destroy_container(container) DockerClient.destroy_container(container)
rescue Docker::Error::NotFoundError => error rescue Docker::Error::NotFoundError => error
Raven.capture_exception(error) Sentry.capture_exception(error)
ensure ensure
head :ok head :ok
end end
@ -447,7 +447,7 @@ class SubmissionsController < ApplicationController
yield(server_sent_event) if block_given? yield(server_sent_event) if block_given?
server_sent_event.write({code: 200}, event: 'close') server_sent_event.write({code: 200}, event: 'close')
rescue => exception rescue => exception
Raven.capture_exception(exception) Sentry.capture_exception(exception)
logger.error(exception.message) logger.error(exception.message)
logger.error(exception.backtrace.join("\n")) logger.error(exception.backtrace.join("\n"))
server_sent_event.write({code: 500}, event: 'close') server_sent_event.write({code: 500}, event: 'close')

View File

@ -23,7 +23,7 @@ class UserExerciseFeedbacksController < ApplicationController
end end
def create def create
Raven.extra_context(params: uef_params) Sentry.set_extras(params: uef_params)
@exercise = Exercise.find(uef_params[:exercise_id]) @exercise = Exercise.find(uef_params[:exercise_id])
rfc = RequestForComment.unsolved.where(exercise_id: @exercise.id, user_id: current_user.id).first rfc = RequestForComment.unsolved.where(exercise_id: @exercise.id, user_id: current_user.id).first

View File

@ -24,7 +24,7 @@ class LinterCheckRun < ApplicationRecord
) )
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
# Something bad happened. Probably, the RegEx in lib/py_lint_adapter.rb didn't work. # Something bad happened. Probably, the RegEx in lib/py_lint_adapter.rb didn't work.
Raven.extra_context(testrun: testrun, linter_result: linter_result) Sentry.set_extras(testrun: testrun, linter_result: linter_result)
end end
end end
end end

View File

@ -11,7 +11,7 @@ h2 Version
div.mb-4 div.mb-4
= "Release:" = "Release:"
pre = Raven.configuration.release pre = Sentry.configuration.release
h2 Docker h2 Docker

View File

@ -20,12 +20,12 @@ html lang="#{I18n.locale || I18n.default_locale}"
script type="text/javascript" script type="text/javascript"
| I18n.defaultLocale = "#{I18n.default_locale}"; | I18n.defaultLocale = "#{I18n.default_locale}";
| I18n.locale = "#{I18n.locale}"; | I18n.locale = "#{I18n.locale}";
- unless Raven.configuration.current_environment == "development" - unless Sentry.configuration.environment == "development"
| Sentry.init({ | Sentry.init({
| dsn: 'https://637ca99538224b4bb28cd9e670e1b372@sentry.xikolo.de/33', | dsn: 'https://637ca99538224b4bb28cd9e670e1b372@sentry.xikolo.de/33',
| attachStacktrace: true, | attachStacktrace: true,
| release: "#{Raven.configuration.release}", | release: "#{Sentry.configuration.release}",
| environment: "#{Raven.configuration.current_environment}", | environment: "#{Sentry.configuration.environment}",
| }); | });
- if @current_user - if @current_user
| Sentry.configureScope(function(scope) { | Sentry.configureScope(function(scope) {

View File

@ -40,7 +40,7 @@
- output_runs.each do |testrun| - output_runs.each do |testrun|
- output = testrun.try(:output) - output = testrun.try(:output)
- if output - if output
- Raven.extra_context(output: output) - Sentry.set_extras(output: output)
- begin - begin
- Timeout::timeout(2) do - Timeout::timeout(2) do
// (?:\\"|.) is required to correctly identify " within the output. // (?:\\"|.) is required to correctly identify " within the output.

View File

@ -1,21 +0,0 @@
# frozen_string_literal: true
require 'concurrent'
Rails.application.tap do |app|
pool = ::Concurrent::ThreadPoolExecutor.new(max_queue: 10)
Raven.configure do |config|
config.sanitize_fields = app.config.filter_parameters.map(&:to_s)
config.processors -= [Raven::Processor::PostData] # Do this to send POST data
# config.excluded_exceptions -= ['ActionController::InvalidAuthenticityToken']
config.async = lambda do |event|
pool.post { ::Raven.send_event(event) }
end
# Do not sent full list of gems with each event
config.send_modules = false
end
end

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
Sentry.init do |config|
# Do not send full list of gems with each event
config.send_modules = false
# Send some more data, such as request bodies
config.send_default_pii = true
# Strip sensitive user data such as passwords from event annotations
filter = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
config.before_send = lambda do |event, _hint|
event.request.data = filter.filter(event.request.data)
event
end
end

View File

@ -38,7 +38,7 @@ class DockerClient
Pathname.new(local_workspace_path).children.each do |p| Pathname.new(local_workspace_path).children.each do |p|
p.rmtree p.rmtree
rescue Errno::ENOENT, Errno::EACCES => error rescue Errno::ENOENT, Errno::EACCES => error
Raven.capture_exception(error) Sentry.capture_exception(error)
Rails.logger.error("clean_container_workspace: Got #{error.class.to_s}: #{error.to_s}") Rails.logger.error("clean_container_workspace: Got #{error.class.to_s}: #{error.to_s}")
end end
# FileUtils.rmdir(Pathname.new(local_workspace_path)) # FileUtils.rmdir(Pathname.new(local_workspace_path))
@ -237,7 +237,7 @@ class DockerClient
clean_container_workspace(container) clean_container_workspace(container)
FileUtils.rmtree(local_workspace_path(container)) FileUtils.rmtree(local_workspace_path(container))
rescue Errno::ENOENT, Errno::EACCES => error rescue Errno::ENOENT, Errno::EACCES => error
Raven.capture_exception(error) Sentry.capture_exception(error)
Rails.logger.error("clean_container_workspace: Got #{error.class.to_s}: #{error.to_s}") Rails.logger.error("clean_container_workspace: Got #{error.class.to_s}: #{error.to_s}")
end end

View File

@ -16,16 +16,16 @@ class DockerContainerPool
#Rails.logger.debug('created container ' + container.to_s + ' for execution environment ' + execution_environment.to_s) #Rails.logger.debug('created container ' + container.to_s + ' for execution environment ' + execution_environment.to_s)
container container
rescue StandardError => e rescue StandardError => e
Raven.extra_context({container: container.inspect, execution_environment: execution_environment.inspect, config: config.inspect}) Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect, config: config.inspect})
Raven.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
def self.return_container(container, execution_environment) def self.return_container(container, execution_environment)
Faraday.get(config[:location] + "/docker_container_pool/return_container/" + container.id) Faraday.get(config[:location] + "/docker_container_pool/return_container/" + container.id)
rescue StandardError => e rescue StandardError => e
Raven.extra_context({container: container.inspect, execution_environment: execution_environment.inspect, config: config.inspect}) Sentry.set_extras({container: container.inspect, execution_environment: execution_environment.inspect, config: config.inspect})
Raven.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
@ -36,8 +36,8 @@ class DockerContainerPool
container_id = JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/get_container/" + execution_environment.id.to_s).body)['id'] container_id = JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/get_container/" + execution_environment.id.to_s).body)['id']
Docker::Container.get(container_id) unless container_id.blank? Docker::Container.get(container_id) unless container_id.blank?
rescue StandardError => e rescue StandardError => e
Raven.extra_context({container_id: container_id.inspect, execution_environment: execution_environment.inspect, config: config.inspect}) Sentry.set_extras({container_id: container_id.inspect, execution_environment: execution_environment.inspect, config: config.inspect})
Raven.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
else else
@ -53,15 +53,15 @@ class DockerContainerPool
response = JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/quantities").body) response = JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/quantities").body)
response.transform_keys(&:to_i) response.transform_keys(&:to_i)
rescue StandardError => e rescue StandardError => e
Raven.extra_context({response: response.inspect}) Sentry.set_extras({response: response.inspect})
Raven.capture_exception(e) Sentry.capture_exception(e)
[] []
end end
def self.dump_info def self.dump_info
JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/dump_info").body) JSON.parse(Faraday.get(config[:location] + "/docker_container_pool/dump_info").body)
rescue StandardError => e rescue StandardError => e
Raven.capture_exception(e) Sentry.capture_exception(e)
nil nil
end end
end end

View File

@ -34,7 +34,7 @@ class PyLintAdapter < TestingFrameworkAdapter
end || [] end || []
end end
rescue Timeout::Error rescue Timeout::Error
Raven.capture_message({stdout: output[:stdout], regex: ASSERTION_ERROR_REGEXP}.to_json) Sentry.capture_message({stdout: output[:stdout], regex: ASSERTION_ERROR_REGEXP}.to_json)
assertion_error_matches = [] assertion_error_matches = []
end end
concatenated_errors = assertion_error_matches.map { |result| "#{result[:name]}: #{result[:result]}" }.flatten concatenated_errors = assertion_error_matches.map { |result| "#{result[:name]}: #{result[:result]}" }.flatten
@ -62,7 +62,7 @@ class PyLintAdapter < TestingFrameworkAdapter
captures = message[:result].match(Regexp.new(regex))&.named_captures&.symbolize_keys captures = message[:result].match(Regexp.new(regex))&.named_captures&.symbolize_keys
if captures.nil? if captures.nil?
Raven.capture_message({regex: regex, message: message[:result]}.to_json) Sentry.capture_message({regex: regex, message: message[:result]}.to_json)
replacement = {} replacement = {}
else else
replacement = captures.each do |key, value| replacement = captures.each do |key, value|
@ -85,8 +85,8 @@ class PyLintAdapter < TestingFrameworkAdapter
assessment assessment
rescue StandardError => e rescue StandardError => e
# A key was not defined or something really bad happened # A key was not defined or something really bad happened
Raven.extra_context(assessment) Sentry.set_extras(assessment)
Raven.capture_exception(e) Sentry.capture_exception(e)
assessment assessment
end end
@ -104,7 +104,7 @@ class PyLintAdapter < TestingFrameworkAdapter
# Read config key # Read config key
I18n.t(keys.append('log_missing').join('.'), default: false) I18n.t(keys.append('log_missing').join('.'), default: false)
end end
Raven.capture_message({key: key, default: default}.to_json) if translation == default && log_missing Sentry.capture_message({key: key, default: default}.to_json) if translation == default && log_missing
translation translation
end end
end end

View File

@ -28,7 +28,7 @@ class PyUnitAdapter < TestingFrameworkAdapter
}.flatten || [] }.flatten || []
end end
rescue Timeout::Error rescue Timeout::Error
Raven.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json) Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json)
assertion_error_matches = [] assertion_error_matches = []
end end
{count: count, failed: failed + errors, error_messages: assertion_error_matches} {count: count, failed: failed + errors, error_messages: assertion_error_matches}

View File

@ -166,7 +166,7 @@ describe InternalUsersController do
describe 'GET #forgot_password' do describe 'GET #forgot_password' do
context 'when no user is logged in' do context 'when no user is logged in' do
before(:each) do before(:each) do
allow(controller).to receive(:set_raven_context).and_return(nil) allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(nil) expect(controller).to receive(:current_user).and_return(nil)
get :forgot_password get :forgot_password
@ -178,7 +178,7 @@ describe InternalUsersController do
context 'when a user is already logged in' do context 'when a user is already logged in' do
before(:each) do before(:each) do
allow(controller).to receive(:set_raven_context).and_return(nil) allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(user) expect(controller).to receive(:current_user).and_return(user)
get :forgot_password get :forgot_password

View File

@ -155,7 +155,7 @@ describe SessionsController do
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
let(:user) { double } let(:user) { double }
before(:each) { before(:each) {
allow(controller).to receive(:set_raven_context).and_return(nil) allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).at_least(:once).and_return(user) expect(controller).to receive(:current_user).at_least(:once).and_return(user)
} }
@ -219,7 +219,7 @@ describe SessionsController do
describe 'GET #new' do describe 'GET #new' do
context 'when no user is logged in' do context 'when no user is logged in' do
before(:each) do before(:each) do
allow(controller).to receive(:set_raven_context).and_return(nil) allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(nil) expect(controller).to receive(:current_user).and_return(nil)
get :new get :new
@ -231,7 +231,7 @@ describe SessionsController do
context 'when a user is already logged in' do context 'when a user is already logged in' do
before(:each) do before(:each) do
allow(controller).to receive(:set_raven_context).and_return(nil) allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher)) expect(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))
get :new get :new