Recently the sugar glycoaldehyde was detected in a star system 400 light years from Earth. How exactly are molecules detected in space? I am aware that spectroscopy is used to detect them, but I don't know the details.
The research article corresponding to the observation to which the question is referring is Detection of the simplest sugar, glycolaldehyde, in a solar-type protostar with ALMA. Note that the molecule is glycolaldehyde rather than glycoaldehyde.
This observation of glycolaldehyde in space is not the first. It was earlier observed by Greenbank radio telescope, in West Virginia, USA, for example. The Greenbank observation is reported in INTERSTELLAR GLYCOLALDEHYDE: THE FIRST SUGAR. Glycolaldehyde was detected through radio signals in the 71-103 GHz range that are photons emitted when the molecule transitions from an excited rotation state to a lower energy rotational state.
In the ALMA observation, the molecule was detected based upon radio signals near 220 GHz and 690 GHz. These correspond to photons emitted by the molecule when transitioning from an excited rotational state to a lower energy rotational state, but are a different set of transitions from those observed at Greenbank, including some for excited vibrational states.
I'll try to add more information later, there are a wide variety of spectroscopic techniques: absorbance vs. emission; rotation, vibration and electronics transitions, and many different frequency ranges.