From de355f97c332e3b8ff52dc76b0c39829b9f6ddda Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 5 Oct 2023 11:05:03 +0100 Subject: [PATCH 1/3] Update setup for Rails 7.1 --- sentry-rails/Gemfile | 6 ++-- .../spec/dummy/test_rails_app/configs/7-2.rb | 36 +++++++++++++++++++ sentry-rails/spec/sentry/rails_spec.rb | 6 ---- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb diff --git a/sentry-rails/Gemfile b/sentry-rails/Gemfile index ac53377b9..115e71e02 100644 --- a/sentry-rails/Gemfile +++ b/sentry-rails/Gemfile @@ -11,7 +11,7 @@ platform :jruby do end rails_version = ENV["RAILS_VERSION"] -rails_version = "7.0.0" if rails_version.nil? +rails_version = "7.1.0" if rails_version.nil? rails_version = Gem::Version.new(rails_version) if rails_version < Gem::Version.new("6.0.0") @@ -20,8 +20,10 @@ else gem "sqlite3", platform: :ruby end -if rails_version > Gem::Version.new("7.0.0") +if rails_version >= Gem::Version.new("7.2.0.alpha") gem "rails", github: "rails/rails" +elsif rails_version >= Gem::Version.new("7.1.0") + gem "rails", "~> #{rails_version}" else gem "rails", "~> #{rails_version}" gem "psych", "~> 3.0.0" diff --git a/sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb b/sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb new file mode 100644 index 000000000..d17545fe0 --- /dev/null +++ b/sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb @@ -0,0 +1,36 @@ +require "active_storage/engine" +require "action_cable/engine" +require "sentry/rails/error_subscriber" + +def run_pre_initialize_cleanup + # Zeitwerk checks if registered loaders load paths repeatedly and raises error if that happens. + # And because every new Rails::Application instance registers its own loader, we need to clear previously registered ones from Zeitwerk. + Zeitwerk::Registry.loaders.clear + + # Rails removes the support of multiple instances, which includes freezing some setting values. + # This is the workaround to avoid FrozenError. Related issue: https://github.com/rails/rails/issues/42319 + ActiveSupport::Dependencies.autoload_once_paths = [] + ActiveSupport::Dependencies.autoload_paths = [] + + # there are a few Rails initializers/finializers that register hook to the executor + # because the callbacks are stored inside the `ActiveSupport::Executor` class instead of an instance + # the callbacks duplicate after each time we initialize the application and cause issues when they're executed + ActiveSupport::Executor.reset_callbacks(:run) + ActiveSupport::Executor.reset_callbacks(:complete) + + # Rails uses this module to set a global context for its ErrorReporter feature. + # this needs to be cleared so previously set context won't pollute later reportings (see ErrorSubscriber). + ActiveSupport::ExecutionContext.clear + + ActionCable::Channel::Base.reset_callbacks(:subscribe) + ActionCable::Channel::Base.reset_callbacks(:unsubscribe) + + # Rails 7.1 stores the error reporter directly under the ActiveSupport class. + # So we need to make sure the subscriber is not subscribed unexpectedly before any tests + ActiveSupport.error_reporter.unsubscribe(Sentry::Rails::ErrorSubscriber) +end + +def configure_app(app) + app.config.active_storage.service = :test + app.config.enable_reloading = false +end diff --git a/sentry-rails/spec/sentry/rails_spec.rb b/sentry-rails/spec/sentry/rails_spec.rb index 5d2e35a6e..9aaf37252 100644 --- a/sentry-rails/spec/sentry/rails_spec.rb +++ b/sentry-rails/spec/sentry/rails_spec.rb @@ -14,12 +14,6 @@ make_basic_app end - after do - # We need to cleanup Rails.logger because after https://github.com/rails/rails/pull/49417 - # Rails.logger could get recreated with the previous logger value and become deeply nested broadcast logger - Rails.logger = nil - end - it "has version set" do expect(described_class::VERSION).to be_a(String) end From 8c217dc820547f407462232ecee2286cf57bb11f Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 5 Oct 2023 11:15:27 +0100 Subject: [PATCH 2/3] Pin sentry-delayed_job's Rails version --- sentry-delayed_job/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-delayed_job/Gemfile b/sentry-delayed_job/Gemfile index 4abb1cb88..4ab4c8be3 100644 --- a/sentry-delayed_job/Gemfile +++ b/sentry-delayed_job/Gemfile @@ -14,7 +14,7 @@ gem "rexml" gem "delayed_job" gem "delayed_job_active_record" -gem "rails" +gem "rails", "> 5.0.0", "< 7.1.0" platform :jruby do gem "activerecord-jdbcmysql-adapter" From 9cc99ca7ed214cd77853815a6df4b5b4846ab292 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 5 Oct 2023 11:16:13 +0100 Subject: [PATCH 3/3] Fix sentry-sidekiq's build failure --- sentry-sidekiq/Gemfile | 12 +++++++++--- .../sentry/sidekiq/sentry_context_middleware_spec.rb | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/sentry-sidekiq/Gemfile b/sentry-sidekiq/Gemfile index 692fae02d..b2bc2e8a8 100644 --- a/sentry-sidekiq/Gemfile +++ b/sentry-sidekiq/Gemfile @@ -17,9 +17,16 @@ gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5 sidekiq_version = ENV["SIDEKIQ_VERSION"] sidekiq_version = "6.0" if sidekiq_version.nil? +sidekiq_version = Gem::Version.new(sidekiq_version) -gem "sidekiq", "~> #{sidekiq_version}" -gem "rails" +if sidekiq_version >= Gem::Version.new("7.0") + # This is for a unreleased fix for sidekiq 7 + # https://github.com/sidekiq/sidekiq/commit/b7236f814ccb61d3b1e6fc5251ed3d3ac7428eb3 + gem "sidekiq", github: "sidekiq/sidekiq" +else + gem "sidekiq", "~> #{sidekiq_version}" +end +gem "rails", "> 5.0.0", "< 7.1.0" if RUBY_VERSION.to_f >= 2.6 gem "debug", github: "ruby/debug", platform: :ruby @@ -27,4 +34,3 @@ if RUBY_VERSION.to_f >= 2.6 end gem "pry" - diff --git a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb index 4a8542291..f7c1a21a3 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb @@ -22,7 +22,7 @@ execute_worker(processor, SadWorker) expect(transport.events.count).to eq(1) - event = transport.events.first + event = transport.events[0] expect(event.user).to eq(user) end @@ -36,7 +36,7 @@ execute_worker(processor, HappyWorker) expect(transport.events.count).to eq(1) - transaction = transport.events.first + transaction = transport.events[0] expect(transaction).not_to be_nil expect(transaction.user).to eq(user) end @@ -45,7 +45,7 @@ execute_worker(processor, SadWorker) expect(transport.events.count).to eq(2) - transaction = transport.events.first + transaction = transport.events[0] expect(transaction.user).to eq(user) event = transport.events.last expect(event.user).to eq(user) @@ -65,7 +65,7 @@ execute_worker(processor, HappyWorker, trace_propagation_headers: trace_propagation_headers) expect(transport.events.count).to eq(1) - transaction = transport.events.first + transaction = transport.events[0] expect(transaction).not_to be_nil expect(transaction.contexts.dig(:trace, :trace_id)).to eq(parent_transaction.trace_id) end @@ -140,11 +140,11 @@ q = queue.to_a expect(q.size).to be(2) - first_headers = q.first["trace_propagation_headers"] + first_headers = q[0]["trace_propagation_headers"] expect(first_headers["sentry-trace"]).to eq(transaction.to_sentry_trace) expect(first_headers["baggage"]).to eq(transaction.to_baggage) - second_headers = q.second["trace_propagation_headers"] + second_headers = q[1]["trace_propagation_headers"] expect(second_headers["sentry-trace"]).to eq(transaction.to_sentry_trace) expect(second_headers["baggage"]).to eq(transaction.to_baggage) end