Sha256: a9c185c9c59df3b62cfb03a0d6f5b3c9787e4b7f39444146a56b6de99d20dfa9
Contents?: true
Size: 1.57 KB
Versions: 29
Compression:
Stored size: 1.57 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) if Thread.current[:rorvswild_ignore_net_http] request_without_rorvswild(req, body, &block) else request_with_rorvswild(req, body, &block) end end def request_with_rorvswild(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 def self.ignore(&block) old_value = Thread.current[:rorvswild_ignore_net_http] Thread.current[:rorvswild_ignore_net_http] = true block.call ensure Thread.current[:rorvswild_ignore_net_http] = old_value end end end end
Version data entries
29 entries across 29 versions & 1 rubygems