def self.trace(request)
state = NewRelic::Agent::TransactionState.tl_get
if state.is_execution_traced? && !request_is_hydra_enabled?(request)
wrapped_request = ::NewRelic::Agent::HTTPClients::TyphoeusHTTPRequest.new(request)
segment = NewRelic::Agent::Transaction.start_external_request_segment(
wrapped_request.type, wrapped_request.uri, wrapped_request.method)
segment.add_request_headers wrapped_request
callback = Proc.new do
wrapped_response = ::NewRelic::Agent::HTTPClients::TyphoeusHTTPResponse.new(request.response)
segment.read_response_headers wrapped_response
segment.finish
end
request.on_complete.unshift(callback)
end
rescue => e
NewRelic::Agent.logger.error("Exception during trace setup for Typhoeus request", e)
end