Skip to content

Re-position RescuedExceptionInterceptor middleware #1564

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

Merged
merged 1 commit into from
Sep 8, 2021
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
4 changes: 2 additions & 2 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Railtie < ::Rails::Railtie
initializer "sentry.use_rack_middleware" do |app|
# placed after all the file-sending middlewares so we can avoid unnecessary transactions
app.config.middleware.insert_after ActionDispatch::Executor, Sentry::Rails::CaptureExceptions
# need to be placed at last to smuggle app exceptions via env
app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
# need to place as close to DebugExceptions as possible to intercept most of the exceptions, including those raised by middlewares
app.config.middleware.insert_after ActionDispatch::DebugExceptions, Sentry::Rails::RescuedExceptionInterceptor
end

# because the extension works by registering the around_perform callcack, it should always be ran
Expand Down
3 changes: 2 additions & 1 deletion sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
app = Rails.application
index_of_executor = app.middleware.find_index { |m| m == ActionDispatch::Executor }
expect(app.middleware.find_index(Sentry::Rails::CaptureExceptions)).to eq(index_of_executor + 1)
expect(app.middleware.find_index(Sentry::Rails::RescuedExceptionInterceptor)).to eq(app.middleware.count - 1)
index_of_debug_exceptions = app.middleware.find_index { |m| m == ActionDispatch::DebugExceptions }
expect(app.middleware.find_index(Sentry::Rails::RescuedExceptionInterceptor)).to eq(index_of_debug_exceptions + 1)
end

it "inserts a callback to disable background_worker for the runner mode" do
Expand Down