Sha256: 26941e86a6024fa92114b0d30936c6e87c9df687e932832d5cba05cc523d7141

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 KB

Contents

require 'honeybadger/plugin'

module Honeybadger
  module Plugins
    module NetHttp
      module Instrumentation
        def self.included(base)
          base.send(:alias_method, :request_without_honeybadger, :request)
          base.send(:alias_method, :request, :request_with_honeybadger)
        end

        def request_with_honeybadger(*args, &block)
          request = args[0]
          uri = request.path.to_s.match(%r{https?://}) ? URI(request.path) : URI("http#{use_ssl? ? 's' : ''}://#{address}:#{port}#{request.path}")

          if uri.host.to_s.match("honeybadger.io")
            return request_without_honeybadger(*args, &block)
          end

          ActiveSupport::Notifications.instrument("net_http.request", { :uri => uri, :method => request.method }) do
            request_without_honeybadger(*args, &block)
          end
        end
      end

      Plugin.register do
        requirement { defined?(::ActiveSupport::Notifications) }
        requirement { defined?(::Net::HTTP) }
        requirement { config[:'traces.enabled'] }

        execution { ::Net::HTTP.send(:include, Instrumentation) }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
honeybadger-2.0.12 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.11 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.10 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.9 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.8 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.6 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.5 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.4 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.3 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.2 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.13 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.12 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.11 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.10 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.9 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.8 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.7 lib/honeybadger/plugins/net_http.rb
honeybadger-2.0.0.beta.6 lib/honeybadger/plugins/net_http.rb