Module: Oboe::Inst::Memcached

Includes:
API::Memcache
Defined in:
lib/oboe/inst/memcached.rb

Constant Summary

Constants included from API::Memcache

API::Memcache::MEMCACHE_OPS

Class Method Summary collapse

Methods included from API::Memcache

#memcache_hit?, #remote_host

Class Method Details

.included(cls) ⇒ 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
33
34
35
36
37
38
39
# File 'lib/oboe/inst/memcached.rb', line 9

def self.included(cls)
  Oboe.logger.info '[oboe/loading] Instrumenting memcached' if Oboe::Config[:verbose]

  cls.class_eval do
    MEMCACHE_OPS.reject { |m| !method_defined?(m) }.each do |m|
      define_method("#{m}_with_oboe") do |*args|
        opts = { :KVOp => m }

        if args.length && !args[0].is_a?(Array)
          opts[:KVKey] = args[0].to_s
          rhost = remote_host(args[0].to_s)
          opts[:RemoteHost] = rhost if rhost
        end

        Oboe::API.trace('memcache', opts) do
          result = send("#{m}_without_oboe", *args)

          info_kvs = {}
          info_kvs[:KVHit] = memcache_hit?(result) if m == :get && args.length && args[0].class == String
          info_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:memcached][:collect_backtraces]

          Oboe::API.log('memcache', 'info', info_kvs) unless info_kvs.empty?
          result
        end
      end

      class_eval "alias #{m}_without_oboe #{m}"
      class_eval "alias #{m} #{m}_with_oboe"
    end
  end
end