Sha256: 885b36ad2a0c7a110224103a124b239e2f775aebdd6598ba589aeed175e92b4c

Contents?: true

Size: 1.54 KB

Versions: 24

Compression:

Stored size: 1.54 KB

Contents

require 'net/http'
require 'honeybadger/plugin'
require 'honeybadger/instrumentation'
require 'resolv'

module Honeybadger
  module Plugins
    module Net
      module HTTP
        def request(request_data, body = nil, &block)
          return super unless started?
          return super if hb?

          Honeybadger.instrumentation.monotonic_timer { super }.tap do |duration, response_data|
            context = {
              duration: duration,
              method: request_data.method,
              status: response_data.code.to_i
            }.merge(parsed_uri_data(request_data))

            Honeybadger.event('request.net_http', context)
          end[1] # return the response data only
        end

        def hb?
          address.to_s[/#{Honeybadger.config[:'connection.host'].to_s}/]
        end

        def parsed_uri_data(request_data)
          uri = request_data.uri || build_uri(request_data)
          {}.tap do |uri_data|
            uri_data[:host] = uri.host
            uri_data[:url] = uri.to_s if Honeybadger.config[:'net_http.insights.full_url']
          end
        end

        def build_uri(request_data)
          hostname = (address[/#{Resolv::IPv6::Regex}/]) ? "[#{address}]" : address
          URI.parse("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{request_data.path}")
        end

        Plugin.register :net_http do
          requirement { config.load_plugin_insights?(:net_http) }

          execution do
            ::Net::HTTP.send(:prepend, Honeybadger::Plugins::Net::HTTP)
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
honeybadger-5.19.2 lib/honeybadger/plugins/net_http.rb
honeybadger-5.19.1 lib/honeybadger/plugins/net_http.rb
honeybadger-5.19.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.18.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.17.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.16.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.6 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.5 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.4 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.3 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.2 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.1 lib/honeybadger/plugins/net_http.rb
honeybadger-5.15.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.14.2 lib/honeybadger/plugins/net_http.rb
honeybadger-5.14.1 lib/honeybadger/plugins/net_http.rb
honeybadger-5.14.0 lib/honeybadger/plugins/net_http.rb
honeybadger-5.13.3 lib/honeybadger/plugins/net_http.rb
honeybadger-5.13.2 lib/honeybadger/plugins/net_http.rb
honeybadger-5.13.1 lib/honeybadger/plugins/net_http.rb
honeybadger-5.13.0 lib/honeybadger/plugins/net_http.rb