Skip to content

Instantly share code, notes, and snippets.

@itsderek23
Created April 9, 2017 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save itsderek23/72f0d0ddf1d2ed3d906ba1c9e859ff9f to your computer and use it in GitHub Desktop.
Save itsderek23/72f0d0ddf1d2ed3d906ba1c9e859ff9f to your computer and use it in GitHub Desktop.
# config/intializers/page_request_info.rb
module ActionController
class PageRequestInfo
# http://guides.rubyonrails.org/active_support_instrumentation.html
# http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html
# call() is called as an ActiveSupport::Notifications subscriber callback - see the very bottom of this file for the subscriber registration
# We manipulate the Notification event payload so that lograge can log out extra information easily.
def call(name, started, finished, unique_id, payload)
request_info = Thread.current[:page_request_info] || {}
log_info = {}
log_info.merge!(select_params(payload))
log_info.merge!(user_info(request_info[:current_user]))
payload.merge!(log_info)
rescue StandardError => e
# Log errors in Sentry ... don't want our app to blow up because of an instrumentation exception.
Raven.extra_context(request_info: request_info, payload: payload)
Raven.capture_exception(e)
end
private
# Lograge already logs the controller and action from the raw payload. No reason to log it in params as well.
def select_params(payload)
return {} if !payload[:params].is_a?(Hash)
params = payload[:params].reject do |k|
['controller', 'action'].include? k
end
{ params: params }
end
def user_info(user)
if user.is_a?(User)
{ user_id: user.id, user_email: user.email }
else
{}
end
end
end
end
@sebastianvirlan
Copy link

Hi, is there any solution in order to print :view_runtime and :db_runtime direct to the webpage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment