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:
parent
6e69c25134
commit
a92d88747e
|
@ -31,6 +31,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :check_readonly_mode
|
before_action :check_readonly_mode
|
||||||
before_action :handle_theme
|
before_action :handle_theme
|
||||||
before_action :set_current_user_for_logs
|
before_action :set_current_user_for_logs
|
||||||
|
before_action :set_mp_snapshot_fields
|
||||||
before_action :clear_notifications
|
before_action :clear_notifications
|
||||||
around_action :with_resolved_locale
|
around_action :with_resolved_locale
|
||||||
before_action :set_mobile_view
|
before_action :set_mobile_view
|
||||||
|
@ -295,6 +296,12 @@ class ApplicationController < ActionController::Base
|
||||||
response.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}"
|
response.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}"
|
||||||
end
|
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
|
def clear_notifications
|
||||||
if current_user && !@readonly_mode
|
if current_user && !@readonly_mode
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,10 @@ smtp_openssl_verify_mode =
|
||||||
# load MiniProfiler in production, to be used by developers
|
# load MiniProfiler in production, to be used by developers
|
||||||
load_mini_profiler = true
|
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
|
# recommended, cdn used to access assets
|
||||||
cdn_url =
|
cdn_url =
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ if defined?(Rack::MiniProfiler) && defined?(Rack::MiniProfiler::Config)
|
||||||
connection: DiscourseRedis.new(nil, namespace: false)
|
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/,
|
/^\/message-bus/,
|
||||||
/^\/extra-locales/,
|
/^\/extra-locales/,
|
||||||
/topics\/timings/,
|
/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
|
# 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
|
# so let's rule out all handheld, tablet, and mobile devices
|
||||||
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
|
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
|
||||||
path = env['PATH_INFO']
|
env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/
|
||||||
|
|
||||||
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/) &&
|
|
||||||
!skip.any? { |re| re =~ path }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# without a user provider our results will use the ip address for namespacing
|
# without a user provider our results will use the ip address for namespacing
|
||||||
|
|
Loading…
Reference in New Issue