Sha256: 8f740e3c49908846059ea6bd624dd8c94850e37f2d097d16e2ecea81ad229e3b
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
module Hickory module LogSubscribers class ActionController < ActiveSupport::LogSubscriber def process_action(event) return if Hickory::Rails.ignore_if.present? && Hickory::Rails.ignore_if.call(event) payload = event.payload default_keys = %i[method format controller action user_id request_id] metadata = payload.slice(default_keys).tap { |data| data.merge!(uri(payload)) data.merge!(runtimes(event, payload)) data.merge!(status(payload)) data.merge!(params(payload)) } logger.info("canonical-request #{metadata[:method]} #{metadata[:path]}", metadata) end private def uri(payload) return {} unless payload.key?(:path) _uri = URI.parse(payload[:path]) { path: _uri.path }.tap { |data| data[:query] = _uri.query unless _uri.query.nil? } end def runtimes(event, payload) { duration: event.duration.to_f.round(2) }.tap { |data| data[:view] = payload[:view_runtime].to_f.round(2) if payload.key?(:view_runtime) data[:db] = payload[:db_runtime].to_f.round(2) if payload.key?(:db_runtime) } end def status(payload) if status = payload[:status] { status: status.to_i } elsif error = payload[:exception] exception, message = error { status: get_error_status_code(exception), error: "#{exception}: #{message}" } else { status: 0 } end end def params(payload) { params: payload[:params].except(:controller, :action, :format) } end def get_error_status_code(exception) status = ActionDispatch::ExceptionWrapper.rescue_responses[exception] Rack::Utils.status_code(status) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hickory-0.1.4 | lib/hickory/log_subscribers/action_controller.rb |