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')

Instance Method Summary collapse

Instance Method Details

#client_methodsObject



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

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



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

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

#dalli_methodsObject



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

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

#instrument_methods(client_class, requested_methods = METHODS) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 38

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



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

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)


15
16
17
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 15

def supports_binary_protocol?
  BINARY_PROTOCOL_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
end

#supports_datastore_instances?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/new_relic/agent/instrumentation/memcache/helper.rb', line 11

def supports_datastore_instances?
  DATASTORE_INSTANCES_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
end