class Curl::Multi

Public Instance Methods

add(curl)
Also aliased as: add_without_tingyun
Alias for: add_with_tingyun
add_with_tingyun(curl) click to toggle source

Add CAT with callbacks if the request is serial

# File lib/ting_yun/instrumentation/curb.rb, line 93
def add_with_tingyun(curl) #THREAD_LOCAL_ACCESS
  if curl.respond_to?(:_ty_serial) && curl._ty_serial
    hook_pending_request(curl) if TingYun::Agent.tl_is_execution_traced?
  end

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

  unless request._ty_instrumented
    install_header_callback( request, wrapped_response )
    install_completion_callback( request, t0, node, wrapped_request, wrapped_response )
    request._ty_instrumented = true
  end
rescue => err
  TingYun::Agent.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/ting_yun/instrumentation/curb.rb, line 165
def install_completion_callback( request, t0, segment, wrapped_request, wrapped_response )
  original_callback = request.on_complete
  request._ty_original_on_complete = original_callback
  request.on_complete do |finished_request|
    begin
      TingYun::Agent::CrossAppTracing.finish_trace(TingYun::Agent::TransactionState.tl_get,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/ting_yun/instrumentation/curb.rb, line 149
def install_header_callback( request, wrapped_response )
  original_callback = request.on_header
  request._ty_original_on_header = original_callback
  request._ty_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_tingyun
perform_with_tingyun(&blk) click to toggle source

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

# File lib/ting_yun/instrumentation/curb.rb, line 106
def perform_with_tingyun(&blk)
  return perform_without_tingyun if
      self.requests.first &&
          self.requests.first.respond_to?(:_ty_serial) &&
          self.requests.first._ty_serial

  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("External/Multiple/Curb::Multi/perform") do
    perform_without_tingyun(&blk)
  end
end
Also aliased as: perform
perform_without_tingyun(&blk)
Alias for: perform
remove_instrumentation_callbacks( request ) click to toggle source
# File lib/ting_yun/instrumentation/curb.rb, line 180
def remove_instrumentation_callbacks( request )
  request.on_complete(&request._ty_original_on_complete)
  request.on_header(&request._ty_original_on_header)
  request._ty_instrumented = false
end
wrap_request(request) click to toggle source

Create request and response adapter objects for the specified request

# File lib/ting_yun/instrumentation/curb.rb, line 140
def wrap_request(request)
  return TingYun::Http::CurbRequest.new(request),
      TingYun::Http::CurbResponse.new(request)
end