Class: Skylight::Core::Probes::HTTPClient::Probe Private

Inherits:
Object
  • Object
show all
Defined in:
lib/skylight/core/probes/httpclient.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

DISABLED_KEY =

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.

:__skylight_httpclient_disabled

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disableObject

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.


9
10
11
12
13
14
# File 'lib/skylight/core/probes/httpclient.rb', line 9

def self.disable
  Thread.current[DISABLED_KEY] = true
  yield
ensure
  Thread.current[DISABLED_KEY] = false
end

.disabled?Boolean

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.

Returns:

  • (Boolean)

16
17
18
# File 'lib/skylight/core/probes/httpclient.rb', line 16

def self.disabled?
  !!Thread.current[DISABLED_KEY]
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.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/skylight/core/probes/httpclient.rb', line 20

def install
  ::HTTPClient.class_eval do
    # HTTPClient has request methods on the class object itself,
    # but the internally instantiate a client and perform the method
    # on that, so this instance method override will cover both
    # `HTTPClient.get(...)` and `HTTPClient.new.get(...)`

    alias_method :do_request_without_sk, :do_request
    def do_request(method, uri, query, body, header, &block)
      if Probes::HTTPClient::Probe.disabled?
        return do_request_without_sk(method, uri, query, body, header, &block)
      end

      opts = Formatters::HTTP.build_opts(method, uri.scheme, uri.host, uri.port, uri.path, uri.query)

      Skylight::Core::Fanout.instrument(opts) do
        do_request_without_sk(method, uri, query, body, header, &block)
      end
    end
  end
end