diff --git a/sentry-rails/lib/sentry/rails/configuration.rb b/sentry-rails/lib/sentry/rails/configuration.rb index 1b2fa93db..2b9bff571 100644 --- a/sentry-rails/lib/sentry/rails/configuration.rb +++ b/sentry-rails/lib/sentry/rails/configuration.rb @@ -176,7 +176,7 @@ def initialize @enable_db_query_source = true @db_query_source_threshold_ms = 100 @active_support_logger_subscription_items = Sentry::Rails::ACTIVE_SUPPORT_LOGGER_SUBSCRIPTION_ITEMS_DEFAULT.dup - @active_job_report_after_job_retries = false + @active_job_report_after_job_retries = true end end end diff --git a/sentry-rails/spec/sentry/rails/activejob_spec.rb b/sentry-rails/spec/sentry/rails/activejob_spec.rb index 85b58df9b..08a0ef88b 100644 --- a/sentry-rails/spec/sentry/rails/activejob_spec.rb +++ b/sentry-rails/spec/sentry/rails/activejob_spec.rb @@ -1,77 +1,6 @@ # frozen_string_literal: true -require "spec_helper" -require "active_job/railtie" - -class NormalJob < ActiveJob::Base - def perform - "foo" - end -end - -class FailedJob < ActiveJob::Base - self.logger = nil - - class TestError < RuntimeError - end - - def perform - a = 1 - b = 0 - raise TestError, "Boom!" - end -end - -class FailedWithExtraJob < FailedJob - def perform - Sentry.get_current_scope.set_extras(foo: :bar) - super - end -end - -class JobWithArgument < ActiveJob::Base - def perform(*args, integer:, post:, **options) - raise "foo" - end -end - -class QueryPostJob < ActiveJob::Base - self.logger = nil - - def perform - Post.all.to_a - end -end - -class RescuedActiveJob < FailedWithExtraJob - rescue_from TestError, with: :rescue_callback - - def rescue_callback(error); end -end - -class ProblematicRescuedActiveJob < FailedWithExtraJob - rescue_from TestError, with: :rescue_callback - - def rescue_callback(error) - raise "foo" - end -end - -class NormalJobWithCron < NormalJob - include Sentry::Cron::MonitorCheckIns - sentry_monitor_check_ins -end - -class FailedJobWithCron < FailedJob - include Sentry::Cron::MonitorCheckIns - sentry_monitor_check_ins slug: "failed_job", monitor_config: Sentry::Cron::MonitorConfig.from_crontab("5 * * * *") -end - -class FailedJobWithRetryOn < FailedJob - if respond_to? :retry_on - retry_on StandardError, attempts: 3, wait: 0 - end -end +require_relative "../../support/test_jobs" RSpec.describe "without Sentry initialized", type: :job do it "runs job" do @@ -85,7 +14,9 @@ class FailedJobWithRetryOn < FailedJob RSpec.describe "ActiveJob integration", type: :job do before do - make_basic_app + make_basic_app do |config| + config.rails.active_job_report_after_job_retries = false + end end let(:event) do @@ -218,6 +149,7 @@ def post.to_global_id before do make_basic_app do |config| config.traces_sample_rate = 1.0 + config.rails.active_job_report_after_job_retries = false end end @@ -261,7 +193,9 @@ def post.to_global_id context "when DeserializationError happens in user's jobs" do before do - make_basic_app + make_basic_app do |config| + config.rails.active_job_report_after_job_retries = false + end end class DeserializationErrorJob < ActiveJob::Base @@ -441,7 +375,16 @@ def perform(event, hint) end end + context "when active_job_report_after_job_retries is false" do + before do + Sentry.configuration.rails.active_job_report_after_job_retries = false + end + + after do + Sentry.configuration.rails.active_job_report_after_job_retries = true + end + it "reports 3 exceptions" do allow(Sentry::Rails::ActiveJobExtensions::SentryReporter) .to receive(:capture_exception).and_call_original diff --git a/sentry-rails/spec/sentry/rails/configuration_spec.rb b/sentry-rails/spec/sentry/rails/configuration_spec.rb index b7961f894..fbee96120 100644 --- a/sentry-rails/spec/sentry/rails/configuration_spec.rb +++ b/sentry-rails/spec/sentry/rails/configuration_spec.rb @@ -62,7 +62,7 @@ class MySubscriber; end describe "#active_job_report_after_job_retries" do it "has correct default value" do - expect(subject.active_job_report_after_job_retries).to eq(false) + expect(subject.active_job_report_after_job_retries).to be(true) end end end diff --git a/sentry-rails/spec/support/test_jobs.rb b/sentry-rails/spec/support/test_jobs.rb index 8f2957c70..4923d9a49 100644 --- a/sentry-rails/spec/support/test_jobs.rb +++ b/sentry-rails/spec/support/test_jobs.rb @@ -65,3 +65,9 @@ class FailedJobWithCron < FailedJob include Sentry::Cron::MonitorCheckIns sentry_monitor_check_ins slug: "failed_job", monitor_config: Sentry::Cron::MonitorConfig.from_crontab("5 * * * *") end + +class FailedJobWithRetryOn < FailedJob + if respond_to? :retry_on + retry_on StandardError, attempts: 3, wait: 0 + end +end