The common answer is a stack trace. In JavaScript you can get that any time and any where with:
new Error().stack;
Stack traces lose their helpfulness in applications with high frequency network traffic because the network buffer will likely not be the start of flow control but a stack trace cannot run deeper than that.