Module: Gitlab::Instrumentation::ElasticsearchTransportInterceptor

Included in:
Elasticsearch::Transport::Client
Defined in:
lib/gitlab/instrumentation/elasticsearch_transport.rb

Instance Method Summary collapse

Instance Method Details

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


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/instrumentation/elasticsearch_transport.rb', line 8

def perform_request(method, path, params = {}, body = nil, headers = nil)
  start = Time.now
  headers = (headers || {})
    .reverse_merge({ 'X-Opaque-Id': Labkit::Correlation::CorrelationId.current_or_new_id })
  response = super
ensure
  if ::Gitlab::SafeRequestStore.active?
    duration = (Time.now - start)

    ::Gitlab::Instrumentation::ElasticsearchTransport.increment_request_count

    if response&.body && response.body.is_a?(Hash) && response.body['timed_out']
      ::Gitlab::Instrumentation::ElasticsearchTransport.increment_timed_out_count
    end

    ::Gitlab::Instrumentation::ElasticsearchTransport.add_duration(duration)
    ::Gitlab::Instrumentation::ElasticsearchTransport.add_call_details(duration, method, path, params, body)
  end
end