From a91776e9bb655b1938cca341ce883521d7a8666d Mon Sep 17 00:00:00 2001 From: Mike Stewart Date: Mon, 26 Nov 2018 19:52:07 -0400 Subject: [PATCH 1/3] Set consistent context in delayed_job integration --- lib/bugsnag/middleware/delayed_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bugsnag/middleware/delayed_job.rb b/lib/bugsnag/middleware/delayed_job.rb index 0476e1ef9..5539d6960 100644 --- a/lib/bugsnag/middleware/delayed_job.rb +++ b/lib/bugsnag/middleware/delayed_job.rb @@ -24,6 +24,7 @@ def call(report) job_data[:active_job] = job.payload_object.job_data if job.payload_object.respond_to?(:job_data) payload_data = construct_job_payload(job.payload_object) report.context = payload_data[:display_name] if payload_data.include?(:display_name) + report.context ||= payload_data[:class] if payload_data.include?(:class) job_data[:payload] = payload_data end From a798bed7807f5ab4f08922e8ee16d4b3c8053c15 Mon Sep 17 00:00:00 2001 From: Mike Stewart Date: Tue, 27 Nov 2018 13:38:01 -0400 Subject: [PATCH 2/3] Changelog entry for bugsnag/bugsnag-ruby#499 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c416d366..875a17c86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +## TBD + +### Enhancements + +* Set default Delayed Job error context to job class + | [#499](https://github.com/bugsnag/bugsnag-ruby/pull/499) + | [Mike Stewart](https://github.com/mike-stewart) + ## 6.15.0 (27 July 2020) ### Enhancements From 80e0c800992ea37b2398437a42ca0b29047d4112 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 27 Jul 2020 12:29:35 +0100 Subject: [PATCH 3/3] Add maze runner test for report context class name --- features/delayed_job.feature | 17 +++++++++++++++++ features/fixtures/delayed_job/app/Rakefile | 6 +++++- .../app/app/jobs/test_report_context_job.rb | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 features/fixtures/delayed_job/app/app/jobs/test_report_context_job.rb diff --git a/features/delayed_job.feature b/features/delayed_job.feature index a6a004ebe..e9b062550 100644 --- a/features/delayed_job.feature +++ b/features/delayed_job.feature @@ -34,3 +34,20 @@ Scenario: A handled exception sends a report And the event "metaData.job.payload.display_name" equals "TestModel.notify_with_args" And the event "metaData.job.payload.method_name" equals "notify_with_args" And the payload field "events.0.metaData.job.payload.args.0" equals "Test" + +Scenario: The report context uses the class name if no display name is available + Given I run the service "delayed_job" with the command "bundle exec rake delayed_job_tests:report_context" + And I wait to receive a request + Then the request is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" + And the event "unhandled" is true + And the event "severity" equals "error" + And the event "context" equals "TestReportContextJob" + And the event "severityReason.type" equals "unhandledExceptionMiddleware" + And the event "severityReason.attributes.framework" equals "DelayedJob" + And the exception "errorClass" equals "RuntimeError" + And the event "metaData.job.class" equals "Delayed::Backend::ActiveRecord::Job" + And the event "metaData.job.id" is not null + And the event "metaData.job.attempt" equals 1 + And the event "metaData.job.max_attempts" equals 1 + And the event "metaData.job.payload.display_name" is null + And the event "metaData.job.payload.method_name" is null diff --git a/features/fixtures/delayed_job/app/Rakefile b/features/fixtures/delayed_job/app/Rakefile index 719fc8574..efcae1adb 100644 --- a/features/fixtures/delayed_job/app/Rakefile +++ b/features/fixtures/delayed_job/app/Rakefile @@ -13,6 +13,10 @@ namespace :delayed_job_tests do task :notify_with_args do run_delayed_job_test('"TestModel.delay.notify_with_args(\"Test\")"') end + + task :report_context do + run_delayed_job_test('"Delayed::Job.enqueue TestReportContextJob.new"') + end end def run_delayed_job_test(command) @@ -21,4 +25,4 @@ def run_delayed_job_test(command) end system("rails runner #{command}") Process.wait -end \ No newline at end of file +end diff --git a/features/fixtures/delayed_job/app/app/jobs/test_report_context_job.rb b/features/fixtures/delayed_job/app/app/jobs/test_report_context_job.rb new file mode 100644 index 000000000..4efeecb3d --- /dev/null +++ b/features/fixtures/delayed_job/app/app/jobs/test_report_context_job.rb @@ -0,0 +1,7 @@ +class TestReportContextJob < ApplicationJob + queue_as :default + + def perform(*) + raise "oh dear" + end +end