Module: HTTPInstrumentation::Instrumentation::NetHTTPHook

Defined in:
lib/http_instrumentation/instrumentation/net_http_hook.rb

Overview

This module is responsible for instrumenting the net/http module in the standard library.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.installed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/http_instrumentation/instrumentation/net_http_hook.rb', line 17

def installed?
  !!(defined?(::Net::HTTP) && ::Net::HTTP.include?(self))
end

.instrument!Object



13
14
15
# File 'lib/http_instrumentation/instrumentation/net_http_hook.rb', line 13

def instrument!
  Instrumentation.instrument!(::Net::HTTP, self) if defined?(::Net::HTTP)
end

Instance Method Details

#request(req) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/http_instrumentation/instrumentation/net_http_hook.rb', line 22

def request(req, *)
  return super unless started?

  HTTPInstrumentation.instrument("net/http") do |payload|
    response = super

    default_port = (use_ssl? ? 443 : 80)
    scheme = (use_ssl? ? "https" : "http")
    url = "#{scheme}://#{address}#{":#{port}" unless port == default_port}#{req.path}"
    payload[:http_method] = req.method
    payload[:url] = url
    payload[:status_code] = response.code

    response
  end
end