npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@request-inspector/node-instrumenter

v1.0.0-beta4

Published

A request timing diagnostic tool for Web and Node.js applications

Downloads

8

Readme

Request Inspector

WARNING: This software is still in beta. It is highly likely that you will encounter bugs. If you do, please file an issue on GitHub and let me know!

Request Inspector is an HTTP(S) request diagnostic tool for Node.js servers.

When a web or mobile client makes an HTTP call to a backend, it can be tricky to find out why that particular request took X amount of time. This is especially true in the days of microservices, where servers make calls to servers which make calls to other servers. How does one correlate timing information across all of these microservices? Enter Request Inspector.

Request inspector works by adding a header to all HTTP requests that is then used to track the request through multiple systems. Request inspector also uses continuation local storage in Node.js to track that request through asynchronous calls locally. This data is then sent to a special Request Inspector server which aggregates and correlates all of this data.

Here is a screenshot showing the timeline working across three separate servers:

UI Screenshot

Be sure to check out the example.

Installation

Request Inspector is currently split into two packages: a Node.js instrumenter and the server. The instrumenter runs inside of your Node.js server, which collects data and sends it to the server.

Start by installing the server globally:

npm install -g @request-inspector/server

Then install the Node.js instrumenter in your server project:

npm install @request-inspector/node-instrumenter

Finally, install the browser instrumenter in your client project and use webpack, browserfiy or similar to bundle it into your application:

npm install @request-inspector/browser-instrumenter

Alternatively, you can download the browser instrumenter as a single file and add it with a script tag, e.g. <script src="/lib/request_inspector.js"></script>.

Usage

Start by instrumenting your Node.js application by requiring/importing the module and initializing it:

const instrumenter = require('@request-inspector/node-instrumenter');
instrumenter.init({
  serverHostname: 'localhost',
  serverPort: 7176,
  serviceName: 'template'
}, (initErr) => {

  // Your app code here

});

Then instrument your browser application by initializing the module:

window.requestInspector.init({
  serverHostname: 'localhost',
  serverPort: 7176,
  serviceName: 'template'
})

Then, start the server:

request-inspector [-p PORT]

Note: it is recommended that you run this initialization code before you require/import any other code.

This code will automatically instrument all inbound HTTP requests for you. You can also add more data points to get a more fine-grained look at what your application is doing:

const templateReadEvent = instrumenter.begin('file-read');
fs.readFile('./my-file', (err, data) => {
  instrumenter.end(templateReadEvent);
});

Each begin and end call is automatically correlated with an HTTP request that Node.js received. Note that you cannot begin an event that is not associated with an HTTP request. You can use the instrumenter.isInRequestContext() check to see if you are in a request context or not.

You can also add extra data associated with your event:

const templateReadEvent = instrumenter.begin('file-read', {
  filename: './my-file'
});
fs.readFile('./my-file', (err, data) => {
  instrumenter.end(templateReadEvent, {
    error: err && err.toString()
  });
});

This information can be in any format that can be passed to JSON.stringify, and it is sent to the server and shown in the UI.

To view the results, point your browser to the request-inspector server URL that you entered in the init method above, e.g. http://localhost:7176/.

License

MIT License

Copyright (c) 2018 Bryan Hughes [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.