Build a Node.js Performance Tracing Tool with Async Hooks and Performance API
This article explains how to combine Node.js's experimental Async Hooks and Performance Timing APIs to create a simple tracing and performance monitoring tool, eliminating manual timing and offering a foundation that can be extended into a custom solution, while also noting an open‑source Pandora.js utility.
Trace, or link monitoring, is a mature technology in real‑time application performance monitoring that lets you visually identify slow links and target optimizations. However, applying this technique on Node.js has been somewhat cumbersome, requiring extensive handling of monitoring nodes.
Recently, newer versions of Node.js (>8.x) introduced two experimental APIs: Async Hooks and the Performance Timing API. The former injects hooks into asynchronous operations, facilitating request tracing, while the latter implements the W3C Performance Timeline specification, providing wrapped performance metrics.
By combining these two APIs we can implement a simple performance monitoring tool, freeing us from the awkwardness of manual timing before and after calls. Additional features can be built on this example to develop a personalized performance monitoring solution.
Click Read the original article to explore further.
Additionally, the team has open‑sourced a lightweight, feature‑rich Node.js application management tool called Pandora.js, built with TypeScript, which already includes Metrics and Trace capabilities using the aforementioned technologies. Interested users can check it on GitHub, give it a star, contribute PRs, or submit resumes.
GitHub: https://github.com/midwayjs/pandora
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Node Underground
No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
