diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fe0fdfe..73bf3e488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +## v6.25.2 (7 February 2023) + +### Enhancements + +* Improve performance of `Bugsnag.notify` + | [#774](https://github.com/bugsnag/bugsnag-ruby/pull/774) + | [sambostock](https://github.com/sambostock) + ## v6.25.1 (5 January 2023) ### Fixes diff --git a/Gemfile-maze-runner b/Gemfile-maze-runner index 05bb7a68b..8dddc7ee1 100644 --- a/Gemfile-maze-runner +++ b/Gemfile-maze-runner @@ -1,3 +1,3 @@ source "https://rubygems.org" -gem 'bugsnag-maze-runner', git: 'https://github.com/bugsnag/maze-runner', tag: 'v7.6.0' +gem 'bugsnag-maze-runner', git: 'https://github.com/bugsnag/maze-runner', tag: 'v7.10.1' diff --git a/VERSION b/VERSION index 41ce415f3..aec9b1056 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.25.1 +6.25.2 diff --git a/features/fixtures/que/Dockerfile b/features/fixtures/que/Dockerfile index a7244b028..cabf13b71 100644 --- a/features/fixtures/que/Dockerfile +++ b/features/fixtures/que/Dockerfile @@ -13,3 +13,5 @@ ENV QUE_VERSION $QUE_VERSION RUN bundle install COPY app/ /usr/src/app + +CMD bundle exec que ./app.rb diff --git a/features/fixtures/rails_integrations/app/lib/tasks/fixture.rake b/features/fixtures/rails_integrations/app/lib/tasks/fixture.rake new file mode 100644 index 000000000..620e946cc --- /dev/null +++ b/features/fixtures/rails_integrations/app/lib/tasks/fixture.rake @@ -0,0 +1,13 @@ +namespace :fixture do + task queue_unhandled_job: [:environment] do + UnhandledJob.perform_later(1, yes: true) + end + + task queue_working_job: [:environment] do + WorkingJob.perform_later + end + + task queue_resque_job: [:environment] do + Resque.enqueue(ResqueWorker, 123, "abc", [7, 8, 9], x: true, y: false) + end +end diff --git a/features/fixtures/sidekiq/Dockerfile b/features/fixtures/sidekiq/Dockerfile index 84c878528..8fb1ce2a5 100644 --- a/features/fixtures/sidekiq/Dockerfile +++ b/features/fixtures/sidekiq/Dockerfile @@ -14,4 +14,6 @@ ENV SIDEKIQ_VERSION $SIDEKIQ_VERSION RUN bundle install -COPY app/ /app/ \ No newline at end of file +COPY app/ /app/ + +CMD bundle exec sidekiq -r ./app.rb diff --git a/features/que.feature b/features/que.feature index 9e872f7d5..c143b8c60 100644 --- a/features/que.feature +++ b/features/que.feature @@ -1,8 +1,8 @@ Feature: Errors are delivered to Bugsnag from Que Scenario: Que will deliver unhandled errors - Given I run the service "que" with the command "bundle exec ruby app.rb unhandled" - And I run the service "que" with the command "timeout 5 bundle exec que ./app.rb" + Given I start the service "que" + When I execute the command "bundle exec ruby app.rb unhandled" in the service "que" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -14,8 +14,8 @@ Scenario: Que will deliver unhandled errors And the exception "errorClass" equals "RuntimeError" Scenario: Que will deliver handled errors - Given I run the service "que" with the command "bundle exec ruby app.rb handled" - And I run the service "que" with the command "timeout 5 bundle exec que ./app.rb" + Given I start the service "que" + When I execute the command "bundle exec ruby app.rb handled" in the service "que" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is false diff --git a/features/rails_features/integrations.feature b/features/rails_features/integrations.feature index bd8c9d40e..1b4655417 100644 --- a/features/rails_features/integrations.feature +++ b/features/rails_features/integrations.feature @@ -1,14 +1,10 @@ Feature: App type is set correctly for integrations in a Rails app -Background: - Given I start the rails service - And I run the "db:prepare" rake task in the rails app - And I run the "db:migrate" rake task in the rails app - @rails_integrations Scenario: Delayed job + Given I start the rails service with the database + And I run the "jobs:work" rake task in the rails app in the background When I run "User.new.delay.raise_the_roof" with the rails runner - And I run the "jobs:workoff" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -27,6 +23,7 @@ Scenario: Delayed job @rails_integrations Scenario: Mailman + Given I start the rails service When I run "./run_mailman" in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier @@ -41,8 +38,9 @@ Scenario: Mailman @rails_integrations Scenario: Que + Given I start the rails service with the database + And I run "bundle exec que ./config/environment.rb" in the rails app in the background When I run "QueJob.enqueue" with the rails runner - And I run "timeout 5 bundle exec que ./config/environment.rb" in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -56,6 +54,7 @@ Scenario: Que @rails_integrations Scenario: Rake + Given I start the rails service When I run the "rake_task:raise" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier @@ -71,8 +70,9 @@ Scenario: Rake @rails_integrations Scenario: Resque (no on_exit hooks) - When I run "Resque.enqueue(ResqueWorker, 123, %(abc), x: true, y: false)" with the rails runner - And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app + Given I start the rails service + And I run the "resque:work" rake task in the rails app in the background + When I run the "fixture:queue_resque_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -87,8 +87,11 @@ Scenario: Resque (no on_exit hooks) 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.payload.args.2.0" equals 7 + And the event "metaData.payload.args.2.1" equals 8 + And the event "metaData.payload.args.2.2" equals 9 + And the event "metaData.payload.args.3.x" is true + And the event "metaData.payload.args.3.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 @@ -96,8 +99,9 @@ Scenario: Resque (no on_exit hooks) @rails_integrations Scenario: Resque (with on_exit hooks) Given I set environment variable "RUN_AT_EXIT_HOOKS" to "1" - When I run "Resque.enqueue(ResqueWorker, %(xyz), [7, 8, 9], a: 4, b: 5)" with the rails runner - And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app + And I start the rails service + And I run the "resque:work" rake task in the rails app in the background + When I run the "fixture:queue_resque_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -110,20 +114,22 @@ 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.payload.args.0" equals 123 + And the event "metaData.payload.args.1" equals "abc" + And the event "metaData.payload.args.2.0" equals 7 + And the event "metaData.payload.args.2.1" equals 8 + And the event "metaData.payload.args.2.2" equals 9 + And the event "metaData.payload.args.3.x" is true + And the event "metaData.payload.args.3.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 @rails_integrations Scenario: Sidekiq + Given I start the rails service + And I run "bundle exec sidekiq" in the rails app in the background When I run "SidekiqWorker.perform_async" with the rails runner - And I run "timeout 5 bundle exec sidekiq" in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -140,8 +146,9 @@ Scenario: Sidekiq @rails_integrations Scenario: Using Sidekiq as the Active Job queue adapter for a job that raises Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "sidekiq" - When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner - And I run "timeout 5 bundle exec sidekiq" in the rails app + And I start the rails service + And I run "bundle exec sidekiq" in the rails app in the background + When I run the "fixture:queue_unhandled_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -162,8 +169,9 @@ Scenario: Using Sidekiq as the Active Job queue adapter for a job that raises @rails_integrations Scenario: Using Resque as the Active Job queue adapter for a job that raises Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque" - When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner - And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app + And I start the rails service + And I run the "resque:work" rake task in the rails app in the background + When I run the "fixture:queue_unhandled_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -183,8 +191,9 @@ Scenario: Using Resque as the Active Job queue adapter for a job that raises @rails_integrations Scenario: Using Que as the Active Job queue adapter for a job that raises Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "que" - When I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner - And I run "timeout 5 bundle exec que -q default ./config/environment.rb" in the rails app + And I start the rails service with the database + And I run "bundle exec que -q default ./config/environment.rb" in the rails app in the background + When I run the "fixture:queue_unhandled_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -204,8 +213,9 @@ Scenario: Using Que as the Active Job queue adapter for a job that raises @rails_integrations Scenario: Using Delayed Job as the Active Job queue adapter for a job that raises Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "delayed_job" - And I run "UnhandledJob.perform_later(1, yes: true)" with the rails runner - And I run the "jobs:workoff" rake task in the rails app + And I start the rails service with the database + And I run the "jobs:work" rake task in the rails app in the background + When I run the "fixture:queue_unhandled_job" rake task in the rails app And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -225,27 +235,31 @@ Scenario: Using Delayed Job as the Active Job queue adapter for a job that raise @rails_integrations Scenario: Using Sidekiq as the Active Job queue adapter for a job that works Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "sidekiq" - And I run "WorkingJob.perform_later" with the rails runner - And I run "timeout 5 bundle exec sidekiq" in the rails app + And I start the rails service + And I run "bundle exec sidekiq" in the rails app in the background + When I run the "fixture:queue_working_job" rake task in the rails app Then I should receive no requests @rails_integrations Scenario: Using Resque as the Active Job queue adapter for a job that works Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "resque" - And I run "WorkingJob.perform_later" with the rails runner - And I run "timeout --signal QUIT 5 bundle exec rake resque:work" in the rails app + And I start the rails service + And I run "bundle exec rake resque:work" in the rails app in the background + When I run the "fixture:queue_working_job" rake task in the rails app Then I should receive no requests @rails_integrations Scenario: Using Que as the Active Job queue adapter for a job that works Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "que" - And I run "WorkingJob.perform_later" with the rails runner - And I run "timeout 5 bundle exec que -q default ./config/environment.rb" in the rails app + And I start the rails service with the database + And I run "bundle exec que -q default ./config/environment.rb" in the rails app in the background + When I run the "fixture:queue_working_job" rake task in the rails app Then I should receive no requests @rails_integrations Scenario: Using Delayed Job as the Active Job queue adapter for a job that works Given I set environment variable "ACTIVE_JOB_QUEUE_ADAPTER" to "delayed_job" - And I run "WorkingJob.perform_later" with the rails runner - And I run the "jobs:workoff" rake task in the rails app + And I start the rails service with the database + And I run the "jobs:work" rake task in the rails app in the background + When I run the "fixture:queue_working_job" rake task in the rails app Then I should receive no requests diff --git a/features/sidekiq.feature b/features/sidekiq.feature index f3f398841..181f04809 100644 --- a/features/sidekiq.feature +++ b/features/sidekiq.feature @@ -1,7 +1,8 @@ Feature: Bugsnag raises errors in Sidekiq workers Scenario: An unhandled RuntimeError sends a report - Given I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:unhandled_error" + Given I start the service "sidekiq" + And I execute the command "bundle exec ruby initializers/UnhandledError.rb" in the service "sidekiq" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is true @@ -19,7 +20,8 @@ Scenario: An unhandled RuntimeError sends a report And the event "metaData.config.delivery_method" equals "thread_queue" Scenario: A handled RuntimeError can be notified - Given I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:handled_error" + Given I start the service "sidekiq" + And I execute the command "bundle exec ruby initializers/HandledError.rb" in the service "sidekiq" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is false @@ -35,7 +37,8 @@ Scenario: A handled RuntimeError can be notified Scenario: Synchronous delivery can be used Given I set environment variable "BUGSNAG_DELIVERY_METHOD" to "synchronous" - And I run the service "sidekiq" with the command "timeout 5 bundle exec rake sidekiq_tests:handled_error" + And I start the service "sidekiq" + And I execute the command "bundle exec ruby initializers/HandledError.rb" in the service "sidekiq" And I wait to receive an error Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier And the event "unhandled" is false diff --git a/features/steps/ruby_notifier_steps.rb b/features/steps/ruby_notifier_steps.rb index 6c2640790..1fc8f375d 100644 --- a/features/steps/ruby_notifier_steps.rb +++ b/features/steps/ruby_notifier_steps.rb @@ -27,13 +27,27 @@ } end +Given("I start the rails service with the database") do + steps %Q{ + Given I start the rails service + And I run the "db:prepare" rake task in the rails app + And I run the "db:migrate" rake task in the rails app + } +end + When("I navigate to the route {string} on the rails app") do |route| RAILS_FIXTURE.navigate_to(route) end When("I run {string} in the rails app") do |command| steps %Q{ - When I run the service "rails#{ENV['RAILS_VERSION']}" with the command "#{command}" + When I execute the command "#{command}" in the service "rails#{ENV['RAILS_VERSION']}" + } +end + +When("I run {string} in the rails app in the background") do |command| + steps %Q{ + When I execute the command "#{command}" in the service "rails#{ENV['RAILS_VERSION']}" in the background } end @@ -43,9 +57,15 @@ } end +When("I run the {string} rake task in the rails app in the background") do |task| + steps %Q{ + When I run "bundle exec rake #{task}" in the rails app in the background + } +end + When("I run {string} with the rails runner") do |code| steps %Q{ - When I run "bundle exec rails runner '#{code}'" in the rails app + When I execute the command "bundle exec rails runner #{code}" in the service "rails#{ENV['RAILS_VERSION']}" } end diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index a25ed6b49..5d002a907 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -78,7 +78,7 @@ def configure(validate_api_key=true) # # Optionally accepts a block to append metadata to the yielded report. def notify(exception, auto_notify=false, &block) - unless auto_notify.is_a? TrueClass or auto_notify.is_a? FalseClass + unless false.equal? auto_notify or true.equal? auto_notify configuration.warn("Adding metadata/severity using a hash is no longer supported, please use block syntax instead") auto_notify = false end