Skip to content

Commit

Permalink
Merge c0d4dd9 into 7b9f8fc
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother authored Jul 5, 2021
2 parents 7b9f8fc + c0d4dd9 commit 537ff27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Correct the timing of loading ActiveJobExtensions, take 2 [#1494](https://github.com/getsentry/sentry-ruby/pull/1494)

## 4.6.0

### Features
Expand Down
10 changes: 4 additions & 6 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Railtie < ::Rails::Railtie
# before the application is eager-loaded (before user's jobs register their own callbacks)
# See https://github.com/getsentry/sentry-ruby/issues/1249#issuecomment-853871871 for the detail explanation
initializer "sentry.extend_active_job", before: :eager_load! do |app|
extend_active_job if defined?(ActiveJob)
ActiveSupport.on_load(:active_job) do
require "sentry/rails/active_job"
prepend Sentry::Rails::ActiveJobExtensions
end
end

config.after_initialize do |app|
Expand Down Expand Up @@ -45,11 +48,6 @@ def configure_trusted_proxies
Sentry.configuration.trusted_proxies += Array(::Rails.application.config.action_dispatch.trusted_proxies)
end

def extend_active_job
require "sentry/rails/active_job"
ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
end

def extend_controller_methods
require "sentry/rails/controller_methods"
require "sentry/rails/controller_transaction"
Expand Down
11 changes: 10 additions & 1 deletion sentry-rails/spec/isolated/active_job_activation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
# for https://github.com/getsentry/sentry-ruby/issues/1249
require "active_job"
require "active_job/railtie"
require "active_support/all"
require "sentry/rails"
require "minitest/autorun"
Expand All @@ -12,6 +12,11 @@ class TestApp < Rails::Application

app = TestApp

# Simulate code from the application's init files in config/initializer
app.initializer :config_initializer do
Rails.application.config.active_job.queue_name = "bobo"
end

# to simulate jobs being load during the eager_load initializer
app.initializer :eager_load! do
Object.class_eval <<~CODE
Expand Down Expand Up @@ -56,4 +61,8 @@ def test_the_extension_is_loaded_before_eager_load_is_called
assert_match(/RESCUED/, log_result, "ApplicationJob's rescue_from should be called")
refute_match(/I SHOULD NEVER BE EXECUTED/, log_result, "ErrorJob's around_perform should not be triggered")
end

def test_the_extension_doesnt_load_activejob_too_soon
assert_equal("bobo", ApplicationJob.queue_name)
end
end

0 comments on commit 537ff27

Please sign in to comment.