Various embodiments of a sealed package and a method of forming such package are disclosed. The package includes a housing, a substrate hermetically sealed to the housing, and a light source disposed on a first major surface of the substrate. The package further includes a detector disposed on the first major surface of the substrate and having a detecting surface. The package also includes a masking layer disposed on at least one of the first major surface and a second major surface of the substrate, where the masking layer includes a first aperture aligned with an emission axis of the light source in a direction orthogonal to the first major surface of the substrate. The masking layer further includes a second aperture aligned with a detection axis of the detector in a direction orthogonal to the first major surface of the substrate.