setup a generalized way to leave out errors from sentry reporting

refs CNVS-20836

Once this is merged, plugins or extensions can
register their own exceptions if they don't
want them broadcast to sentry for whatever reason
(there are some job failures that are a good candidate
for this)

Change-Id: Ic3bceb8185a92479166ec55c8c6c66dacf259f5a
Reviewed-on: https://gerrit.instructure.com/55678
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Ethan Vizitei <evizitei@instructure.com>
This commit is contained in:
Ethan Vizitei 2015-06-03 16:49:22 -06:00 committed by Ethan Vizitei
parent 74cb0f5c6d
commit 21a728f05c
2 changed files with 64 additions and 13 deletions

View File

@ -5,7 +5,29 @@ class SentryProxy
if exception.is_a?(String) || exception.is_a?(Symbol) if exception.is_a?(String) || exception.is_a?(Symbol)
Raven.capture_message(exception.to_s, data) Raven.capture_message(exception.to_s, data)
else else
Raven.capture_exception(exception, data) Raven.capture_exception(exception, data) if reportable?(exception)
end end
end end
# There are some errors we don't care to report to sentry because
# they don't indicate a problem, but not all of them are necessarily
# in the canvas codebase (and so we might not know about them at the time we
# configure the sentry client in an initializer). This allows plugins and extensions
# to register their own errors that they don't want to get reported to sentry
def self.register_ignorable_error(error_class)
@ignorable_errors = (self.ignorable_errors << error_class).uniq
end
def self.ignorable_errors
@ignorable_errors ||= []
end
def self.clear_ignorable_errors
@ignorable_errors = []
end
def self.reportable?(exception)
!ignorable_errors.include?(exception.class)
end
end end

View File

@ -3,21 +3,50 @@ require_relative "../spec_helper"
describe SentryProxy do describe SentryProxy do
let(:data){ {a: 'b', c: 'd'} } let(:data){ {a: 'b', c: 'd'} }
it "forwards exceptions on to raven" do before(:each){ SentryProxy.clear_ignorable_errors }
e = StandardError.new
Raven.expects(:capture_exception).with(e, data) class MyCustomError < StandardError
SentryProxy.capture(e, data)
end end
it "passes messages to the capture_message raven method" do describe ".capture" do
e = "Some Message" it "forwards exceptions on to raven" do
Raven.expects(:capture_message).with(e, data) e = MyCustomError.new
SentryProxy.capture(e, data) Raven.expects(:capture_exception).with(e, data)
SentryProxy.capture(e, data)
end
it "passes messages to the capture_message raven method" do
e = "Some Message"
Raven.expects(:capture_message).with(e, data)
SentryProxy.capture(e, data)
end
it "changes symbols to strings because raven chokes otherwise" do
e = :some_exception_type
Raven.expects(:capture_message).with("some_exception_type", data)
SentryProxy.capture(e, data)
end
it "does not send the message if configured as ignorable" do
SentryProxy.register_ignorable_error(MyCustomError)
e = MyCustomError.new
Raven.expects(:capture_exception).times(0)
SentryProxy.capture(e, data)
end
end end
it "changes symbols to strings because raven chokes otherwise" do
e = :some_exception_type describe ".register_ignorable_error" do
Raven.expects(:capture_message).with("some_exception_type", data) it "keeps track of errors we don't care about reporting" do
SentryProxy.capture(e, data) SentryProxy.register_ignorable_error(MyCustomError)
expect(SentryProxy.ignorable_errors).to include(MyCustomError)
end
it "prevents the same error from being registered many times" do
start_count = SentryProxy.ignorable_errors.size
10.times { SentryProxy.register_ignorable_error(MyCustomError) }
expect(SentryProxy.ignorable_errors.size).to eq(start_count + 1)
end
end end
end end