Module: NewRelic::Agent::Instrumentation::Ethon::NRShared

Included in:
Easy, Multi
Defined in:
lib/new_relic/agent/instrumentation/ethon/instrumentation.rb

Constant Summary collapse

INSTRUMENTATION_NAME =
'Ethon'
NOTICEABLE_ERROR_CLASS =
'Ethon::Errors::EthonError'

Instance Method Summary collapse

Instance Method Details

#prep_easy(easy, parent = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/new_relic/agent/instrumentation/ethon/instrumentation.rb', line 13

def prep_easy(easy, parent = nil)
  wrapped_request = NewRelic::Agent::HTTPClients::EthonHTTPRequest.new(easy)
  segment = NewRelic::Agent::Tracer.start_external_request_segment(
    library: wrapped_request.type,
    uri: wrapped_request.uri,
    procedure: wrapped_request.method,
    parent: parent
  )
  segment.add_request_headers(wrapped_request)

  callback = proc do
    wrapped_response = NewRelic::Agent::HTTPClients::EthonHTTPResponse.new(easy)
    segment.process_response_headers(wrapped_response)

    if easy.return_code != :ok
      e = NewRelic::Agent::NoticeableError.new(NOTICEABLE_ERROR_CLASS,
        "return_code: >>#{easy.return_code}<<, response_code: >>#{easy.response_code}<<")
      segment.notice_error(e)
    end

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

  easy.on_complete { callback.call }

  segment
end

#wrap_with_tracing(segment, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/new_relic/agent/instrumentation/ethon/instrumentation.rb', line 41

def wrap_with_tracing(segment, &block)
  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

  NewRelic::Agent::Tracer.capture_segment_error(segment) do
    yield
  end
ensure
  NewRelic::Agent::Transaction::Segment.finish(segment)
end