<commit_before>module Yell
  module Adapters
    module Logstash
      # Filter class to be used with Rails ActionController
      # Use as a before_action to enable collection of more/custom data fields
      class ControllerFilters
        # Filter entry point (for before_action)
        # @param controller[ActionController::Base]
        def self.before(controller)
          if controller.respond_to?(:yell_adapter_logstash_fields)
            Thread.current[:yell_adapter_logstash_fields] = controller.send(:yell_adapter_logstash_fields, controller)
          else
            Thread.current[:yell_adapter_logstash_fields] = self.yell_adapter_logstash_fields(controller)
          end

          if controller.respond_to?(:yell_adapter_logstash_tags)
            Thread.current[:yell_adapter_logstash_tags] = controller.send(:yell_adapter_logstash_tags, controller)
          else
            Thread.current[:yell_adapter_logstash_tags] = self.yell_adapter_logstash_tags(controller)
          end
        end

        private
        # Default hash of fields to be collected
        # @param controller[ActionController::Base]
        # @return [Hash<String,String>]
        def self.yell_adapter_logstash_fields(controller)
          {
              'controller' => controller.class.name,
              'action' => controller.action_name,
              'params' => controller.request.filtered_parameters,
              'ip' => controller.request.remote_ip,
              'format' => controller.request.format.try(:ref),
              'method' => controller.request.method,
              'path' => (controller.request.fullpath rescue "unknown")
          }
        end
        # Default hash of tags to be collected
        # @param controller[ActionController::Base]
        # @return [Hash<String,String>]
        def self.yell_adapter_logstash_tags(controller)
          {
              'request_uuid' => controller.request.uuid
          }<commit_msg>add request ip<commit_after>module Yell
  module Adapters
    module Logstash
      # Filter class to be used with Rails ActionController
      # Use as a before_action to enable collection of more/custom data fields
      class ControllerFilters
        # Filter entry point (for before_action)
        # @param controller[ActionController::Base]
        def self.before(controller)
          if controller.respond_to?(:yell_adapter_logstash_fields)
            Thread.current[:yell_adapter_logstash_fields] = controller.send(:yell_adapter_logstash_fields, controller)
          else
            Thread.current[:yell_adapter_logstash_fields] = self.yell_adapter_logstash_fields(controller)
          end

          if controller.respond_to?(:yell_adapter_logstash_tags)
            Thread.current[:yell_adapter_logstash_tags] = controller.send(:yell_adapter_logstash_tags, controller)
          else
            Thread.current[:yell_adapter_logstash_tags] = self.yell_adapter_logstash_tags(controller)
          end
        end

        private
        # Default hash of fields to be collected
        # @param controller[ActionController::Base]
        # @return [Hash<String,String>]
        def self.yell_adapter_logstash_fields(controller)
          {
              'controller' => controller.class.name,
              'action' => controller.action_name,
              'params' => controller.request.filtered_parameters,
              'ip' => controller.request.ip,
              'remote_ip' => controller.request.remote_ip,
              'format' => controller.request.format.try(:ref),
              'method' => controller.request.method,
              'path' => (controller.request.fullpath rescue "unknown")
          }
        end
        # Default hash of tags to be collected
        # @param controller[ActionController::Base]
        # @return [Hash<String,String>]
        def self.yell_adapter_logstash_tags(controller)
          {
              'request_uuid' => controller.request.uuid
          }
{'fraction_non_alphanumeric': 0.08373145587125974, 'fraction_numerical': 0.0, 'mean_word_length': 2.520353982300885, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5165', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1048, 'n_words': 206}