module SignalFx::Tracing::Instrumenter::Elasticsearch

Attributes

instrumented[R]

Public Class Methods

instrument(opts = {}) click to toggle source
# File lib/signalfx/tracing/instrumentation/elasticsearch.rb, line 12
def instrument(opts = {})
  return if @instrumented

  begin
    require 'elasticsearch'
  rescue LoadError
    return
  end

  begin
    require 'elasticsearch-tracer'
  rescue LoadError => e
    puts e.message
    return
  end

  patch_new if opts.fetch(:auto_instrument, false)

  # prevent re-instrumenting
  @instrumented = true
end
new(arguments = {}, &block) click to toggle source
# File lib/signalfx/tracing/instrumentation/elasticsearch.rb, line 38
def new(arguments = {}, &block)
  # create a new TracingClient, which is almost identical to the
  # default client, and add the tracing transport afterwards. This
  # allows us to maintain the original transport if the user has
  # specified a non-default transport
  client = ::Elasticsearch::Tracer::TracingClient.new(arguments, &block)
  client.transport = ::Elasticsearch::Tracer::Transport.new(tracer: OpenTracing.global_tracer,
                                                            active_span: -> { OpenTracing.global_tracer.active_span },
                                                            transport: client.transport)

  return client
end
patch_new() click to toggle source
# File lib/signalfx/tracing/instrumentation/elasticsearch.rb, line 34
def patch_new
  ::Elasticsearch::Client.module_eval do
    alias_method :new_original, :new

    def new(arguments = {}, &block)
      # create a new TracingClient, which is almost identical to the
      # default client, and add the tracing transport afterwards. This
      # allows us to maintain the original transport if the user has
      # specified a non-default transport
      client = ::Elasticsearch::Tracer::TracingClient.new(arguments, &block)
      client.transport = ::Elasticsearch::Tracer::Transport.new(tracer: OpenTracing.global_tracer,
                                                                active_span: -> { OpenTracing.global_tracer.active_span },
                                                                transport: client.transport)

      return client
    end
  end
end