Sha256: 16a83f2e0338dcb92ef22851fc03e193cff2ae8a5aadb97d158f5c37828ba0d6

Contents?: true

Size: 1.94 KB

Versions: 34

Compression:

Stored size: 1.94 KB

Contents

module Skylight
  module Probes
    module Redis
      class Probe
        def install
          version = defined?(::Redis::VERSION) ? Gem::Version.new(::Redis::VERSION) : nil

          if !version || version < Gem::Version.new("3.0.0")
            # Using $stderr here isn't great, but we don't have a logger accessible
            $stderr.puts "[SKYLIGHT] [#{Skylight::VERSION}] The installed version of Redis doesn't " \
                          "support Middlewares. At least version 3.0.0 is required."
            return
          end

          ::Redis::Client.class_eval do
            alias call_without_sk call

            def call(command, &block)
              command_name = command[0]

              return call_without_sk(command, &block) if command_name == :auth

              opts = {
                category: "db.redis.command",
                title:    command_name.upcase.to_s
              }

              Skylight.instrument(opts) do
                call_without_sk(command, &block)
              end
            end
          end
        end

        # 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

        ::Redis.class_eval do
          alias pipelined_without_sk pipelined

          def pipelined(&block)
            Skylight.instrument(PIPELINED_OPTS) do
              pipelined_without_sk(&block)
            end
          end


          alias multi_without_sk multi

          def multi(&block)
            Skylight.instrument(MULTI_OPTS) do
              multi_without_sk(&block)
            end
          end
        end
      end
    end

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

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
skylight-1.6.1 lib/skylight/probes/redis.rb
skylight-1.6.0 lib/skylight/probes/redis.rb
skylight-1.5.1 lib/skylight/probes/redis.rb
skylight-1.5.0 lib/skylight/probes/redis.rb
skylight-1.4.4 lib/skylight/probes/redis.rb
skylight-1.4.3 lib/skylight/probes/redis.rb
skylight-1.4.2 lib/skylight/probes/redis.rb
skylight-1.4.1 lib/skylight/probes/redis.rb
skylight-1.4.0 lib/skylight/probes/redis.rb
skylight-1.4.0.beta.2 lib/skylight/probes/redis.rb
skylight-1.4.0.beta lib/skylight/probes/redis.rb
skylight-1.3.1 lib/skylight/probes/redis.rb
skylight-1.3.0 lib/skylight/probes/redis.rb
skylight-1.2.2 lib/skylight/probes/redis.rb
skylight-1.2.1 lib/skylight/probes/redis.rb
skylight-1.2.0 lib/skylight/probes/redis.rb
skylight-1.1.0 lib/skylight/probes/redis.rb
skylight-1.0.1 lib/skylight/probes/redis.rb
skylight-1.0.0 lib/skylight/probes/redis.rb
skylight-0.10.6 lib/skylight/probes/redis.rb