node-continuation-local-storage icon indicating copy to clipboard operation
node-continuation-local-storage copied to clipboard

how to know current callstack finished

Open peaksnail opened this issue 8 years ago • 2 comments

hi I want to know when current callstack finished, and then I will do some other things after that; I debug the function exit in the finally of namespace.bind or run, But It couldn't work Is there some good way to know when current callstack finished(include callback)?

thanks zeng

peaksnail avatar Jul 11 '16 06:07 peaksnail

Hi! If you have a webapp may be this approach will help you. I decided to put expressjs response object in the context and added this to the lib.

https://github.com/AleksMeshkov/node-continuation-local-storage/commit/7eee8cf67a4c3f79ca69bd7b5246c183dbdaaedd

AleksMeshkov avatar Aug 23 '17 12:08 AleksMeshkov

I am interested in this as well. This functionality could be added with some kind of event when the context exits. I don't know the performance implications of adding this however.

Our use case is for our tracing library to automatically instrument code. For cases following a request/response pattern (i.e. web frameworks) it's easy to know when to finish the span. However, for cases like message queue consumers or task workers, it can be difficult to know when to finish the span since there is no explicit callback or response. In this case, the only way to know that the span is finished right now is for the user to explicitly finish it. It would be really useful to be able to know when the context has exited to automatically finish the span.

@othiym23 I believe you have created this library for a similar use case? Any insight on this would be appreciated :)

rochdev avatar Jun 05 '18 13:06 rochdev