Optical sensor protection