module Skylight module Probes module Redis # Unfortunately, because of the nature of pipelining, there's no way for us to # give a time breakdown on the individual items. PIPELINED_OPTS = { category: "db.redis.pipelined".freeze, title: "PIPELINE".freeze, internal: true }.freeze MULTI_OPTS = { category: "db.redis.multi".freeze, title: "MULTI".freeze, internal: true }.freeze module ClientInstrumentation def call(command, *) command_name = command[0] return super if command_name == :auth opts = { category: "db.redis.command", title: command_name.upcase.to_s, internal: true } Skylight.instrument(opts) { super } end end module ClientInstrumentationV5 def call_v(command) command_name = command[0] return super if command_name == :auth opts = { category: "db.redis.command", title: command_name.upcase.to_s, internal: true } Skylight.instrument(opts) { super } end end module Instrumentation def pipelined(*) Skylight.instrument(PIPELINED_OPTS) { super } end def multi(*) Skylight.instrument(MULTI_OPTS) { super } end end class Probe def install version = defined?(::Redis::VERSION) ? Gem::Version.new(::Redis::VERSION) : nil if !version || version < Gem::Version.new("3.0.0") Skylight.error "The installed version of Redis doesn't support Middlewares. " \ "At least version 3.0.0 is required." return end if ::Redis::Client.method_defined?(:call_v) ::Redis::Client.prepend(ClientInstrumentationV5) else ::Redis::Client.prepend(ClientInstrumentation) end ::Redis.prepend(Instrumentation) end end end register(:redis, "Redis", "redis", Redis::Probe.new) end end