Skip to content

Commit

Permalink
Refactor Sentry's Railtie
Browse files Browse the repository at this point in the history
1. Give every patch/extension their own method to clarify their
   purposes.
2. Move most of the patches into after_initializer hook from their own
   initializers. This is for making the order of each step more
   understandable.
  • Loading branch information
st0012 committed Dec 16, 2020
1 parent 75d78de commit 460ff62
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions sentry-rails/lib/sentry/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@

module Sentry
class Railtie < ::Rails::Railtie
# middlewares can't be injected after initialize
initializer "sentry.use_rack_middleware" do |app|
app.config.middleware.insert 0, Sentry::Rails::CaptureExceptions
end

initializer 'sentry.action_controller' do
ActiveSupport.on_load :action_controller do
include Sentry::Rails::ControllerMethods
include Sentry::Rails::ControllerTransaction
ActionController::Live.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
end
config.after_initialize do
configure_sentry_logger
extend_controller_methods
extend_active_job
override_exceptions_handling
override_streaming_reporter
setup_backtrace_cleanup_callback
inject_breadcrumbs_logger
activate_tracing
end

initializer 'sentry.action_view' do
ActiveSupport.on_load :action_view do
ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
end
def configure_sentry_logger
Sentry.configuration.logger = ::Rails.logger
end

config.after_initialize do
Sentry.configuration.logger = ::Rails.logger
def extend_active_job
ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
end

setup_backtrace_cleanup_callback
inject_breadcrumbs_logger
override_exceptions_handling
activate_tracing
def extend_controller_methods
ActiveSupport.on_load :action_controller do
include Sentry::Rails::ControllerMethods
include Sentry::Rails::ControllerTransaction
ActionController::Live.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
end
end

def inject_breadcrumbs_logger
Expand Down Expand Up @@ -63,17 +68,17 @@ def override_exceptions_handling
end
end

def override_streaming_reporter
ActiveSupport.on_load :action_view do
ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
end
end

def activate_tracing
if Sentry.configuration.tracing_enabled?
Sentry::Rails::Tracing.subscribe_tracing_events
Sentry::Rails::Tracing.patch_active_support_notifications
end
end

initializer 'sentry.active_job' do
ActiveSupport.on_load :active_job do
require 'sentry/rails/active_job'
end
end
end
end

0 comments on commit 460ff62

Please sign in to comment.