Sha256: 81fd8290594c03f2b7cd969149a17e17eb0e5bc4731495033ddb0c0f45ecc36f

Contents?: true

Size: 1.38 KB

Versions: 20

Compression:

Stored size: 1.38 KB

Contents

require "skylight/formatters/http"

module Skylight
  module Probes
    module NetHTTP
      module Instrumentation
        def request(req, *)
          return super if !started? || Probes::NetHTTP::Probe.disabled?

          method = req.method

          # req['host'] also includes special handling for default ports
          host, port = req["host"] ? req["host"].split(":") : nil

          # If we're connected with a persistent socket
          host ||= address

          path = req.path
          scheme = use_ssl? ? "https" : "http"

          # Contained in the path
          query = nil

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

          Skylight.instrument(opts) { super }
        end
      end

      # Probe for instrumenting Net::HTTP requests. Works by monkeypatching the default Net::HTTP#request method.
      class Probe
        DISABLED_KEY = :__skylight_net_http_disabled

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

        def self.disabled?
          !!Thread.current[DISABLED_KEY]
        end

        def install
          Net::HTTP.prepend(Instrumentation)
        end
      end
    end

    register(:net_http, "Net::HTTP", "net/http", NetHTTP::Probe.new)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
skylight-6.1.0.beta lib/skylight/probes/net_http.rb
skylight-6.0.4 lib/skylight/probes/net_http.rb
skylight-6.0.3 lib/skylight/probes/net_http.rb
skylight-5.3.5 lib/skylight/probes/net_http.rb
skylight-6.0.2 lib/skylight/probes/net_http.rb
skylight-6.0.1 lib/skylight/probes/net_http.rb
skylight-6.0.0 lib/skylight/probes/net_http.rb
skylight-6.0.0.beta2 lib/skylight/probes/net_http.rb
skylight-6.0.0.beta lib/skylight/probes/net_http.rb
skylight-5.3.4 lib/skylight/probes/net_http.rb
skylight-5.3.3 lib/skylight/probes/net_http.rb
skylight-5.3.2 lib/skylight/probes/net_http.rb
skylight-5.3.1 lib/skylight/probes/net_http.rb
skylight-5.3.0 lib/skylight/probes/net_http.rb
skylight-5.2.0 lib/skylight/probes/net_http.rb
skylight-5.2.0.beta2 lib/skylight/probes/net_http.rb
skylight-5.2.0.beta lib/skylight/probes/net_http.rb
skylight-5.1.1 lib/skylight/probes/net_http.rb
skylight-5.1.0.beta3 lib/skylight/probes/net_http.rb
skylight-5.1.0.beta2 lib/skylight/probes/net_http.rb