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

traceparent

v1.0.0

Published

Context management helper for the w3c traceparent header format

Downloads

102,851

Readme

traceparent

npm Build status codecov Standard - JavaScript Style Guide

This is a basic implementation of the traceparent header part of the W3C trace context spec.

Installation

npm install traceparent

Example Usage

const crypto = require('crypto')
const TraceParent = require('traceparent')

const version = Buffer.alloc(1).toString('hex')
const traceId = crypto.randomBytes(16).toString('hex')
const id = crypto.randomBytes(8).toString('hex')
const flags = '01'

const header = `${version}-${traceId}-${id}-${flags}`

const parent = TraceParent.fromString(header)

API

new TraceParent(buffer)

Construct a new TraceParent instance from an existing buffer. The contents are binary data that corresponds to the structure of the W3C traceparent header format, with separators removed.

TraceParent.fromString(header)

Reconstruct a TraceParent instance from a formatted W3C traceparent header string.

TraceParent.startOrResume(parent, settings)

Resume from a parent context, if given, or start a new context. Accepts another TraceParent instance, a W3C traceparent header string, or a Span or Transaction instance from elastic-apm-node.

Requires a settings object with a transactionSampleRate value from 0.0 to 1.0 to generate a sampling decision for the context. This will only be applied when starting a new context. When continuing an existing context, the sampling decision will be propagated into all child contexts.

traceParent.recorded

Returns true if this TraceParent is sampled.

traceParent.traceId

The traceId property will propagate through all children in the tree to link them all together.

traceParent.id

The id property is used to uniquely identify a given TraceParent instance within the tree.

traceParent.parentId

The parentId property links this context to its direct parent in the tree.

traceParent.flags

The flags property is used to store metadata such as the sampling decision.

traceParent.version

The version property corresponds to the version segment of the W3C traceparent header.

traceParent.child()

Create a new TraceParent instance that is a child of this one.

traceParent.toString()

Formats the TraceParent instance as a W3C traceparent header.

traceParent.ensureParentId()

Return the parent ID, if there is none, generate one. This is useful in browser instrumentation to produce a starting span around a browser request which was not instrumented prior to page load.

License

MIT