require 'action_view/log_subscriber' require_relative './rails/middleware.rb' require_relative './models/collection.rb' require_relative './instrument/metrics_collector.rb' module RailsPerformance class Engine < ::Rails::Engine isolate_namespace RailsPerformance initializer "rails_performance.middleware" do |app| next unless RailsPerformance.enabled if ::Rails::VERSION::MAJOR.to_i >= 5 app.middleware.insert_after ActionDispatch::Executor, RailsPerformance::Rails::Middleware else app.middleware.insert_after ActionDispatch::Static, RailsPerformance::Rails::Middleware end if defined?(Sidekiq) require_relative './gems/sidekiq.rb' Sidekiq.configure_server do |config| config.server_middleware do |chain| chain.add RailsPerformance::Gems::Sidekiq end end end end initializer :configure_metrics, after: :initialize_logger do next unless RailsPerformance.enabled ActiveSupport::Notifications.subscribe( "process_action.action_controller", RailsPerformance::Instrument::MetricsCollector.new ) end config.after_initialize do next unless RailsPerformance.enabled ActionView::LogSubscriber.send :prepend, RailsPerformance::Extensions::View ActiveRecord::LogSubscriber.send :prepend, RailsPerformance::Extensions::Db end end end