Action Controller Instrumentation
在 ActionController::Base
中为多个端点添加了 instrumentation。它还提供了一些与 process_action 相关的钩子。这允许像 Active Record 和/或 DataMapper 这样的 ORM 插入 ActionController
并显示相关信息。
查看 ActiveRecord::Railties::ControllerRuntime 获取示例。
命名空间
方法
实例公共方法
redirect_to(*) 链接
源代码: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 47 def redirect_to(*) ActiveSupport::Notifications.instrument("redirect_to.action_controller", request: request) do |payload| result = super payload[:status] = response.status payload[:location] = response.filtered_location result end end
render(*) 链接
源代码: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 26 def render(*) render_output = nil self.view_runtime = cleanup_view_runtime do Benchmark.ms { render_output = super } end render_output end
send_data(data, options = {}) 链接
源代码: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 41 def send_data(data, options = {}) ActiveSupport::Notifications.instrument("send_data.action_controller", options) do super end end
send_file(path, options = {}) 链接
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 34 def send_file(path, options = {}) ActiveSupport::Notifications.instrument("send_file.action_controller", options.merge(path: path)) do super end end
实例私有方法
append_info_to_payload(payload) 链接
每次处理完操作后,都会使用有效负载调用此方法,因此您可以添加更多信息。
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 103 def append_info_to_payload(payload) # :doc: payload[:view_runtime] = view_runtime end
cleanup_view_runtime() 链接
一个钩子,允许您清理任何时间,错误地计入视图,例如数据库查询时间。
def cleanup_view_runtime
super - time_taken_in_something_expensive
end
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_controller/metal/instrumentation.rb, line 97 def cleanup_view_runtime # :doc: yield end