The light that we receive from space contains a lot of information. Specifically, because of quantum nature of molecules and atoms, theses small species absorb light at very specific wavelengths.Each molecule, atom or ion has a unique set of absorption features. Think of it as the molecule own fingerprint. Hence, if we look at a star or a hot gas, we can deduce which species are present by looking at the very specific emission lines present in our spectrum of light. Similarly, if the light of a star or of a galaxy passes trough a dust cloud, then we can deduce which species are present in that cloud from the absorption lines present.
Molecular hydrogen doesn't really have absorption lines in the infrared, visible and UV light and so it doesn't emit nor absorb very much light and so we don't see it in our spectrum, i.e. whether there is hydrogen or not, the light that we receive looks the same.