The most common method astronomers use to determine the composition of stars, planets, and other objects is spectroscopy. Today, this process uses instruments with a grating that spreads out the light from an object by wavelength. This spread-out light is called a spectrum.
I hope this helps.