主要是针对两种redis gem做hook和prepend

# opentelemetry-instrumentation-redis-0.24.0/lib/opentelemetry/instrumentation/redis/instrumentation.rb
module OpenTelemetry
  module Instrumentation
    module Redis
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        install do |_config|
          require_dependencies
          patch_client
        end

        private

        def require_dependencies
          require_relative 'patches/redis_v4_client' if defined?(::Redis) && ::Redis::VERSION < '5'
          require_relative 'middlewares/redis_client' if defined?(::RedisClient)
        end

        def patch_client
          ::RedisClient.register(Middlewares::RedisClientInstrumentation) if defined?(::RedisClient)
          ::Redis::Client.prepend(Patches::RedisV4Client) if defined?(::Redis) && ::Redis::VERSION < '5'
        end
      end
    end
  end
end

span的名称就是命令名,以Patches::RedisV4Client为例

# opentelemetry-instrumentation-redis-0.24.0/lib/opentelemetry/instrumentation/redis/patches/redis_v4_client.rb
module OpenTelemetry
  module Instrumentation
    module Redis
      module Patches
        module RedisV4Client
          MAX_STATEMENT_LENGTH = 500
          private_constant :MAX_STATEMENT_LENGTH

          def process(commands)
            # ...

            attributes = {
              'db.system' => 'redis',
              'net.peer.name' => host,
              'net.peer.port' => port
            }

            # ...

            span_name = if commands.length == 1
                          commands[0][0].to_s.upcase
                        else
                          'PIPELINED'
                        end

            instrumentation_tracer.in_span(span_name, attributes: attributes, kind: :client) do |s|
              super(commands).tap do |reply|
                if reply.is_a?(::Redis::CommandError)
                  s.record_exception(reply)
                  s.status = Trace::Status.error(reply.message)
                end
              end
            end
          end
        end
      end
    end
  end
end