Sha256: 8aee66ae08ba02058515530ad415035490132383dfda33bf85cba394f03f9fb4

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

require 'honeybadger/plugin'
require 'honeybadger/trace'

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
            # Disable tracing during #request so that additional calls (i.e.
            # when connection wasn't started) don't result in double counting.
            Trace.ignore_events { 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

23 entries across 23 versions & 2 rubygems

Version Path
honeybadger-2.6.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.6.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.5.3 lib/honeybadger/plugins/net_http.rb
honeybadger-2.5.2 lib/honeybadger/plugins/net_http.rb
honeybadger-2.5.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.5.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.4.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.4.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.3.3 lib/honeybadger/plugins/net_http.rb
honeybadger-2.3.2 lib/honeybadger/plugins/net_http.rb
honeybadger-2.3.2.beta.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.3.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.3.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.2.0 lib/honeybadger/plugins/net_http.rb
honeybadger-2.2.0.beta.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.1.6.beta.1 lib/honeybadger/plugins/net_http.rb
honeybadger-2.1.5 lib/honeybadger/plugins/net_http.rb
honeybadger-2.1.4 lib/honeybadger/plugins/net_http.rb
honeybadger-2.1.3 lib/honeybadger/plugins/net_http.rb
honeybadger-2.1.1 lib/honeybadger/plugins/net_http.rb