Sha256: 16f2f18942ae64f1737d9a66f3a95984b775498f61e75353983b957f8427fbb4

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 KB

Contents

module LogStasher
  module ActionController
    module Instrumentation
      def process_action(*args)
        add_custom_fields_to_store
        LogStasher.clear_request_context
        LogStasher.add_default_fields_to_request_context(request)

        super(*args)
      end
      
      private

      # this method is called from within super of process_action.
      def append_info_to_payload(payload) #:nodoc:
        LogStasher.add_default_fields_to_payload(payload, request)
        if self.respond_to?(:logstasher_add_custom_fields_to_request_context)
          logstasher_add_custom_fields_to_request_context(LogStasher.request_context)
        end

        if self.respond_to?(:logtasher_add_custom_fields_to_payload)
          before_keys = payload.keys.clone
          logtasher_add_custom_fields_to_payload(payload)
          after_keys = payload.keys
          # Store all extra keys added to payload hash in payload itself. This is a thread safe way
          LogStasher.custom_fields += after_keys - before_keys
        end

        payload[:status] = response.status
        super(payload)

        LogStasher.store.each do |key, value|
          payload[key] = value
        end

        LogStasher.request_context.each do |key, value|
          payload[key] = value
        end
      end
      
      def add_custom_fields_to_store
        LogStasher.store[:ip] = request.remote_ip
        LogStasher.store[:route] = "#{request.params[:controller]}##{request.params[:action]}"
        LogStasher.request_context[:request_id] = request.env['action_dispatch.request_id']
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
logstasher-0.9.0 lib/logstasher/rails_ext/action_controller/base.rb
logstasher-0.8.6 lib/logstasher/rails_ext/action_controller/base.rb
logstasher-0.8.5 lib/logstasher/rails_ext/action_controller/base.rb
logstasher-0.8.2 lib/logstasher/rails_ext/action_controller/base.rb
logstasher-0.8.0 lib/logstasher/rails_ext/action_controller/base.rb