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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.aliasedObject

Returns the value of attribute aliased.



21
22
23
# File 'lib/http_instrumentation/instrumentation/net_http_hook.rb', line 21

def aliased
  @aliased
end

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, :request) if defined?(::Net::HTTP)
end

Instance Method Details

#request(req, *args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/http_instrumentation/instrumentation/net_http_hook.rb', line 24

def request(req, *args, &block)
  unless started?
    if HTTPInstrumentation::Instrumentation::NetHTTPHook.aliased
      return request_without_http_instrumentation(req, *args, &block)
    else
      return super
    end
  end

  HTTPInstrumentation.instrument("net/http") do |payload|
    response = if HTTPInstrumentation::Instrumentation::NetHTTPHook.aliased
      request_without_http_instrumentation(req, *args, &block)
    else
      super
    end

    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