Sha256: 8dfb1c1e378d9b9c53a15d50dc828fb7438ab64256a8f85760a0f3a2be28b316
Contents?: true
Size: 1.2 KB
Versions: 28
Compression:
Stored size: 1.2 KB
Contents
require "skylight/formatters/http" module Skylight module Probes module HTTPClient module Instrumentation # HTTPClient has request methods on the class object itself, # but they internally instantiate a client and perform the method # on that, so this instance method override will cover both # `HTTPClient.get(...)` and `HTTPClient.new.get(...)` def do_request(method, uri, *) return super if Probes::HTTPClient::Probe.disabled? opts = Formatters::HTTP.build_opts(method, uri.scheme, uri.host, uri.port, uri.path, uri.query) Skylight.instrument(opts) { super } end end class Probe DISABLED_KEY = :__skylight_httpclient_disabled def self.disable old_value = Thread.current[DISABLED_KEY] Thread.current[DISABLED_KEY] = true yield ensure Thread.current[DISABLED_KEY] = old_value end def self.disabled? !!Thread.current[DISABLED_KEY] end def install ::HTTPClient.prepend(Instrumentation) end end end register(:httpclient, "HTTPClient", "httpclient", HTTPClient::Probe.new) end end
Version data entries
28 entries across 28 versions & 1 rubygems