Skip to content

fix(rails): don't load ActionController::Live before initialization - #3109

Merged
sl0thentr0py merged 1 commit into
getsentry:masterfrom
ajaynomics:fix-rails-live-load-hook
Oct 28, 2026
Merged

sl0thentr0py merged 1 commit into
getsentry:masterfrom
ajaynomics:fix-rails-live-load-hook

Conversation

@ajaynomics

Copy link
Copy Markdown
Contributor

Description

Under Rails 8.1 with eager_load off (rake tasks, console, most dev boots), sentry-rails makes Rails print:

:action_dispatch_response was loaded before application initialization

The railtie referenced ActionController::Live inside the :action_controller load hook to prepend StreamingReporter. That reference autoloads ActionController::Live, which loads ActionDispatch::Response too early, and Rails warns.

Rails 8.1.4 added an :action_controller_live load hook. This PR prepends the reporter from that hook, so nothing touches ActionController::Live until the app does. On older Rails the direct reference stays.

Tested with a new isolated spec, sentry-rails/spec/isolated/streaming_reporter_spec.rb. It asserts the reporter is still prepended, and boots a bare app in a child process to assert initialization leaves ActionController::Live unloaded. The second example fails on master and passes here. spec/isolated and spec/sentry pass on the ruby-3.4_rails-8.1.3 cell; RuboCop is clean on both files.

Referencing ActionController::Live in the railtie loads ActionDispatch::Response
before the application has initialized, which Rails 8.1 warns about when
eager loading is off. Use the :action_controller_live load hook that Rails
8.1.4 added, and keep the direct reference on older versions.
@sl0thentr0py
sl0thentr0py force-pushed the fix-rails-live-load-hook branch from 2e45071 to 1e7e1b1 Compare October 28, 2026 13:48
@sl0thentr0py

Copy link
Copy Markdown
Member

thx @ajaynomics !

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.19%. Comparing base (7d10c02) to head (1e7e1b1).
⚠️ Report is 208 commits behind head on master.

Files with missing lines Patch % Lines
sentry-rails/lib/sentry/rails/railtie.rb 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3109      +/-   ##
==========================================
+ Coverage   90.13%   90.19%   +0.05%     
==========================================
  Files         132      155      +23     
  Lines        5301     6455    +1154     
==========================================
+ Hits         4778     5822    +1044     
- Misses        523      633     +110     
Components Coverage Δ
sentry-ruby 97.13% <ø> (-0.16%) ⬇️
sentry-rails 57.40% <ø> (+1.89%) ⬆️
sentry-sidekiq 95.08% <ø> (+0.03%) ⬆️
sentry-resque 94.44% <ø> (ø)
sentry-delayed_job 94.68% <ø> (ø)
sentry-opentelemetry 99.55% <100.00%> (+0.24%) ⬆️
Files with missing lines Coverage Δ
sentry-rails/lib/sentry/rails/railtie.rb 24.17% <16.66%> (-1.44%) ⬇️

... and 72 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sl0thentr0py
sl0thentr0py merged commit 368796f into getsentry:master Oct 28, 2026
156 of 157 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sentry-rails triggers "Prematurely executing load hooks" warning for :action_dispatch_response on Rails 8.2

2 participants