class Curl::Multi

Public Instance Methods

add(curl)
Also aliased as: add_without_newrelic
Alias for: add_with_newrelic
add_with_newrelic(curl) click to toggle source

Add CAT with callbacks if the request is serial

# File lib/new_relic/agent/instrumentation/curb.rb, line 94
def add_with_newrelic(curl) #THREAD_LOCAL_ACCESS
  if curl.respond_to?(:_nr_serial) && curl._nr_serial
    hook_pending_request(curl) if NewRelic::Agent.tl_is_execution_traced?
  end

  return add_without_newrelic( curl )
end
Also aliased as: add
add_without_newrelic(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/new_relic/agent/instrumentation/curb.rb, line 124
def hook_pending_request(request) #THREAD_LOCAL_ACCESS
  wrapped_request, wrapped_response = wrap_request(request)
  state = NewRelic::Agent::TransactionState.tl_get
  t0    = Time.now
  node  = NewRelic::Agent::CrossAppTracing.start_trace(state, t0, wrapped_request)

  unless request._nr_instrumented
    install_header_callback(request, wrapped_response)
    install_completion_callback(request, t0, node, wrapped_request, wrapped_response)
    request._nr_instrumented = true
  end
rescue => err
  NewRelic::Agent.logger.error("Untrapped exception", err)
end
install_completion_callback(request, t0, node, wrapped_request, wrapped_response) click to toggle source

Install a callback that will finish the trace.

# File lib/new_relic/agent/instrumentation/curb.rb, line 165
def install_completion_callback(request, t0, node, wrapped_request, wrapped_response) #THREAD_LOCAL_ACCESS
  original_callback = request.on_complete
  request._nr_original_on_complete = original_callback
  request.on_complete do |finished_request|
    begin
      state = NewRelic::Agent::TransactionState.tl_get
      NewRelic::Agent::CrossAppTracing.finish_trace(state, t0, node, 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/new_relic/agent/instrumentation/curb.rb, line 149
def install_header_callback( request, wrapped_response )
  original_callback = request.on_header
  request._nr_original_on_header = original_callback
  request._nr_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_newrelic
perform_with_newrelic(&blk) click to toggle source

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

# File lib/new_relic/agent/instrumentation/curb.rb, line 107
def perform_with_newrelic(&blk)
  return perform_without_newrelic if
    self.requests.first &&
    self.requests.first.respond_to?(:_nr_serial) &&
    self.requests.first._nr_serial

  trace_execution_scoped("External/Multiple/Curb::Multi/perform") do
    perform_without_newrelic(&blk)
  end
end
Also aliased as: perform
perform_without_newrelic(&blk)
Alias for: perform
remove_instrumentation_callbacks(request) click to toggle source
# File lib/new_relic/agent/instrumentation/curb.rb, line 181
def remove_instrumentation_callbacks(request)
  request.on_complete(&request._nr_original_on_complete)
  request.on_header(&request._nr_original_on_header)
  request._nr_instrumented = false
end
wrap_request(request) click to toggle source

Create request and response adapter objects for the specified request

# File lib/new_relic/agent/instrumentation/curb.rb, line 141
def wrap_request(request)
  return NewRelic::Agent::HTTPClients::CurbRequest.new(request),
         NewRelic::Agent::HTTPClients::CurbResponse.new(request)
end