Module: NewRelic::Agent::Instrumentation::Ethon::Easy

Includes:
NRShared
Included in:
Prepend
Defined in:
lib/new_relic/agent/instrumentation/ethon/prepend.rb,
lib/new_relic/agent/instrumentation/ethon/instrumentation.rb

Defined Under Namespace

Modules: Prepend

Constant Summary collapse

ACTION_INSTANCE_VAR =
:@nr_action
HEADERS_INSTANCE_VAR =
:@nr_headers

Constants included from NRShared

NRShared::INSTRUMENTATION_NAME, NRShared::NOTICEABLE_ERROR_CLASS

Instance Method Summary collapse

Methods included from NRShared

#prep_easy, #wrap_with_tracing

Instance Method Details

#fabricate_with_tracing(_url, action_name, _options) ⇒ Object

‘Ethon::Easy` doesn’t expose the “action name” (‘GET’, ‘POST’, etc.) and Ethon’s fabrication of HTTP classes uses ‘Ethon::Easy::Http::Custom` for non-standard actions. To be able to know the action name at `#perform` time, we set a new instance variable on the `Ethon::Easy` instance with the base name of the fabricated class, respecting the ’Custom’ name where appropriate.



64
65
66
67
68
# File 'lib/new_relic/agent/instrumentation/ethon/instrumentation.rb', line 64

def fabricate_with_tracing(_url, action_name, _options)
  fabbed = yield
  instance_variable_set(ACTION_INSTANCE_VAR, NewRelic::Agent.base_name(fabbed.class.name).upcase)
  fabbed
end

#headers_equals_with_tracing(headers) ⇒ Object

‘Ethon::Easy` uses `Ethon::Easy::Header` to set request headers on libcurl with `#headers=`. After they are set, they aren’t easy to get at again except via FFI so set a new instance variable on the ‘Ethon::Easy` instance to store them in Ruby hash format.



74
75
76
77
# File 'lib/new_relic/agent/instrumentation/ethon/instrumentation.rb', line 74

def headers_equals_with_tracing(headers)
  instance_variable_set(HEADERS_INSTANCE_VAR, headers)
  yield
end

#perform_with_tracing(*args) ⇒ Object



79
80
81
82
83
84
# File 'lib/new_relic/agent/instrumentation/ethon/instrumentation.rb', line 79

def perform_with_tracing(*args)
  return unless NewRelic::Agent::Tracer.state.is_execution_traced?

  segment = prep_easy(self)
  wrap_with_tracing(segment) { yield }
end