Module: Datadog::Contrib::Elasticsearch::TracedClient

Defined in:
lib/ddtrace/contrib/elasticsearch/core.rb

Overview

Datadog APM Elastic Search integration.

Instance Method Summary collapse

Instance Method Details

#initializeObject



20
21
22
23
24
# File 'lib/ddtrace/contrib/elasticsearch/core.rb', line 20

def initialize(*)
  pin = Datadog::Pin.new(SERVICE, app: 'elasticsearch', app_type: Datadog::Ext::AppTypes::DB)
  pin.onto(self)
  super
end

#perform_request(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ddtrace/contrib/elasticsearch/core.rb', line 26

def perform_request(*args)
  pin = Datadog::Pin.get_from(self)
  return super unless pin && pin.tracer

  method = args[0]
  path = args[1]
  params = args[2]
  body = args[3]
  full_url = URI.parse(path)

  url = full_url.path
  response = nil
  pin.tracer.trace('elasticsearch.query') do |span|
    span.service = pin.service
    span.span_type = SPAN_TYPE

    span.set_tag(METHOD, method)
    span.set_tag(URL, url)
    span.set_tag(PARAMS, JSON.generate(params)) if params
    span.set_tag(BODY, JSON.generate(body)) if body

    quantized_url = Datadog::Contrib::Elasticsearch::Quantize.format_url(url)
    span.resource = "#{method} #{quantized_url}"

    response = super(*args)
  end

  response
end