Module: NewRelic::Agent::Instrumentation::Memcache::Helper

Included in:
Prepend
Defined in:
lib/new_relic/agent/instrumentation/memcache/helper.rb

Constant Summary collapse

DATASTORE_INSTANCES_SUPPORTED_VERSION =
Gem::Version.new('2.6.4')
BINARY_PROTOCOL_SUPPORTED_VERSION =
Gem::Version.new('3.0.2')
META_PROTOCOL_SUPPORTED_VERSION =
Gem::Version.new('3.2.0')
READ_MULTI_SUPPORTED_VERSION =
Gem::Version.new('5.0.0')

Instance Method Summary collapse

Instance Method Details

#client_methodsObject



29
30
31
32
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 29

def client_methods
  [:get, :get_multi, :set, :add, :incr, :decr, :delete, :replace, :append,
    :prepend, :cas, :single_get, :multi_get, :single_cas, :multi_cas]
end

#dalli_cas_methodsObject



38
39
40
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 38

def dalli_cas_methods
  [:get_cas, :set_cas, :replace_cas, :delete_cas]
end

#dalli_methodsObject



34
35
36
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 34

def dalli_methods
  [:get, :set, :add, :incr, :decr, :delete, :replace, :append, :prepend, :cas]
end

#instrument_methods(client_class, requested_methods = METHODS) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 48

def instrument_methods(client_class, requested_methods = METHODS)
  supported_methods_for(client_class, requested_methods).each do |method_name|
    visibility = NewRelic::Helper.instance_method_visibility(client_class, method_name)
    method_name_without = :"#{method_name}_without_newrelic_trace"

    client_class.class_eval do
      include NewRelic::Agent::Instrumentation::Memcache::Tracer

      alias_method(method_name_without, method_name)

      define_method(method_name) do |*args, &block|
        with_newrelic_tracing(method_name, *args) { __send__(method_name_without, *args, &block) }
      end

      __send__(visibility, method_name)
      __send__(visibility, method_name_without)
    end
  end
end

#supported_methods_for(client_class, methods) ⇒ Object



42
43
44
45
46
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 42

def supported_methods_for(client_class, methods)
  methods.select do |method_name|
    client_class.method_defined?(method_name) || client_class.private_method_defined?(method_name)
  end
end

#supports_binary_protocol?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 17

def supports_binary_protocol?
  NewRelic::Helper.version_satisfied?(BINARY_PROTOCOL_SUPPORTED_VERSION, '<=', ::Dalli::VERSION)
end

#supports_datastore_instances?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 13

def supports_datastore_instances?
  NewRelic::Helper.version_satisfied?(DATASTORE_INSTANCES_SUPPORTED_VERSION, '<=', ::Dalli::VERSION)
end

#supports_meta_protocol?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 21

def supports_meta_protocol?
  NewRelic::Helper.version_satisfied?(META_PROTOCOL_SUPPORTED_VERSION, '<=', ::Dalli::VERSION)
end

#supports_read_multi_req?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 25

def supports_read_multi_req?
  NewRelic::Helper.version_satisfied?(READ_MULTI_SUPPORTED_VERSION, '<=', ::Dalli::VERSION)
end