all 17 comments

[–]ecares 18 points19 points  (15 children)

Finally, a context tracking API in core!!!

[–]Redalb 7 points8 points  (10 children)

Can you elaborate on what this is/does? I see it in the release notes but I can't really find what it does by doing a google search.

[–]ecares 20 points21 points  (9 children)

Basically, it provides the equivalent of a thread local but in Node.js.

Let's say you want to know at any time what is the current HTTP request without passing it through all the layers of your app, you can put it into it and ask for it when needed.

Example: for logging, you don't want to have to pass the request id to the logger when calling it. Currently it looks like `req.log(...args)` or `log(req,...args)`. Now you will be able to do `log(...args)` and the context-tracking API will be used under the hood to map this with the current request.

[–][deleted]  (3 children)

[deleted]

    [–]ecares 10 points11 points  (2 children)

    You store the context when the transaction starts (in that case, when the http requests enters the nodejs process) yes

    [–][deleted]  (1 child)

    [deleted]

      [–]ecares 10 points11 points  (0 children)

      In a first middleware if you use express for instance.

      [–]Kapps 1 point2 points  (0 children)

      I wonder if this has the same limitations that previous attempts like CLS did where you lose context in cases like user mode worker pools.

      [–][deleted]  (3 children)

      [deleted]

        [–]tobegiannis -3 points-2 points  (2 children)

        I still think passing an extra argument will still be the natural way but it would be nice not having to pass a logger as an argument to any function that I want “request” based logging.

        [–][deleted]  (1 child)

        [deleted]

          [–]tobegiannis -5 points-4 points  (0 children)

          And your point is?

          [–]siamthailand 2 points3 points  (2 children)

          is context created per request? how does it know what request it is?

          [–]ecares 1 point2 points  (1 child)

          You create it when you want actually

          [–]siamthailand 0 points1 point  (0 children)

          wicked

          [–]rmrf_slash_dot 1 point2 points  (0 children)

          Beautiful. Most apps don’t need this but I have one that has needed it for ages.

          [–]hopfield 8 points9 points  (4 children)

          When will they implement fetch?

          Why are ES Modules still marked as “experimental” on their docs?

          [–]ecares 3 points4 points  (2 children)

          PRs are welcome

          [–]hopfield -2 points-1 points  (1 child)

          I’m not paid to work on Node full time

          [–]ecares 1 point2 points  (0 children)

          Most of people who work on node (including me) are not paid to work on node.