Sha256: dc56b0bfac320bfcff19944ffccd0740956f5a2762afcf85e97c25e6c89e5682

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.

DependencyDetection.defer do
  named :httprb

  depends_on do
    defined?(HTTP) && defined?(HTTP::Client)
  end

  executes do
    ::NewRelic::Agent.logger.info 'Installing http.rb instrumentation'
    require 'new_relic/agent/distributed_tracing/cross_app_tracing'
    require 'new_relic/agent/http_clients/http_rb_wrappers'
  end

  executes do
    class HTTP::Client
      def perform_with_newrelic_trace(request, options)
        wrapped_request = ::NewRelic::Agent::HTTPClients::HTTPRequest.new(request)

        begin
          segment = NewRelic::Agent::Tracer.start_external_request_segment(
            library: wrapped_request.type,
            uri: wrapped_request.uri,
            procedure: wrapped_request.method
          )

          segment.add_request_headers wrapped_request

          response = NewRelic::Agent::Tracer.capture_segment_error segment do
            perform_without_newrelic_trace(request, options)
          end

          wrapped_response = ::NewRelic::Agent::HTTPClients::HTTPResponse.new response
          segment.process_response_headers wrapped_response

          response
        ensure
          segment.finish if segment
        end
      end

      alias perform_without_newrelic_trace perform
      alias perform perform_with_newrelic_trace
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-6.15.0 lib/new_relic/agent/instrumentation/http.rb
newrelic_rpm-6.14.0 lib/new_relic/agent/instrumentation/http.rb
newrelic_rpm-6.13.1 lib/new_relic/agent/instrumentation/http.rb
newrelic_rpm-6.13.0 lib/new_relic/agent/instrumentation/http.rb
newrelic_rpm-6.12.0.367 lib/new_relic/agent/instrumentation/http.rb