Menu

1 / 3

How to Trace Every Request Through Your Node.js Logs with AsyncLocalStorage

#sitepoint#request#requestid#context#logger
Long article (2802 words) — no AI summary yet.
Reading 0:00
15s threshold

Community Article

Community articles are authored by SitePoint Premium contributors. Content is screened before publication, and SitePoint reserves the right to moderate or remove articles that violate our guidelines. Views expressed are those of the authors and do not necessarily reflect those of SitePoint.

The AI briefing for Developers

Stay up to date with AI tools, model releases, and developer workflows that matter.

Weekly. Free. One click to leave.

A Node.js API handles many requests at once on a single thread. That's what makes it fast, and it's also what makes its logs hard to read. When two customers load their order history at the same moment, the log looks like this:

loading order summary customerId = c - 42 loading order summary customerId = c - 77 order summary loaded customerId = c - 77 request finished status = 200 ms = 246 order summary loaded customerId = c - 42 request finished status = 200 ms = 1126

Which request finished line belongs to which customer?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.