Sha256: 497493aa19fe52a9d76615a5c9114a268da5d31534e1c6f9b8952a9952acd889
Contents?: true
Size: 1.58 KB
Versions: 10
Compression:
Stored size: 1.58 KB
Contents
require 'skylight/formatters/http' module Skylight module Probes module NetHTTP # 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 Thread.current[DISABLED_KEY] = true yield ensure Thread.current[DISABLED_KEY] = false end def self.disabled? !!Thread.current[DISABLED_KEY] end def install Net::HTTP.class_eval do alias request_without_sk request def request(req, body = nil, &block) if !started? || Skylight::Probes::NetHTTP::Probe.disabled? return request_without_sk(req, body, &block) end 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 ||= self.address port ||= self.port 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) do request_without_sk(req, body, &block) end end end end end end register("Net::HTTP", "net/http", NetHTTP::Probe.new) end end
Version data entries
10 entries across 10 versions & 1 rubygems