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

Breadcrumbs: Update reports class, add Breadcrumbs middleware #512

Merged
merged 20 commits into from
Dec 17, 2018

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Dec 11, 2018

Goal

Adds breadcrumbs middleware and enables the report to receive them.

@Cawllec Cawllec requested review from tobyhs, kellymason and a team December 11, 2018 14:18
filter_cleaner = Bugsnag::Cleaner.new(configuration.meta_data_filters)
payload_event[:metaData] = filter_cleaner.clean_object(meta_data)
payload_event[:breadcrumbs] = breadcrumbs.map do |raw_crumb|
breadcrumb = raw_crumb.to_h
Copy link
Contributor

Choose a reason for hiding this comment

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

if breadcrumbs is an Array of Breadcrumb objects, should one of these be breadcrumb (instead of raw_crumb)? It seems like the variable names should be reversed, as raw implies something more primitive.

Alternatively, the block variable can be breadcrumb but the converted one can be named something like breadcrumb_hash.

lib/bugsnag/report.rb Show resolved Hide resolved
it "includes left breadcrumbs" do
Bugsnag.leave_breadcrumb("Test breadcrumb")
notify_test_exception
expect(Bugsnag).to have_sent_notification{ |payload, headers|
Copy link
Contributor

Choose a reason for hiding this comment

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

Use do + end, although I suspect there could be some Ruby precedence issue that prevents this from working; if that's the case, add a space before the { (same comment applies to a few other lines below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the have_sent_notification method doesn't handled do end blocks, only {} blocks. This may be something to look at in a longer term ticket.

expect(report.name).to eq("ZeroDivisionError")
expect(report.message).to eq("divided by 0")

expect(report.summary).to match({
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably use eq instead of match (same with line 1185)

self.meta_data = {}
self.name = exception.class.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.

If exception is a string (which is likely true if exception doesn't respond to message) instead of an exception, would it make more sense to default to RuntimeError instead (because code later on will convert it to that)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the breadcrumb name should reflect what was notified explicitly. In this case the result would be String which on a breadcrumb with limited information I think is more telling than RuntimeError would be.

Copy link
Contributor

Choose a reason for hiding this comment

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

Users will use this information to try and find the error in the UI so switching between class and message will be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fair, I hadn't considered it in that context.

self.meta_data = {}

# Notified strings display as RuntimeErrors in the dashboard
self.name = exception.is_a?(Exception) ? exception.class.to_s : RuntimeError.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.

Should this check match the check in #generate_raw_exceptions? (so that it calls #to_exception or #exception if applicable, and also check that it isn't a Java::JavaLang::Throwable for jruby; this might require a little refactoring)

# @return [Hash] a Hash containing the report's name, message, and severity
def summary
{
:name => name,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the key name here should be class or error_class instead to align with the Data Access API filters and field names (slightly leaning towards error_class).

attr_accessor :meta_data
attr_accessor :name
Copy link
Contributor

Choose a reason for hiding this comment

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

After digging through the existing code some more, it looks like it would be easier to define a plain name method (instead of attr_accessor :name) that returns exceptions[0][:errorClass] as that would be consistent (because the exceptions attribute also makes the exception go through the #error_class method to find its error class or "name", which your code further below doesn't do now).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeping the message and name as it is now allows the user to override how the follow-up breadcrumb will be displayed. If they want to assign a custom name/message that will allow them to navigate breadcrumbs more easily they should be able to.

attr_accessor :configuration
attr_accessor :context
attr_accessor :delivery_method
attr_accessor :exceptions
attr_accessor :hostname
attr_accessor :grouping_hash
attr_accessor :message
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 the comment a few lines after this, I think you can remove this and change your #summary method to use exceptions[0][:message]

Copy link
Contributor

@tobyhs tobyhs left a comment

Choose a reason for hiding this comment

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

possible use of De Morgan's Law to make something a little bit easier to read, otherwise lgtm

# @return [Hash] a Hash containing the report's error class, error message, and severity
def summary
# Guard against the exceptions array being removed/changed or emptied here
if !exceptions.is_a?(Array) || exceptions.first.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be easier to read if you changed the condition to exceptions.respond_to?(:first) && exceptions.first and put the known error class case first.

@Cawllec Cawllec merged commit 7cea4a7 into breadcrumbs/base Dec 17, 2018
@imjoehaines imjoehaines deleted the breadcrumbs/update-reports-class branch June 16, 2021 08:50
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.

None yet

3 participants