Sha256: 02bdcd05ed204fd7bcfd4203773dea44b7f7c1e17b044e636c366f331059544c

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Honeybadger
  module Integrations
    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.match(%r{https?://}) ? URI(request.path) : URI("http#{use_ssl? ? 's' : ''}://#{address}:#{port}#{request.path}")

          if uri.host.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
    end
  end

  Dependency.register do
    requirement { defined?(::ActiveSupport::Notifications) }
    requirement { defined?(::Net::HTTP) }
    requirement { Honeybadger.configuration.traces? }

    injection { ::Net::HTTP.send(:include, Integrations::NetHttp::Instrumentation) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
honeybadger-1.15.3 lib/honeybadger/integrations/net_http.rb
honeybadger-1.15.2 lib/honeybadger/integrations/net_http.rb
honeybadger-1.15.1 lib/honeybadger/integrations/net_http.rb
honeybadger-1.15.0 lib/honeybadger/integrations/net_http.rb