class Curl::Multi

Public Instance Methods

add(curl)
Also aliased as: add_without_oneapm
Alias for: add_with_oneapm
add_with_oneapm(curl) click to toggle source

Add CAT with callbacks if the request is serial

# File lib/one_apm/inst/http_clients/curb.rb, line 96
def add_with_oneapm(curl)
  if curl.respond_to?(:_oa_serial) && curl._oa_serial
    hook_pending_request(curl) if OneApm::Manager.tl_is_execution_traced?
  end

  return add_without_oneapm( curl )
end
Also aliased as: add
add_without_oneapm(curl)
Alias for: add
hook_pending_request(request) click to toggle source

Instrument the specified request (a Curl::Easy object) and set up cross-application tracing if it's enabled.

# File lib/one_apm/inst/http_clients/curb.rb, line 126
def hook_pending_request(request)
  wrapped_request, wrapped_response = wrap_request(request)
  state   = OneApm::TransactionState.tl_get
  t0      = Time.now
  segment = OneApm::Agent::CrossAppTracing.start_trace(state, t0, wrapped_request)

  unless request._oa_instrumented
    install_header_callback(request, wrapped_response)
    install_completion_callback(request, t0, segment, wrapped_request, wrapped_response)
    request._oa_instrumented = true
  end
rescue => err
  OneApm::Manager.logger.error("Untrapped exception", err)
end
install_completion_callback(request, t0, segment, wrapped_request, wrapped_response) click to toggle source

Install a callback that will finish the trace.

# File lib/one_apm/inst/http_clients/curb.rb, line 167
def install_completion_callback(request, t0, segment, wrapped_request, wrapped_response)
  original_callback = request.on_complete
  request._oa_original_on_complete = original_callback
  request.on_complete do |finished_request|
    begin
      state = OneApm::TransactionState.tl_get
      OneApm::Agent::CrossAppTracing.finish_trace(state, t0, segment, wrapped_request, wrapped_response)
    ensure
      # Make sure the existing completion callback is run, and restore the
      # on_complete callback to how it was before.
      original_callback.call(finished_request) if original_callback
      remove_instrumentation_callbacks(request)
    end
  end
end
install_header_callback( request, wrapped_response ) click to toggle source

Install a callback that will record the response headers to enable CAT linking

# File lib/one_apm/inst/http_clients/curb.rb, line 151
def install_header_callback( request, wrapped_response )
  original_callback = request.on_header
  request._oa_original_on_header = original_callback
  request._oa_header_str = ''
  request.on_header do |header_data|
    wrapped_response.append_header_data( header_data )

    if original_callback
      original_callback.call( header_data )
    else
      header_data.length
    end
  end
end
perform(&blk)
Also aliased as: perform_without_oneapm
Alias for: perform_with_oneapm
perform_with_oneapm(&blk) click to toggle source

Trace as an External/Multiple call if the first request isn't serial.

# File lib/one_apm/inst/http_clients/curb.rb, line 109
def perform_with_oneapm(&blk)
  return perform_without_oneapm if
    self.requests.first &&
    self.requests.first.respond_to?(:_oa_serial) &&
    self.requests.first._oa_serial

  trace_execution_scoped("External/Multiple/Curb::Multi/perform") do
    perform_without_oneapm(&blk)
  end
end
Also aliased as: perform
perform_without_oneapm(&blk)
Alias for: perform
remove_instrumentation_callbacks(request) click to toggle source
# File lib/one_apm/inst/http_clients/curb.rb, line 183
def remove_instrumentation_callbacks(request)
  request.on_complete(&request._oa_original_on_complete)
  request.on_header(&request._oa_original_on_header)
  request._oa_instrumented = false
end
wrap_request(request) click to toggle source

Create request and response adapter objects for the specified request

# File lib/one_apm/inst/http_clients/curb.rb, line 143
def wrap_request(request)
  return OneApm::Support::HTTPClients::CurbRequest.new(request),
         OneApm::Support::HTTPClients::CurbResponse.new(request)
end