Module: Oboe::Inst::EventMachine::HttpClient

Included in:
EventMachine::HttpClient
Defined in:
lib/oboe/inst/em-http-request.rb

Instance Method Summary collapse

Instance Method Details

#parse_response_header_with_oboe(*args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oboe/inst/em-http-request.rb', line 31

def parse_response_header_with_oboe(*args, &block)
  report_kvs = {}
  xtrace = nil
  blacklisted = Oboe::API.blacklisted?(@uri)

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

  parse_response_header_without_oboe(*args, &block)

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

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

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

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

  end

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