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

Release v6.24.1 #712

Merged
merged 15 commits into from
Nov 30, 2021
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
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Metrics/ClassLength:
Exclude:
- 'lib/bugsnag/configuration.rb'

Style/RescueModifier:
Enabled: false

# We can't use ".freeze" on our constants in case users are monkey patching
# them — this would be a BC break
Style/MutableConstant:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## v6.24.1 (30 November 2021)

### Fixes

* Fix metadata not being recorded when using Resque outside of Active Job
| [#710](https://github.com/bugsnag/bugsnag-ruby/pull/710)
| [isnotajoke](https://github.com/isnotajoke)

## v6.24.0 (6 October 2021)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group :test, optional: true do
gem 'rake', ruby_version <= Gem::Version.new('1.9.3') ? '~> 11.3.0' : '~> 12.3.0'
gem 'rspec'
gem 'rspec-mocks'
gem 'yard', '~> 0.9.25'
gem 'yard', ruby_version < Gem::Version.new('2.3.0') ? '< 0.9.27' : '~> 0.9.25'
gem 'pry'
gem 'addressable', '~> 2.3.8'

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.24.0
6.24.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ResqueWorker
@queue = :crash

def self.perform
def self.perform(*arguments, **named_arguments)
raise 'broken'
end
end
18 changes: 14 additions & 4 deletions features/rails_features/integrations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Scenario: Rake
@rails_integrations
Scenario: Resque (no on_exit hooks)
When I run "bundle exec rake resque:work" in the rails app
And I run "Resque.enqueue(ResqueWorker)" with the rails runner
And I run "Resque.enqueue(ResqueWorker, 123, %(abc), x: true, y: false)" with the rails runner
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
Expand All @@ -85,6 +85,10 @@ Scenario: Resque (no on_exit hooks)
And the event "metaData.config.delivery_method" equals "synchronous"
And the event "metaData.context" equals "ResqueWorker@crash"
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.payload.args.0" equals 123
And the event "metaData.payload.args.1" equals "abc"
And the event "metaData.payload.args.2.x" is true
And the event "metaData.payload.args.2.y" is false
And the event "metaData.rake_task.name" equals "resque:work"
And the event "metaData.rake_task.description" equals "Start a Resque worker"
And the event "metaData.rake_task.arguments" is null
Expand All @@ -93,7 +97,7 @@ Scenario: Resque (no on_exit hooks)
Scenario: Resque (with on_exit hooks)
Given I set environment variable "RUN_AT_EXIT_HOOKS" to "1"
When I run "bundle exec rake resque:work" in the rails app
And I run "Resque.enqueue(ResqueWorker)" with the rails runner
And I run "Resque.enqueue(ResqueWorker, %(xyz), [7, 8, 9], a: 4, b: 5)" with the rails runner
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
Expand All @@ -106,6 +110,12 @@ Scenario: Resque (with on_exit hooks)
And the event "metaData.config.delivery_method" equals "thread_queue"
And the event "metaData.context" equals "ResqueWorker@crash"
And the event "metaData.payload.class" equals "ResqueWorker"
And the event "metaData.payload.args.0" equals "xyz"
And the event "metaData.payload.args.1.0" equals 7
And the event "metaData.payload.args.1.1" equals 8
And the event "metaData.payload.args.1.2" equals 9
And the event "metaData.payload.args.2.a" equals 4
And the event "metaData.payload.args.2.b" equals 5
And the event "metaData.rake_task.name" equals "resque:work"
And the event "metaData.rake_task.description" equals "Start a Resque worker"
And the event "metaData.rake_task.arguments" is null
Expand Down Expand Up @@ -150,7 +160,7 @@ Scenario: Using Sidekiq as the Active Job queue adapter for a job that raises
And the event "metaData.sidekiq.queue" equals "default"

@rails_integrations
Scenario: Using Rescue as the Active Job queue adapter for a job that raises
Scenario: Using Resque as the Active Job queue adapter for a job that raises
When I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque"
And I run "bundle exec rake resque:work" in the rails app
And I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner
Expand Down Expand Up @@ -221,7 +231,7 @@ Scenario: Using Sidekiq as the Active Job queue adapter for a job that works
Then I should receive no requests

@rails_integrations
Scenario: Using Rescue as the Active Job queue adapter for a job that works
Scenario: Using Resque as the Active Job queue adapter for a job that works
When I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque"
And I run "bundle exec rake resque:work" in the rails app
And I run "WorkingJob.perform_later" with the rails runner
Expand Down
14 changes: 9 additions & 5 deletions lib/bugsnag/integrations/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ def save
}

metadata = payload
class_name = payload['class']
class_name = metadata['class']

# when using Active Job the payload "class" will always be the Resque
# "JobWrapper", not the actual job class so we need to fix this here
if metadata['args'] && metadata['args'][0] && metadata['args'][0]['job_class']
class_name = metadata['args'][0]['job_class']
metadata['wrapped'] ||= class_name
# "JobWrapper", so we need to unwrap the actual class name
if class_name == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
unwrapped_class_name = metadata['args'][0]['job_class'] rescue nil

if unwrapped_class_name
class_name = unwrapped_class_name
metadata['wrapped'] ||= unwrapped_class_name
end
end

context = "#{class_name}@#{queue}"
Expand Down
2 changes: 1 addition & 1 deletion spec/breadcrumbs/breadcrumb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
describe "#to_h" do
it "outputs as a hash" do
fake_now = Time.gm(2020, 1, 2, 3, 4, 5, 123456)
expect(Time).to receive(:now).and_return(fake_now)
expect(Time).to receive(:now).at_least(:once).and_return(fake_now)

breadcrumb = Bugsnag::Breadcrumbs::Breadcrumb.new(
"my message",
Expand Down
2 changes: 1 addition & 1 deletion spec/bugsnag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ module Kernel
describe "request headers" do
it "Bugsnag-Sent-At should use the current time" do
fake_now = Time.gm(2020, 1, 2, 3, 4, 5, 123456)
expect(Time).to receive(:now).at_most(6).times.and_return(fake_now)
expect(Time).to receive(:now).at_least(6).times.and_return(fake_now)

Bugsnag.notify(BugsnagTestException.new("It crashed"))

Expand Down
27 changes: 27 additions & 0 deletions spec/integrations/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ def require(path)
}
end

it "handles when args[0] does not respond to '[]'" do
resque = Bugsnag::Resque.new
exception = RuntimeError.new("hello")

allow(resque).to receive(:exception).and_return(exception)
allow(resque).to receive(:queue).and_return("queue")
allow(resque).to receive(:payload).and_return({
"class" => "ResqueJob",
"args" => [1234]
})

report = Bugsnag::Report.new(exception, Bugsnag.configuration)

resque.save

expect(Bugsnag).to have_sent_notification { |payload, headers|
event = get_event_from_payload(payload)

expect(event["context"]).to eq("ResqueJob@queue")
expect(event["metaData"]["context"]).to eq("ResqueJob@queue")
expect(event["metaData"]["payload"]).to eq({
"args" => [1234],
"class" => "ResqueJob",
})
}
end

after do
Object.send(:remove_const, :Resque) if @mocked_resque
module Kernel
Expand Down
2 changes: 1 addition & 1 deletion spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def gloops

it "#headers should return the correct request headers" do
fake_now = Time.gm(2020, 1, 2, 3, 4, 5, 123456)
expect(Time).to receive(:now).twice.and_return(fake_now)
expect(Time).to receive(:now).at_least(:twice).and_return(fake_now)

report_or_event = class_to_test.new(
BugsnagTestException.new("It crashed"),
Expand Down