DEV: Add ENV variable for enabling MiniProfiler snapshots (#10690)

* DEV: Add ENV variable for enabling MiniProfiler snapshots

* MiniProfiler is not loaded in test env
This commit is contained in:
Osama Sayegh 2020-09-17 18:18:35 +03:00 committed by GitHub
parent 6e69c25134
commit a92d88747e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -31,6 +31,7 @@ class ApplicationController < ActionController::Base
before_action :check_readonly_mode
before_action :handle_theme
before_action :set_current_user_for_logs
before_action :set_mp_snapshot_fields
before_action :clear_notifications
around_action :with_resolved_locale
before_action :set_mobile_view
@ -295,6 +296,12 @@ class ApplicationController < ActionController::Base
response.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}"
end
def set_mp_snapshot_fields
if defined?(Rack::MiniProfiler)
Rack::MiniProfiler.add_snapshot_custom_field("application version", Discourse.git_version)
end
end
def clear_notifications
if current_user && !@readonly_mode

View File

@ -95,6 +95,10 @@ smtp_openssl_verify_mode =
# load MiniProfiler in production, to be used by developers
load_mini_profiler = true
# Every how many requests should MP profile a request (aka take snapshot)
# Default is never
mini_profiler_snapshots_period = 0
# recommended, cdn used to access assets
cdn_url =

View File

@ -24,7 +24,8 @@ if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)
connection: DiscourseRedis.new(nil, namespace: false)
)
skip = [
Rack::MiniProfiler.config.snapshot_every_n_requests = GlobalSetting.mini_profiler_snapshots_period
Rack::MiniProfiler.config.skip_paths = [
/^\/message-bus/,
/^\/extra-locales/,
/topics\/timings/,
@ -51,10 +52,7 @@ if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)
# we DO NOT WANT mini-profiler loading on anything but real desktops and laptops
# so let's rule out all handheld, tablet, and mobile devices
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
path = env['PATH_INFO']
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/) &&
!skip.any? { |re| re =~ path }
env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/
end
# without a user provider our results will use the ip address for namespacing