-
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
Conversation
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.
I'll take a look at the non v5 one in a sec. Looks good, I think the main point of discussion is the auto_notify method. LMK your thoughts.
lib/bugsnag/integrations/resque.rb
Outdated
Bugsnag.auto_notify(exception, { | ||
:type => "middleware", | ||
:attributes => { | ||
:name => "mailman" |
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.
resque
lib/bugsnag/integrations/mailman.rb
Outdated
@@ -13,7 +13,12 @@ def call(mail) | |||
yield | |||
rescue Exception => ex | |||
raise ex if [Interrupt, SystemExit, SignalException].include? ex.class | |||
Bugsnag.notify(ex, true) do |report| | |||
Bugsnag.auto_notify(ex, { | |||
:type => "middleware", |
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.
middleware_handler
lib/bugsnag/integrations/rack.rb
Outdated
@@ -43,7 +48,12 @@ def call(env) | |||
|
|||
# Notify bugsnag of rack exceptions | |||
if env["rack.exception"] | |||
Bugsnag.notify(env["rack.exception"], true) do |report| | |||
Bugsnag.auto_notify(env["rack.exception"], { | |||
:type => "middleware", |
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.
middleware_handler
@@ -8,7 +8,12 @@ def run_callbacks(kind, *args, &block) | |||
super | |||
rescue StandardError => exception | |||
# This exception will NOT be escalated, so notify it here. | |||
Bugsnag.notify(exception, true) do |report| | |||
Bugsnag.auto_notify(exception, { | |||
:type => "middleware", |
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.
middleware_handler
lib/bugsnag/integrations/railtie.rb
Outdated
@@ -17,7 +17,12 @@ class Railtie < Rails::Railtie | |||
runner do | |||
at_exit do | |||
if $! | |||
Bugsnag.notify($!, true) do |report| | |||
Bugsnag.auto_notify($!, { | |||
:type => "middleware", |
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.
middleware_handler
lib/bugsnag/integrations/resque.rb
Outdated
@@ -26,7 +26,12 @@ def self.add_failure_backend | |||
end | |||
|
|||
def save | |||
Bugsnag.notify(exception, true) do |report| | |||
Bugsnag.auto_notify(exception, { | |||
:type => "middleware", |
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.
middleware_handler
lib/bugsnag.rb
Outdated
configuration.debug("Not notifying because auto_notify is disabled") | ||
return | ||
end | ||
|
||
report = Report.new(exception, configuration, true, severity_reason) |
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.
You could set the severity reason in here to be error?
lib/bugsnag/tasks/bugsnag.rake
Outdated
@@ -6,7 +6,14 @@ namespace :bugsnag do | |||
begin | |||
raise RuntimeError.new("Bugsnag test exception") | |||
rescue => e | |||
Bugsnag.notify(e, {:context => "rake#test_exception"}) | |||
Bugsnag.auto_notify(e, { |
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.
This is fine to just be a normal notify, doesnt need to be an auto_notify. Its just a way of people testing their bugsnag installations
lib/bugsnag.rb
Outdated
end | ||
|
||
# For automatic notification of exceptions | ||
def auto_notify(exception, severity_reason, &block) |
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.
I dont think we need the auto_notify method. If you look where we build and send the report blocks when auto_notify is set to true are run first so we can change the reports in the block for auto notifications.
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.
So I would just call notify like we did before, just telling notify that this is an auto_notify. Then in the block you can set the severity reason and the severity. Its weird that severity is set in the block, and severity reason outside it right now.
lib/bugsnag.rb
Outdated
@@ -80,24 +106,18 @@ def notify(exception, auto_notify=false, &block) | |||
return | |||
end | |||
|
|||
# Test whether severity has been changed | |||
if report.severity != initial_severity | |||
report.default_severity = false |
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.
You could make this a little clearer imo with report.default_severity = report.severity == initial_severity
I agree with re-merging the auto-notify functions, and with passing the severity_reason through a block, as passing it along with the severity makes the most sense. |
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.
Left some inline comments, I think the set_handled_state
method got removed somewhere.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
set_handled_state
doesn't seem to be defined anywhere.
lib/bugsnag/integrations/sidekiq.rb
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, set_handled_states
(trailing 's') doesn't seem to be defined anywhere.
} | ||
) | ||
report.severity = 'info' | ||
break; |
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.
Unneeded semicolon
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This can be declared as attr_reader
, since its only being set internally by a method (I think that was the intent of set_handled_states
). It would prevent accidental overrides by other code/callback writers.
lib/bugsnag.rb
Outdated
@@ -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) |
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.
lib/bugsnag.rb
Outdated
# 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 comment
The 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.
lib/bugsnag/integrations/rack.rb
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
"attirbutes"
lib/bugsnag/integrations/rack.rb
Outdated
report.set_handled_state({ | ||
:type => "middleware_handler", | ||
:attributes => { | ||
:name => "rack" |
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.
Rack
above is capitalized, while this is not. Integration names are another candidate for a constant enumeration.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking the blocks onto separate lines would make this expression more readable.
defaultSeverity
,unhandled
, andseverityReasons
payload properties to support upcoming handled/unhandled functionalitynotify
for handled notifications andauto_notify
for automated/middleware notificationsreferences PLAT_207