Sha256: 3e0708af6cf78edecaddceacb7be1eda785bf5104312e48e95bdb9f8df74a23b

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

module RorVsWild
  module Plugin
    class NetHttp
      HTTP = "http".freeze
      HTTPS = "https".freeze

      def self.setup
        return if !defined?(Net::HTTP)
        return if Net::HTTP.method_defined?(:request_without_rorvswild)

        Net::HTTP.class_eval do
          alias_method :request_without_rorvswild, :request

          def request(req, body = nil, &block)
            return request_without_rorvswild(req, body, &block) if request_called_twice?
            scheme = use_ssl? ? HTTPS : HTTP
            url = "#{req.method} #{scheme}://#{address}#{req.path}"
            RorVsWild.agent.measure_section(url, kind: HTTP) do
              request_without_rorvswild(req, body, &block)
            end
          end

          def request_called_twice?
            # Net::HTTP#request calls itself when connection is not started.
            # This condition prevents from counting twice the request.
            (current_section = RorVsWild::Section.current) && current_section.kind == HTTP
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rorvswild-1.1.1 lib/rorvswild/plugin/net_http.rb
rorvswild-1.1.0 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.1 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0.pre.alpha8 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0.pre.alpha7 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0.pre.alpha6 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0.pre.alpha5 lib/rorvswild/plugin/net_http.rb
rorvswild-1.0.0.pre.alpha4 lib/rorvswild/plugin/net_http.rb