MiniProfiler / rack-mini-profiler

Profiler for your development and production Ruby rack apps.
MIT License
3.71k stars 404 forks source link

Can not get it to work on production #545

Closed ranhorev1 closed 1 year ago

ranhorev1 commented 1 year ago

I made the following changes and I just can't get it to work on production (AWS elastic beanstalk)! It works fine on my development docker any suggestions will be highly appreciated!

Gemfile (at the end of it):

gem 'rack-mini-profiler'
gem 'memory_profiler'
gem 'stackprof'

application.rb: tried both (not together of course) Rack::MiniProfiler.config.authorization_mode = :allow_authorized Rack::MiniProfiler.config.authorization_mode = :allow_all

application_controller.rb

before_action do
  Rails.logger.error("Authorize profiler: #{Rack::MiniProfiler.config.authorization_mode}")
  Rack::MiniProfiler.authorize_request
end
ranhorev1 commented 1 year ago

For anyone else running this issue and needs a straight answer, this is eventually how I got it to work: config/initializer/profiler.rb

require 'rack-mini-profiler'

# Initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)

# Needed for staging env
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::FileStore
Rack::MiniProfiler.config.pre_authorize_cb = lambda { |env| true }
Rack::MiniProfiler.config.authorization_mode = :allow_authorized
Rack::MiniProfiler.config.enable_advanced_debugging_tools = true

in both application_controller.rb and the specific api_controller.rb for the endpoint I use (not really sure both are needed, but that's what I ended up having), ofc you should add your authorization conditions

before_action do
  Rack::MiniProfiler.authorize_request
end

Gemfile (at the end of it):

gem 'rack-mini-profiler', require: false
gem 'memory_profiler'
gem 'stackprof'

good luck