Skip to content
Closed
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
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 17 additions & 74 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry-rails/spec/sentry/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions sentry-rails/spec/support/test_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading