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

Fix Bugsnag call to notify #12967

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Nov 6, 2024

What? Why?

Looking at some Bugsnag report, I noticed the metadata wasn't showing up. It turned out we are using add_metadata as expected. Doc: https://docs.bugsnag.com/platforms/ruby/rails/reporting-handled-errors/#add_metadata

What should we test?

Green specs 🟢

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.

@rioug rioug added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Nov 6, 2024
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.

Good one!
A couple of thoughts, but not worth changing.

app/controllers/errors_controller.rb Outdated Show resolved Hide resolved
app/services/sets/product_set.rb Show resolved Hide resolved
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Interesting, I would have thought that this worked before. Maybe Bugsnag used to convert objects into hashes automatically before? Maybe it broke in an upgrade?

I'm wondering if we should have our own service object to call Bugsnag. I was against it in the past because I don't want to invest work into replicating something that's already there but interfaces change. And maybe our use case is slightly different. I could imagine a DSL like this:

Alert.raise("This shouldn't happen").add_record(current_order)
def add_record(record)
  payload.add_metadata(record.class.name, record.attributes)
  self
end

Then we can chain method calls to add more data as needed. But mostly it's very simple.

Bugsnag uses a lambda for lazy evaluation but we mostly don't compute anything and have the object on hand. We can wrap that in our service object for an easier API that fits most of our use cases.

Hm, is there a gem for that?

app/controllers/errors_controller.rb Outdated Show resolved Hide resolved
@mkllnk mkllnk merged commit 8c6c1e2 into openfoodfoundation:master Nov 14, 2024
51 checks passed
@rioug
Copy link
Collaborator Author

rioug commented Nov 17, 2024

I'm wondering if we should have our own service object to call Bugsnag.

Looks like there was some similar thinking at some point : https://github.com/openfoodfoundation/openfoodnetwork/blob/master/lib/open_food_network/error_logger.rb
It's only used here

OpenFoodNetwork::ErrorLogger.notify(e)

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