W3C Trace Contexts made simple
tctx is a blazing fast, zero-dependency library for working with W3C Trace Context headers in JavaScript. It provides a simple API for creating, parsing, and manipulatingtraceparent and tracestate headers according to the W3C Trace Context Level 2 specification.
Key Features
W3C Spec Compliant
Fully compliant with W3C Trace Context Level 2 specification for distributed tracing.
Blazing Fast Performance
Up to 12x faster than alternative implementations with optimized algorithms.
Universal Runtime Support
Works seamlessly in Node.js, Deno, Bun, and browsers without any changes.
Zero Dependencies
Minimal footprint with only one dependency (@lukeed/csprng) for secure random generation.
Simple API
Intuitive functions for creating, parsing, and propagating trace contexts across services.
TypeScript Support
Full TypeScript type definitions included for excellent developer experience.
What is W3C Trace Context?
The W3C Trace Context specification defines a standardized format for propagating trace information across distributed systems. It consists of two HTTP headers:- traceparent - Contains the core trace identification data (trace ID, parent ID, flags)
- tracestate - Contains vendor-specific trace information as key-value pairs
Quick Example
Performance
tctx is designed for performance. Benchmark results show it significantly outperforms alternative implementations:- 12.5x faster than
traceparentpackage for creating trace contexts - 11.3x faster than
traceparentpackage for creating child spans - 2.8x faster than
trace-contextpackage on average
Get Started
Quickstart
Get up and running with tctx in minutes
Installation
Install tctx with your preferred package manager
API Reference
Explore the complete API documentation
Guides
See real-world usage examples and patterns