-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added unhandled functionality, updated tests and integrations #368
Changes from 12 commits
7e399e3
4e40c4b
5d0411e
880affa
cdb80c4
2aa48ca
4d1770d
a7799ee
725f7f1
7023dab
8cba071
f7db8af
9d4f95e
391a755
464ac7f
82519e3
085108c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ def configure | |
|
||
# Explicitly notify of an exception | ||
def notify(exception, auto_notify=false, &block) | ||
if auto_notify && !configuration.auto_notify | ||
report = Report.new(exception, configuration, auto_notify) | ||
|
||
if !configuration.auto_notify && auto_notify | ||
configuration.debug("Not notifying because auto_notify is disabled") | ||
return | ||
end | ||
|
@@ -49,8 +51,6 @@ def notify(exception, auto_notify=false, &block) | |
return | ||
end | ||
|
||
report = Report.new(exception, configuration) | ||
|
||
# If this is an auto_notify we yield the block before the any middleware is run | ||
yield(report) if block_given? && auto_notify | ||
if report.ignore? | ||
|
@@ -65,13 +65,27 @@ def notify(exception, auto_notify=false, &block) | |
return | ||
end | ||
|
||
# Store before_middleware severity reason for future reference | ||
before_middleware_severity = report.severity | ||
before_middleware_reason = report.severity_reason | ||
|
||
# Run users middleware | ||
configuration.middleware.run(report) do | ||
if report.ignore? | ||
configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in user provided middleware") | ||
return | ||
end | ||
|
||
# Update severity reason if necessary | ||
if report.severity != before_middleware_severity | ||
report.severity_reason = { | ||
:type => "userSpecifiedSeverity" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values for severity_reason should be defined as constants to avoid typos and to aggregate all possible values. Currently these values are scattered between different files. |
||
} | ||
end | ||
|
||
# Store severity before user callbacks | ||
before_callback_severity = report.severity | ||
|
||
# If this is not an auto_notify then the block was provided by the user. This should be the last | ||
# block that is run as it is the users "most specific" block. | ||
yield(report) if block_given? && !auto_notify | ||
|
@@ -80,6 +94,16 @@ def notify(exception, auto_notify=false, &block) | |
return | ||
end | ||
|
||
# Test whether severity has been changed and ensure severity_reason is consistant in auto_notify case | ||
if auto_notify | ||
report.severity = before_middleware_severity | ||
report.severity_reason = before_middleware_reason | ||
elsif report.severity != before_callback_severity | ||
report.severity_reason = { | ||
:type => "userCallbackSeverity" | ||
} | ||
end | ||
|
||
# Deliver | ||
configuration.info("Notifying #{configuration.endpoint} of #{report.exceptions.last[:errorClass]}") | ||
payload_string = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(report.as_json)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,12 @@ def error(job, error) | |
|
||
::Bugsnag.notify(error, true) do |report| | ||
report.severity = "error" | ||
report.set_handled_state({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
:type => "unhandledExceptionMiddleware", | ||
:attributes => { | ||
:framework => "DelayedJob" | ||
} | ||
}) | ||
report.meta_data.merge! overrides | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ def call(env) | |
# Notify bugsnag of rack exceptions | ||
Bugsnag.notify(raised, true) do |report| | ||
report.severity = "error" | ||
report.set_handled_state({ | ||
:type => "unhandledExceptionMiddleware", | ||
:attirbutes => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "attirbutes" |
||
:framework => "Rack" | ||
} | ||
}) | ||
end | ||
|
||
# Re-raise the exception | ||
|
@@ -45,6 +51,12 @@ def call(env) | |
if env["rack.exception"] | ||
Bugsnag.notify(env["rack.exception"], true) do |report| | ||
report.severity = "error" | ||
report.set_handled_state({ | ||
:type => "middleware_handler", | ||
:attributes => { | ||
:name => "rack" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}) | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,12 @@ def call(worker, msg, queue) | |
raise ex if [Interrupt, SystemExit, SignalException].include? ex.class | ||
Bugsnag.notify(ex, true) do |report| | ||
report.severity = "error" | ||
report.set_handled_states({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, |
||
:type => 'unhandledExceptionMiddleware', | ||
:attributes => { | ||
:framework => "Sidekiq" | ||
} | ||
}) | ||
end | ||
raise | ||
ensure | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Bugsnag::Middleware | ||
class ClassifyError | ||
INFO_CLASSES = [ | ||
"AbstractController::ActionNotFound", | ||
"ActionController::InvalidAuthenticityToken", | ||
"ActionController::ParameterMissing", | ||
"ActionController::UnknownAction", | ||
"ActionController::UnknownFormat", | ||
"ActionController::UnknownHttpMethod", | ||
"ActiveRecord::RecordNotFound", | ||
"CGI::Session::CookieStore::TamperedWithCookie", | ||
"Mongoid::Errors::DocumentNotFound", | ||
"SignalException", | ||
"SystemExit" | ||
] | ||
|
||
def initialize(bugsnag) | ||
@bugsnag = bugsnag | ||
end | ||
|
||
def call(report) | ||
report.raw_exceptions.each do |ex| | ||
ancestor_chain = ex.class.ancestors.select { |ancestor| ancestor.is_a?(Class) }.map { |ancestor| ancestor.to_s } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Breaking the blocks onto separate lines would make this expression more readable. |
||
|
||
INFO_CLASSES.each do |info_class| | ||
if ancestor_chain.include?(info_class) | ||
report.set_handled_state( | ||
{ | ||
:type => "error_class", | ||
:attributes => { | ||
:errorClass => info_class | ||
} | ||
} | ||
) | ||
report.severity = 'info' | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unneeded semicolon |
||
end | ||
end | ||
end | ||
|
||
@bugsnag.call(report) | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,12 @@ class Report | |
attr_accessor :raw_exceptions | ||
attr_accessor :release_stage | ||
attr_accessor :severity | ||
attr_accessor :severity_reason | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be declared as |
||
attr_accessor :user | ||
|
||
def initialize(exception, passed_configuration) | ||
def initialize(exception, passed_configuration, auto_notify=false) | ||
@should_ignore = false | ||
@unhandled = auto_notify | ||
|
||
self.configuration = passed_configuration | ||
|
||
|
@@ -43,6 +45,9 @@ def initialize(exception, passed_configuration) | |
self.meta_data = {} | ||
self.release_stage = configuration.release_stage | ||
self.severity = "warning" | ||
self.severity_reason = { | ||
:type => "handledException" | ||
} | ||
self.user = {} | ||
end | ||
|
||
|
@@ -84,6 +89,8 @@ def as_json | |
groupingHash: grouping_hash, | ||
payloadVersion: CURRENT_PAYLOAD_VERSION, | ||
severity: severity, | ||
severityReason: severity_reason, | ||
unhandled: @unhandled, | ||
user: user | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create the report before the validation blocks? This is extra processing when a user is running in a testing/debug mode.