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

Set consistent context in delayed_job integration #615

Merged
merged 3 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions features/delayed_job.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion features/fixtures/delayed_job/app/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -21,4 +25,4 @@ def run_delayed_job_test(command)
end
system("rails runner #{command}")
Process.wait
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TestReportContextJob < ApplicationJob
queue_as :default

def perform(*)
raise "oh dear"
end
end
1 change: 1 addition & 0 deletions lib/bugsnag/middleware/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down