From eb66244b7483bf54e985d6e96c32f94fa6056b8a Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 6 Nov 2024 13:58:34 +1100 Subject: [PATCH 1/2] Fix Bugsnag call to notify Make sure we add metadata as expected: https://docs.bugsnag.com/platforms/ruby/rails/reporting-handled-errors/#add_metadata --- app/controllers/concerns/order_completion.rb | 2 +- app/controllers/concerns/order_stock_check.rb | 2 +- app/controllers/errors_controller.rb | 2 +- app/controllers/spree/admin/products_controller.rb | 8 ++++---- app/jobs/backorder_job.rb | 2 +- app/jobs/stock_sync_job.rb | 4 ++-- app/jobs/subscription_confirm_job.rb | 5 ++--- app/services/place_proxy_order.rb | 5 ++--- app/services/sets/product_set.rb | 10 +++++----- 9 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/controllers/concerns/order_completion.rb b/app/controllers/concerns/order_completion.rb index 58bf7a03b92..d98faf149bb 100644 --- a/app/controllers/concerns/order_completion.rb +++ b/app/controllers/concerns/order_completion.rb @@ -51,7 +51,7 @@ def order_invalid_for_checkout? def order_invalid! Bugsnag.notify("Notice: invalid order loaded during checkout") do |payload| - payload.add_metadata :order, @order + payload.add_metadata :order, :order, @order end flash[:error] = t('checkout.order_not_loaded') diff --git a/app/controllers/concerns/order_stock_check.rb b/app/controllers/concerns/order_stock_check.rb index 13ff145ae89..7b948765337 100644 --- a/app/controllers/concerns/order_stock_check.rb +++ b/app/controllers/concerns/order_stock_check.rb @@ -21,7 +21,7 @@ def check_order_cycle_expiry return unless current_order_cycle&.closed? Bugsnag.notify("Notice: order cycle closed during checkout completion") do |payload| - payload.add_metadata :order, current_order + payload.add_metadata :order, :order, current_order end current_order.empty! current_order.set_order_cycle! nil diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index 17a0f08fa50..5e71f7c142a 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -7,7 +7,7 @@ def not_found Bugsnag.notify("404") do |event| event.severity = "info" - event.add_metadata(:request, request.env) + event.add_metadata(:request, :request, request.env) end render status: :not_found, formats: :html end diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index d383bee4e8e..788d019dce2 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -214,10 +214,10 @@ def set_stock_levels(product, on_hand, on_demand) def notify_bugsnag(error, product, variant) Bugsnag.notify(error) do |report| - report.add_metadata(:product, product.attributes) - report.add_metadata(:product_error, product.errors.first) unless product.valid? - report.add_metadata(:variant, variant.attributes) - report.add_metadata(:variant_error, variant.errors.first) unless variant.valid? + report.add_metadata(:product, + { product: product.attributes, variant: variant.attributes }) + report.add_metadata(:product, :product_error, product.errors.first) unless product.valid? + report.add_metadata(:product, :variant_error, variant.errors.first) unless variant.valid? end end diff --git a/app/jobs/backorder_job.rb b/app/jobs/backorder_job.rb index c8ce3f64a17..73e3f51eba3 100644 --- a/app/jobs/backorder_job.rb +++ b/app/jobs/backorder_job.rb @@ -20,7 +20,7 @@ def self.check_stock(order) # Errors here shouldn't affect the checkout. So let's report them # separately: Bugsnag.notify(e) do |payload| - payload.add_metadata(:order, order) + payload.add_metadata(:order, :order, order) end end diff --git a/app/jobs/stock_sync_job.rb b/app/jobs/stock_sync_job.rb index 14d27f54e3a..009bdb5b5e4 100644 --- a/app/jobs/stock_sync_job.rb +++ b/app/jobs/stock_sync_job.rb @@ -17,7 +17,7 @@ def self.sync_linked_catalogs(order) # Errors here shouldn't affect the shopping. So let's report them # separately: Bugsnag.notify(e) do |payload| - payload.add_metadata(:order, order) + payload.add_metadata(:order, :order, order) end end @@ -30,7 +30,7 @@ def self.sync_linked_catalogs_now(order) # Errors here shouldn't affect the shopping. So let's report them # separately: Bugsnag.notify(e) do |payload| - payload.add_metadata(:order, order) + payload.add_metadata(:order, :order, order) end end diff --git a/app/jobs/subscription_confirm_job.rb b/app/jobs/subscription_confirm_job.rb index 4a7e69a3842..2182671049e 100644 --- a/app/jobs/subscription_confirm_job.rb +++ b/app/jobs/subscription_confirm_job.rb @@ -56,7 +56,7 @@ def confirm_order!(order) send_failed_payment_email(order) else Bugsnag.notify(e) do |payload| - payload.add_metadata :order, order + payload.add_metadata :order, :order, order end send_failed_payment_email(order, e.message) end @@ -109,8 +109,7 @@ def send_failed_payment_email(order, error_message = nil) SubscriptionMailer.failed_payment_email(order).deliver_now rescue StandardError => e Bugsnag.notify(e) do |payload| - payload.add_metadata :order, order - payload.add_metadata :error_message, error_message + payload.add_metadata :subscription_data, { order:, error_message: } end end end diff --git a/app/services/place_proxy_order.rb b/app/services/place_proxy_order.rb index 03bd379d9d0..c6f942d3b02 100644 --- a/app/services/place_proxy_order.rb +++ b/app/services/place_proxy_order.rb @@ -25,7 +25,7 @@ def call rescue StandardError => e summarizer.record_and_log_error(:processing, order, e.message) Bugsnag.notify(e) do |payload| - payload.add_metadata :order, order + payload.add_metadata :order, :order, order end end @@ -57,8 +57,7 @@ def initialise_order true rescue StandardError => e Bugsnag.notify(e) do |payload| - payload.add_metadata :subscription, subscription - payload.add_metadata :proxy_order, proxy_order + payload.add_metadata(:proxy_order, { subscription:, proxy_order: }) end false end diff --git a/app/services/sets/product_set.rb b/app/services/sets/product_set.rb index 15ffe47e21c..c6a4521ab77 100644 --- a/app/services/sets/product_set.rb +++ b/app/services/sets/product_set.rb @@ -146,11 +146,11 @@ def count_result(saved) def notify_bugsnag(error, product, variant, variant_attributes) Bugsnag.notify(error) do |report| - report.add_metadata(:product, product.attributes) - report.add_metadata(:product_error, product.errors.first) unless product.valid? - report.add_metadata(:variant_attributes, variant_attributes) - report.add_metadata(:variant, variant.attributes) - report.add_metadata(:variant_error, variant.errors.first) unless variant.valid? + report.add_metadata( :product_set, + { product: product.attributes, variant_attributes:, + variant: variant.attributes } ) + report.add_metadata(:product_set, :product_error, product.errors.first) if !product.valid? + report.add_metadata(:product_set, :variant_error, variant.errors.first) if !variant.valid? end end end From 2f9200b68bc579911fba442a6c93c20287f15dda Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 11 Nov 2024 14:03:10 +1100 Subject: [PATCH 2/2] Per review, use a better name --- app/controllers/errors_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index 5e71f7c142a..262325f0292 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -7,7 +7,7 @@ def not_found Bugsnag.notify("404") do |event| event.severity = "info" - event.add_metadata(:request, :request, request.env) + event.add_metadata(:request, :env, request.env) end render status: :not_found, formats: :html end