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

Add simpler Alert.raise interface to notify Bugsnag #12992

Merged
merged 11 commits into from
Dec 3, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Nov 21, 2024

What? Why?

Bugsnag's API is great for general purpose but overly complex for our use. It also changes over time and we often make mistakes using it. So this class aims at:

  • Abstracting from Bugsnag, open for other services.
  • Simpler interface to reduce user error.
  • Central place to update Bugsnag API usage when it changes.

In a previous PR, we tried to fix the syntax like this:

-        payload.add_metadata :order, order
+        payload.add_metadata :order, :order, order

But that didn't work. I think that the order object was converted to a hash before but newer versions of Bugsnag have less magic. And passing the order as value doesn't work either, it just got filtered out when I tested. So this pull request adds some logic to convert an ActiveRecord object to proper Bugsnag metadata. We may want to expand the functionality in the future but I didn't want to spend too much time on this now.

Hopefully this PR is enough to propagate correct use from now on.

What should we test?

  • I'm not sure if we can test this properly.
  • We would need to know about an existing bug that triggers Bugsnag and try to do that again on staging.
  • Then you can compare the data there.
  • This code affects only code paths that are not expected to happen on a regular basis.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

This reverts commit 2eec3d6.

We started tracking 404 errors out of interest without an actual problem
to solve. Now we face rate-limiting in our Bugsnag account. And we
didn't use these 404 reports in the two years this code was active. We
don't even act on all 500 errors. So while our resources are so
constrained, let's keep our focus on the severe errors and user reports
and ignore the rest. 404 errors are mostly generated by vulnerability
scanners.
Needs human to review Bugsnag account.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Nov 21, 2024
@mkllnk mkllnk self-assigned this Nov 21, 2024
Bugsnag expects a string as value, not an ActiveRecord object. The
result was just "filtered" data, not showing any of the order's
attributes.

Since wanting to share the order data seems a common pattern, I added a
convenience method for it.
I still think that some of these objects won't be visible in Bugsnag but
I don't want to test any more on cases that were broken before and may
not be relevant now.
Somehow Bugsnag doesn't report in CI environment and I have no idea how
to circumvent that. And I don't want to spend more time on this.
@mkllnk mkllnk marked this pull request as ready for review November 21, 2024 05:52
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work, looks like it will ensure more consistent error reporting, and great cleanup along the way.

Comment on lines +27 to +29
# You need to have a valid Bugsnag API key to record this test.
# And after recording, you need to check the Bugsnag account for the right
# data.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding instructions!

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Thanks for that, that was overdue :)

I think you missed one of the call with an order object.

Comment on lines 58 to 60
Alert.raise(e) do |payload|
payload.add_metadata :order, :order, order
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be :

Suggested change
Alert.raise(e) do |payload|
payload.add_metadata :order, :order, order
end
Alert.raise_with_record(e, order)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. Applied.

@mkllnk mkllnk requested a review from rioug December 3, 2024 02:03
@mkllnk mkllnk merged commit 697f430 into openfoodfoundation:master Dec 3, 2024
51 checks passed
@mkllnk mkllnk deleted the errors branch December 3, 2024 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants