Sha256: 313264ed7a9eba1b159be87db2a2363abcdb62bae6a74265dd71cb7b2fdafab7

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

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

require 'new_relic/agent/http_clients/async_http_wrappers'

module NewRelic::Agent::Instrumentation
  module AsyncHttp
    def call_with_new_relic(method, url, headers = nil, body = nil)
      headers ||= {} # if it is nil, we need to make it a hash so we can insert headers
      wrapped_request = NewRelic::Agent::HTTPClients::AsyncHTTPRequest.new(self, method, url, headers)

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

      begin
        response = nil
        segment.add_request_headers(wrapped_request)

        NewRelic::Agent.disable_all_tracing do
          response = NewRelic::Agent::Tracer.capture_segment_error(segment) do
            yield(headers)
          end
        end

        wrapped_response = NewRelic::Agent::HTTPClients::AsyncHTTPResponse.new(response)
        segment.process_response_headers(wrapped_response)
        response
      ensure
        segment&.finish
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/instrumentation/async_http/instrumentation.rb