Class: Elasticsearch::Tracer::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/tracer/transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracer: OpenTracing.global_tracer, active_span: nil, transport:) ⇒ Transport

Returns a new instance of Transport.



6
7
8
9
10
# File 'lib/elasticsearch/tracer/transport.rb', line 6

def initialize(tracer: OpenTracing.global_tracer, active_span: nil, transport:)
  @tracer = tracer
  @active_span = active_span
  @wrapped = transport
end

Instance Attribute Details

#active_spanObject (readonly)

Returns the value of attribute active_span.



4
5
6
# File 'lib/elasticsearch/tracer/transport.rb', line 4

def active_span
  @active_span
end

#tracerObject (readonly)

Returns the value of attribute tracer.



4
5
6
# File 'lib/elasticsearch/tracer/transport.rb', line 4

def tracer
  @tracer
end

#wrappedObject (readonly)

Returns the value of attribute wrapped.



4
5
6
# File 'lib/elasticsearch/tracer/transport.rb', line 4

def wrapped
  @wrapped
end

Instance Method Details

#perform_request(method, path, params = {}, body = nil, headers = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/elasticsearch/tracer/transport.rb', line 12

def perform_request(method, path, params={}, body=nil, headers=nil)
  tags = {
    'component' => 'elasticsearch-ruby',
    'span.kind' => 'client',
    'http.method' => method,
    'http.url' => path,
    'db.type' => 'elasticsearch',
    'elasticsearch.params' => URI.encode_www_form(params)
  }

  tags['db.statement'] = MultiJson.dump(body) unless Thread.current[self.object_id.to_s]

  span = tracer.start_span(method,
                           child_of: active_span.respond_to?(:call) ? active_span.call : active_span,
                           tags: tags)

  response = @wrapped.perform_request(method, path, params, body, headers)
  span.set_tag('http.status_code', response.status)

  response
rescue Exception => e
  if span
    span.record_exception(e)
  end
  raise
ensure
  span.finish if span
end