Module: NewRelic::Agent::Instrumentation::HTTPrb

Included in:
Prepend
Defined in:
lib/new_relic/agent/instrumentation/httprb/chain.rb,
lib/new_relic/agent/instrumentation/httprb/prepend.rb,
lib/new_relic/agent/instrumentation/httprb/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Constant Summary collapse

INSTRUMENTATION_NAME =
NewRelic::Agent.base_name(name)

Instance Method Summary collapse

Instance Method Details

#with_tracing(request) ⇒ 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
# File 'lib/new_relic/agent/instrumentation/httprb/instrumentation.rb', line 9

def with_tracing(request)
  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

  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) { yield }

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

    response
  ensure
    ::NewRelic::Agent::Transaction::Segment.finish(segment)
  end
end