Class: Appsignal::Hooks::NetHttpHook

Inherits:
Hook
  • Object
show all
Defined in:
lib/appsignal/hooks/net_http.rb

Instance Method Summary collapse

Methods inherited from Hook

#installed?, register, #try_to_install

Instance Method Details

#dependencies_present?Boolean

Returns:

  • (Boolean)

8
9
10
# File 'lib/appsignal/hooks/net_http.rb', line 8

def dependencies_present?
  Appsignal.config && Appsignal.config[:instrument_net_http]
end

#installObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/appsignal/hooks/net_http.rb', line 12

def install
  Net::HTTP.class_eval do
    alias request_without_appsignal request

    def request(request, body=nil, &block)
      ActiveSupport::Notifications.instrument(
        'request.net_http',
        :protocol => use_ssl? ? 'https' : 'http',
        :domain   => request['host'] || self.address,
        :path     => request.path,
        :method   => request.method
      ) do
        request_without_appsignal(request, body, &block)
      end
    end
  end
end