Sha256: 718886aa9c8b6cb39ad1626905393a17679b0b68c01d592515d4e9f8de2faccd

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

module Elasticsearch
  module Rails
    module Lograge

      # Rails initializer class to require Elasticsearch::Rails::Instrumentation files,
      # set up Elasticsearch::Model and add Lograge configuration to display Elasticsearch-related duration
      #
      # Require the component in your `application.rb` file and enable Lograge:
      #
      #     require 'elasticsearch/rails/lograge'
      #
      # You should see the full duration of the request to Elasticsearch as part of each log event:
      #
      #     method=GET path=/search ... status=200 duration=380.89 view=99.64 db=0.00 es=279.37
      #
      # @see https://github.com/roidrage/lograge
      #
      class Railtie < ::Rails::Railtie
        initializer "elasticsearch.lograge" do |app|
          require 'elasticsearch/rails/instrumentation/publishers'
          require 'elasticsearch/rails/instrumentation/log_subscriber'
          require 'elasticsearch/rails/instrumentation/controller_runtime'

          config.lograge.custom_options = lambda do |event|
            { es: event.payload[:elasticsearch_runtime].to_f.round(2) }
          end

          Elasticsearch::Model::Searching::SearchRequest.class_eval do
            include Elasticsearch::Rails::Instrumentation::Publishers::SearchRequest
          end

          ActiveSupport.on_load(:action_controller) do
            include Elasticsearch::Rails::Instrumentation::ControllerRuntime
          end
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
elasticsearch-rails-0.1.5 lib/elasticsearch/rails/lograge.rb
elasticsearch-rails-0.1.4 lib/elasticsearch/rails/lograge.rb
elasticsearch-rails-0.1.3 lib/elasticsearch/rails/lograge.rb
elasticsearch-rails-0.1.2 lib/elasticsearch/rails/lograge.rb
elasticsearch-rails-0.1.1 lib/elasticsearch/rails/lograge.rb
elasticsearch-rails-0.1.0 lib/elasticsearch/rails/lograge.rb