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 'mnemosyne-ruby'
gem 'newrelic_rpm'
gem 'sentry-raven'
gem 'sentry-rails'
gem 'sentry-ruby'
group :development, :staging do
gem 'better_errors'

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -196,7 +196,7 @@ class SubmissionsController < ApplicationController
rescue JSON::ParserError => error
socket.send 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
@ -417,7 +417,7 @@ class SubmissionsController < ApplicationController
container = Docker::Container.get(params[:container_id])
DockerClient.destroy_container(container)
rescue Docker::Error::NotFoundError => error
Raven.capture_exception(error)
Sentry.capture_exception(error)
ensure
head :ok
end
@ -447,7 +447,7 @@ class SubmissionsController < ApplicationController
yield(server_sent_event) if block_given?
server_sent_event.write({code: 200}, event: 'close')
rescue => exception
Raven.capture_exception(exception)
Sentry.capture_exception(exception)
logger.error(exception.message)
logger.error(exception.backtrace.join("\n"))
server_sent_event.write({code: 500}, event: 'close')

View File

@ -23,7 +23,7 @@ class UserExerciseFeedbacksController < ApplicationController
end
def create
Raven.extra_context(params: uef_params)
Sentry.set_extras(params: uef_params)
@exercise = Exercise.find(uef_params[:exercise_id])
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
# 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

View File

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

View File

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

View File

@ -40,7 +40,7 @@
- output_runs.each do |testrun|
- output = testrun.try(:output)
- if output
- Raven.extra_context(output: output)
- Sentry.set_extras(output: output)
- begin
- Timeout::timeout(2) do
// (?:\\"|.) 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|
p.rmtree
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}")
end
# FileUtils.rmdir(Pathname.new(local_workspace_path))
@ -237,7 +237,7 @@ class DockerClient
clean_container_workspace(container)
FileUtils.rmtree(local_workspace_path(container))
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}")
end

View File

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

View File

@ -34,7 +34,7 @@ class PyLintAdapter < TestingFrameworkAdapter
end || []
end
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 = []
end
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
if captures.nil?
Raven.capture_message({regex: regex, message: message[:result]}.to_json)
Sentry.capture_message({regex: regex, message: message[:result]}.to_json)
replacement = {}
else
replacement = captures.each do |key, value|
@ -85,8 +85,8 @@ class PyLintAdapter < TestingFrameworkAdapter
assessment
rescue StandardError => e
# A key was not defined or something really bad happened
Raven.extra_context(assessment)
Raven.capture_exception(e)
Sentry.set_extras(assessment)
Sentry.capture_exception(e)
assessment
end
@ -104,7 +104,7 @@ class PyLintAdapter < TestingFrameworkAdapter
# Read config key
I18n.t(keys.append('log_missing').join('.'), default: false)
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
end
end

View File

@ -28,7 +28,7 @@ class PyUnitAdapter < TestingFrameworkAdapter
}.flatten || []
end
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 = []
end
{count: count, failed: failed + errors, error_messages: assertion_error_matches}

View File

@ -166,7 +166,7 @@ describe InternalUsersController do
describe 'GET #forgot_password' do
context 'when no user is logged in' 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)
get :forgot_password
@ -178,7 +178,7 @@ describe InternalUsersController do
context 'when a user is already logged in' 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)
get :forgot_password

View File

@ -155,7 +155,7 @@ describe SessionsController do
describe 'DELETE #destroy' do
let(:user) { double }
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)
}
@ -219,7 +219,7 @@ describe SessionsController do
describe 'GET #new' do
context 'when no user is logged in' 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)
get :new
@ -231,7 +231,7 @@ describe SessionsController do
context 'when a user is already logged in' 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))
get :new