class ElasticAPM::Spies::ElasticsearchSpy

@api private

Constants

NAME_FORMAT
TYPE

Public Instance Methods

install() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/elastic_apm/spies/elasticsearch.rb, line 11
def install
  ::Elasticsearch::Transport::Client.class_eval do
    alias perform_request_without_apm perform_request

    def perform_request(method, path, *args, &block)
      name = format(NAME_FORMAT, method, path)
      statement = args[0].is_a?(String) ? args[0] : args[0].to_json
      context = Span::Context.new(db: { statement: statement })

      ElasticAPM.with_span name, TYPE, context: context do
        perform_request_without_apm(method, path, *args, &block)
      end
    end
  end
end
perform_request(method, path, *args, &block) click to toggle source
# File lib/elastic_apm/spies/elasticsearch.rb, line 15
def perform_request(method, path, *args, &block)
  name = format(NAME_FORMAT, method, path)
  statement = args[0].is_a?(String) ? args[0] : args[0].to_json
  context = Span::Context.new(db: { statement: statement })

  ElasticAPM.with_span name, TYPE, context: context do
    perform_request_without_apm(method, path, *args, &block)
  end
end