module BaselineRedRpm::Instruments::TyphoeusRequest

Public Instance Methods

run_with_trace() click to toggle source
# File lib/baseline_red_rpm/instruments/typhoeus.rb, line 6
def run_with_trace
  if ::BaselineRedRpm::Tracer.tracing?
    span = ::BaselineRedRpm.tracer.start_span("typhoeus", tags: {
      "component" => "Typhoeus"
    })
    BaselineRedRpm.tracer.inject(span.context, OpenTracing::FORMAT_RACK, options[:headers])

    response = run_without_trace
    span.exit
    uri = URI(response.effective_url)

    span.set_tag "http.status_code", response.code
    span.set_tag "http.url", uri.to_s
    span.set_tag "http.method", options[:method]
    BaselineRedRpm::Utils.log_source_and_backtrace(span, :typhoeus)
  else
    response = run_without_trace
  end
  response
rescue Exception => e
  if span
    span.set_tag('error', true)
    span.log_error(e)
  end
  raise
ensure
  span.finish if span
end