Skip to content
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

Merged
merged 17 commits into from
Oct 2, 2017

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Sep 13, 2017

  • Adds defaultSeverity, unhandled, and severityReasons payload properties to support upcoming handled/unhandled functionality
  • Created separate notifier functions, notify for handled notifications and auto_notify for automated/middleware notifications
  • Middleware set up with correct severity reasons
  • Discussion needed around language-level ruby error handling, and how to allow the user to this up without delving into severity reasons
    references PLAT_207

@Cawllec Cawllec added needs discussion Requires internal analysis/discussion and removed needs discussion Requires internal analysis/discussion labels Sep 13, 2017
Copy link
Contributor

@snmaynard snmaynard left a 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.

Bugsnag.auto_notify(exception, {
:type => "middleware",
:attributes => {
:name => "mailman"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resque

@@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

middleware_handler

@@ -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",
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

middleware_handler

@@ -17,7 +17,12 @@ class Railtie < Rails::Railtie
runner do
at_exit do
if $!
Bugsnag.notify($!, true) do |report|
Bugsnag.auto_notify($!, {
:type => "middleware",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

middleware_handler

@@ -26,7 +26,12 @@ def self.add_failure_backend
end

def save
Bugsnag.notify(exception, true) do |report|
Bugsnag.auto_notify(exception, {
:type => "middleware",
Copy link
Contributor

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)
Copy link
Contributor

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?

@@ -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, {
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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

@Cawllec
Copy link
Contributor Author

Cawllec commented Sep 15, 2017

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.

Copy link
Contributor

@kattrali kattrali left a 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({
Copy link
Contributor

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.

@@ -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({
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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"
Copy link
Contributor

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.

@@ -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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"attirbutes"

report.set_handled_state({
:type => "middleware_handler",
:attributes => {
:name => "rack"
Copy link
Contributor

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 }
Copy link
Contributor

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.

@kattrali kattrali merged commit 643ae3a into v5 Oct 2, 2017
@kattrali kattrali deleted the v5-unhandled branch October 2, 2017 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants