Sha256: 400ab46e3dbfb7dbb69ab84cb423a21a2c579a032391a0a2c4cae2c93c546b25

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

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
      }.freeze

      MULTI_OPTS = {
        category: "db.redis.multi".freeze,
        title:    "MULTI".freeze
      }.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
          }

          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

          ::Redis::Client.prepend(ClientInstrumentation)
          ::Redis.prepend(Instrumentation)
        end
      end
    end

    register(:redis, "Redis", "redis", Redis::Probe.new)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
skylight-5.0.0.beta2 lib/skylight/probes/redis.rb
skylight-5.0.0.beta lib/skylight/probes/redis.rb