module TraceView::Inst::EventMachine::HttpClient

Public Instance Methods

parse_response_header_with_traceview(*args, &block) click to toggle source
# File lib/traceview/inst/em-http-request.rb, line 34
def parse_response_header_with_traceview(*args, &block)
  report_kvs = {}
  xtrace = nil
  blacklisted = TraceView::API.blacklisted?(@uri)

  begin
    report_kvs[:HTTPStatus] = args[2]
    report_kvs[:Async] = 1
  rescue => e
    TraceView.logger.debug "[traceview/debug] em-http-request KV error: #{e.inspect}"
  end

  parse_response_header_without_traceview(*args, &block)

  unless blacklisted
    headers = args[0]
    context = TraceView::Context.toString
    task_id = TraceView::XTrace.task_id(context)

    if headers.is_a?(Hash) && headers.key?('X-Trace')
      xtrace = headers['X-Trace']
    end

    if TraceView::XTrace.valid?(xtrace) && TraceView.tracing?

      # Assure that we received back a valid X-Trace with the same task_id
      if task_id == TraceView::XTrace.task_id(xtrace)
        TraceView::Context.fromString(xtrace)
      else
        TraceView.logger.debug "Mismatched returned X-Trace ID : #{xtrace}"
      end
    end

  end

  ::TraceView::API.log_exit(:'em-http-request', report_kvs)
end