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

context-tracer

v0.6.5

Published

context tracing for node event loop

Downloads

12

Readme

context-tracer : log context info, for your node apps

Propagates a unique context ID throughout calls. Similar to Java MDC and the likes.

For node 6+.

Usage

Returns a callback, augmented with a unique context UUID. Within this callback, all operations (and their childs) will inherit the unique ID.

tracer.set(() => {
  // all nested calls have now access to a unique context ID
  console.log(tracer.get()); // you can now log it
});

Example

The following code :

const tracer = require("context-tracer");

function callThings() {
  nested();
}

function nested() {
  console.log("nested call - stack n°", tracer.get());
}

tracer.set(() => {
  console.log("first call - stack n°", tracer.get());

  // called within the tracer, and inherits the ID
  callThings();
});

Will print :

> first call : stack n°AAAA
> nested call : stack n°AAAA

Installation

> npm install context-tracer

API

tracer.set(callback)

  • Creates a unique context ID
  • provides a context-augmented callback :
    • all calls within the callback will have the same context ID
    • you only need to call the first function in the callback to propagate the context to its childs
tracer.set(() => {
  // all operations called within the tracer will inherit a unique context ID
});

You can nest context augments : the new context ID will override the previous one, only for its callback operations.

tracer.get() ⇒ string

  • Retrieves current context ID
  • Returns a "no context" string if set hasn't been called
console.log("stack n°" + tracer.get());

> stack n°AAAA

:warning: Node 6-7 users

While this package supports node 6-7, the underlying architecture is considered experimental for these versions. Read more here.

Local installation

This project is made using Typescript. To generate the transpiled javascript package, you need to run gulp :

$ gulp

You can run the full test suite with mocha :

$ npm i && npm run test