If the toxic product is lipophilic, it tends to concentrate in the foam. But this is not the case for other types of compounds. For example, heavy metals will settle with the sludge.
It is always difficult to answer this question because the choice is determined by whatever substance you suspect you are dealing with. At first glance, though, I would say gas chromatography.