Skip to content

Instantly share code, notes, and snippets.

@tdl
Last active December 17, 2015 06:19
Show Gist options
  • Save tdl/5564590 to your computer and use it in GitHub Desktop.
Save tdl/5564590 to your computer and use it in GitHub Desktop.
Using MiniProfiler in production on Heroku
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :miniprofiler
# just authorize all requests
private
def miniprofiler
Rack::MiniProfiler.authorize_request
end
end
# it's best to depend on trunk of MiniProfiler, e.g. due to the issue I had with
# graphs not showing up over HTTPS which is fixed in
# https://github.com/SamSaffron/MiniProfiler/commit/831b917e70d57bc3c03858c46b3c5828f73e3f35
gem 'rack-mini-profiler', git: 'git://github.com/SamSaffron/MiniProfiler.git'
# config/initializers/mini_profiler.rb
# Heroku + Unicorn will not work with either:
# FileStore (no persistent disk access allowed)
# MemoryStore (data kept in one process, but Unicorn forks multiple processes)
# Easiest to use is therefore MemcacheStore. RedisStore requires more setup.
if Rails.env.production?
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemcacheStore
# optional: set a user_provider which defaults to always the same user
# by default MiniProfiler separates requests by IP address
# Rack::MiniProfiler.config.user_provider = Proc.new { |env| "tom" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment