Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup for Rails 7.1 #2125

Merged
merged 3 commits into from
Oct 7, 2023
Merged
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-delayed_job/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions sentry-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour has been addressed in rails/rails#49462, so we don't need this anymore.


it "has version set" do
expect(described_class::VERSION).to be_a(String)
end
Expand Down
12 changes: 9 additions & 3 deletions sentry-sidekiq/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ 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
gem "irb"
end

gem "pry"

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down