class Opbeat::Injections::NetHTTP::Injector

Public Instance Methods

install() click to toggle source
# File lib/opbeat/injections/net_http.rb, line 5
def install
  Net::HTTP.class_eval do
    alias request_without_opb request

    def request req, body = nil, &block
      unless Opbeat.started?
        return request_without_opb req, body, &block
      end

      host, port = req['host'] && req['host'].split(':')
      method = req.method
      path = req.path
      scheme = use_ssl? ? 'https' : 'http'

      # inside a session
      host ||= self.address
      port ||= self.port

      extra = {
        scheme: scheme,
        port: port,
        path: path
      }

      signature = "#{method} #{host}".freeze
      kind = "ext.net_http.#{method}".freeze

      Opbeat.trace signature, kind, extra do
        request_without_opb(req, body, &block)
      end
    end
  end
end
request(req, body = nil, &block) click to toggle source
# File lib/opbeat/injections/net_http.rb, line 9
def request req, body = nil, &block
  unless Opbeat.started?
    return request_without_opb req, body, &block
  end

  host, port = req['host'] && req['host'].split(':')
  method = req.method
  path = req.path
  scheme = use_ssl? ? 'https' : 'http'

  # inside a session
  host ||= self.address
  port ||= self.port

  extra = {
    scheme: scheme,
    port: port,
    path: path
  }

  signature = "#{method} #{host}".freeze
  kind = "ext.net_http.#{method}".freeze

  Opbeat.trace signature, kind, extra do
    request_without_opb(req, body, &block)
  end
end