Class: Hoss::Spies::HTTPSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hoss/spies/http.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'ext'
SUBTYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'http_rb'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.copy_request_body(body) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
# File 'lib/hoss/spies/http.rb', line 28

def self.copy_request_body(body)
  case body.source
  when String
    body.source
  when nil
    nil
  else
    ""
  end
end

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hoss/spies/http.rb', line 39

def install
  ::HTTP::Client.class_eval do
    alias perform_without_apm perform

    def perform(req, options)
      if req.headers['HOSS-SKIP-INSTRUMENTATION'] == 'true'
        return perform_without_apm(req, options)
      end

      Hoss.with_event do |event|
        result = nil
        begin
          event.request.headers['host'] = req.uri.host
          req.headers.each {|n,v| event.request.headers[n] = v}
          event.request.method = req.verb.to_s.upcase
          event.request.url = req.uri.to_s
          event.request.body = Hoss::Spies::HTTPSpy::copy_request_body(req.body)
          event.request.received_at = DateTime.now.strftime('%Q').to_i
            result = perform_without_apm(req, options)
            if result
              event.response = Hoss::Event::Response.new
              event.response.received_at = DateTime.now.strftime('%Q').to_i
              event.response.status_code = result.code.to_i
              result.headers.each {|n,v| event.response.headers[n] = v}
              event.response.body = result.body.to_s
            end
            result
          end
        rescue HTTP::TimeoutError => e
          event.error = Hoss::Event::Error.new(Hoss::Event::Error::ConnectionTimeout)
          event.error.received_at = DateTime.now.strftime('%Q').to_i
          raise
        rescue HTTP::Error => e
          event.error = Hoss::Event::Error.new(Hoss::Event::Error::ConnectionError)
          event.error.received_at = DateTime.now.strftime('%Q').to_i
          raise
        rescue Exception => e
          return result unless result.nil?
          return perform_without_apm(req, options)
      end
    end
  end
end