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

Allow overriding an event's unhandled flag #698

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Enhancements

* Allow overriding an event's unhandled flag
| [#698](https://github.com/bugsnag/bugsnag-ruby/pull/698)

## v6.23.0 (21 September 2021)

### Enhancements
Expand Down
5 changes: 5 additions & 0 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def notify(exception, auto_notify=false, &block)
report.severity_reason = initial_reason
end

if report.unhandled_overridden?
# let the dashboard know that the unhandled flag was overridden
report.severity_reason[:unhandledOverridden] = true
end

deliver_notification(report)
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/bugsnag/middleware/session_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def initialize(bugsnag)

def call(report)
session = Bugsnag::SessionTracker.get_current_session
unless session.nil?

if session
if report.unhandled
session[:events][:unhandled] += 1
else
session[:events][:handled] += 1
end

report.session = session
end

Expand Down
36 changes: 36 additions & 0 deletions lib/bugsnag/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def initialize(exception, passed_configuration, auto_notify=false)

@should_ignore = false
@unhandled = auto_notify
@initial_unhandled = @unhandled

self.configuration = passed_configuration

Expand Down Expand Up @@ -374,8 +375,43 @@ def set_user(id = nil, email = nil, name = nil)
@user = new_user
end

def unhandled=(new_unhandled)
# fix the handled/unhandled counts in the current session
update_handled_counts(new_unhandled, @unhandled)

@unhandled = new_unhandled
end

##
# Returns true if the unhandled flag has been changed from its initial value
#
# @api private
# @return [Boolean]
def unhandled_overridden?
@unhandled != @initial_unhandled
end

private

def update_handled_counts(is_unhandled, was_unhandled)
# do nothing if there is no session to update
return if @session.nil?

# increment the counts for the current unhandled value
if is_unhandled
@session[:events][:unhandled] += 1
else
@session[:events][:handled] += 1
end

# decrement the counts for the previous unhandled value
if was_unhandled
@session[:events][:unhandled] -= 1
else
@session[:events][:handled] -= 1
end
end

def generate_exception_list
raw_exceptions.map do |exception|
{
Expand Down
Loading