Add spec and doc to stactrace function.

Builds upon #517 and #524.