Module: AppPerfRpm::Instruments::FaradayConnection

Defined in:
lib/app_perf_rpm/instruments/faraday.rb

Instance Method Summary collapse

Instance Method Details

#run_request_with_trace(method, url, body, headers, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/app_perf_rpm/instruments/faraday.rb', line 6

def run_request_with_trace(method, url, body, headers, &block)
  if ::AppPerfRpm::Tracer.tracing?
    span = ::AppPerfRpm.tracer.start_span("faraday", tags: {
      "component" => "Faraday",
      "span.kind" => "client"
    })
    AppPerfRpm.tracer.inject(span.context, OpenTracing::FORMAT_RACK, @headers)
    result = run_request_without_trace(method, url, body, headers, &block)
    span.set_tag "middleware", @builder.handlers
    span.set_tag "peer.hostname", @url_prefix.host
    span.set_tag "peer.port", @url_prefix.port
    span.set_tag "http.protocol", @url_prefix.scheme
    span.set_tag "http.url", url
    span.set_tag "http.method", method
    span.set_tag "http.status_code", result.status
    AppPerfRpm::Utils.log_source_and_backtrace(span, :faraday)
    span.finish
  else
    result = run_request_without_trace(method, url, body, headers, &block)
  end
  result
rescue Exception => e
  if span
    span.set_tag('error', true)
    span.log_error(e)
  end
  raise
ensure
  span.finish if span
end