 <p><code>runtime.Stack()</code> puts a formatted stack trace into a supplied <code>[]byte</code>. You can then convert that to a string.</p> <p>You can also use <code>debug.Stack()</code>, which allocates a large enough buffer to hold the entire stack trace, puts the trace in it using <code>runtime.Stack</code>, and returns the buffer (<code>[]byte</code>).</p>