Module: NewRelic::Agent::Instrumentation::AsyncHttp

Included in:
AsyncHttp::Prepend
Defined in:
lib/new_relic/agent/instrumentation/async_http/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Instance Method Summary collapse

Instance Method Details

#call_with_new_relic(method, url, headers = nil, body = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/new_relic/agent/instrumentation/async_http/instrumentation.rb', line 9

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