There's no set time. Long enough so that he/she feels they know you well enough to write a great LOR. The longer the better.
I shadowed a DO all the way up until matriculation, and I'll shadow him again when I go back for Christmas. To me, it's a great experience, and a good way to make possible future contacts, especially if you plan on practicing there in the future.
If you are haveing fun shadowing, don't stop, just keep on and on until med school. Maybe do a preceptorship later. Hell, I'd join the group of the guy I shadowed. Why, because I love it that damn much. REALLY!