Sha256: c3c56aebeed633d1d9b8e6c37a2da41f9f99bca4326deefde3cc19976c2f12f9

Contents?: true

Size: 973 Bytes

Versions: 6

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

require "net/http"

module Appsignal
  class Hooks
    # @api private
    class NetHttpHook < Appsignal::Hooks::Hook
      register :net_http

      def dependencies_present?
        Appsignal.config && Appsignal.config[:instrument_net_http]
      end

      def install
        if Appsignal::System.ruby_2_or_up?
          require "appsignal/integrations/net_http"
          Net::HTTP.send(:prepend, Appsignal::Integrations::NetHttpIntegration)
        else
          Net::HTTP.class_eval do
            alias request_without_appsignal request

            def request(request, body = nil, &block)
              Appsignal.instrument(
                "request.net_http",
                "#{request.method} #{use_ssl? ? "https" : "http"}://#{request["host"] || address}"
              ) do
                request_without_appsignal(request, body, &block)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
appsignal-2.10.6-java lib/appsignal/hooks/net_http.rb
appsignal-2.10.6 lib/appsignal/hooks/net_http.rb
appsignal-2.10.6.beta.1-java lib/appsignal/hooks/net_http.rb
appsignal-2.10.6.beta.1 lib/appsignal/hooks/net_http.rb
appsignal-2.10.5-java lib/appsignal/hooks/net_http.rb
appsignal-2.10.5 lib/appsignal/hooks/net_http.rb