
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
traceparent
Advanced tools
This is a basic implementation of the traceparent header part of the W3C trace context spec.
npm install traceparent
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)
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.recordedReturns true if this TraceParent is sampled.
traceParent.traceIdThe traceId property will propagate through all children in the tree to link them all together.
traceParent.idThe id property is used to uniquely identify a given TraceParent instance within the tree.
traceParent.parentIdThe parentId property links this context to its direct parent in the tree.
traceParent.flagsThe flags property is used to store metadata such as the sampling decision.
traceParent.versionThe 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.
FAQs
Context management helper for the w3c traceparent header format
The npm package traceparent receives a total of 22,429 weekly downloads. As such, traceparent popularity was classified as popular.
We found that traceparent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.