Optical sensor for real-time weld defect detection