If you do not have the necessary space to house a discrete optical sensor, your only suitable option would be to use fiber optics. Plastic fiber optics are the perfect choice if there is special requirements for robustness , resistance to chemicals and high ambient temperatures. Here there are a wide selection of unique base units that have varying performance levels as well as functions available. From the simplest design possible having a potentiometer or a high end device that comes with a display also. If there are special requirements like greater temperature application , unique fiber glass with with a corrugated metal shield is also usable.
Additional features include, Robotics, Small parts detection, control of part characteristics, perfect for small installation spaces, handling and assemble technology.