1 | <div align="center">
|
2 | <h1>tctx</h1>
|
3 | <p><code>npm add tctx</code> makes <a href="https://www.w3.org/TR/trace-context/">Trace Contexts</a> simple</p>
|
4 | <hr />
|
5 | <div>
|
6 | <a href="https://github.com/maraisr/tctx/actions/workflows/ci.yml">
|
7 | <img src="https://github.com/maraisr/tctx/actions/workflows/ci.yml/badge.svg"/>
|
8 | </a>
|
9 | <a href="https://npm-stat.com/charts.html?package=tctx">
|
10 | <img src="https://badgen.net/npm/dm/tctx?labelColor=black&color=black" alt="downloads"/>
|
11 | </a>
|
12 | <a href="https://packagephobia.com/result?p=tctx">
|
13 | <img src="https://badgen.net/packagephobia/install/tctx?labelColor=black&color=black" alt="size"/>
|
14 | </a>
|
15 | <a href="https://bundlephobia.com/result?p=tctx">
|
16 | <img src="https://badgen.net/bundlephobia/minzip/tctx?labelColor=black&color=black" alt="size"/>
|
17 | </a>
|
18 | </div>
|
19 | </div>
|
20 |
|
21 | ## ⚡ Features
|
22 |
|
23 | - **Lightweight** — [see](https://npm.anvaka.com/#/view/2d/tctx).
|
24 |
|
25 | - **Efficient** — Effective reuse of memory between children see [benchmarks](#-benchmark).
|
26 |
|
27 | - **Producer Friendly** — Are you a browser? `make()` and go home.
|
28 |
|
29 | ## ⚙️ Install
|
30 |
|
31 | ```sh
|
32 | npm add tctx
|
33 | ```
|
34 |
|
35 | ## 🚀 Usage
|
36 |
|
37 | ```ts
|
38 | // producer
|
39 |
|
40 | import { make } from 'tctx';
|
41 |
|
42 | fetch('/api', {
|
43 | headers: {
|
44 | traceparent: make(),
|
45 | },
|
46 | });
|
47 |
|
48 | // consumer
|
49 |
|
50 | import { parse } from 'tctx';
|
51 |
|
52 | const parent = parse(request.headers.traceparent);
|
53 | const id = parent.child();
|
54 |
|
55 | fetch('/downstream', {
|
56 | headers: {
|
57 | traceparent: id,
|
58 | },
|
59 | });
|
60 | ```
|
61 |
|
62 | ## 💨 Benchmark
|
63 |
|
64 | > via the [`/bench`](/bench) directory with Node v16.12.0
|
65 |
|
66 | ```
|
67 | Validation :: make
|
68 | ✔ tctx
|
69 | ✔ TraceParent
|
70 |
|
71 | Benchmark :: make
|
72 | tctx x 226,914 ops/sec ±1.69% (82 runs sampled)
|
73 | TraceParent x 52,308 ops/sec ±3.87% (78 runs sampled)
|
74 |
|
75 | Validation :: parse
|
76 | ✔ tctx
|
77 | ✔ TraceParent
|
78 |
|
79 | Benchmark :: parse
|
80 | tctx x 3,923,503 ops/sec ±0.44% (94 runs sampled)
|
81 | TraceParent x 120,083 ops/sec ±4.15% (76 runs sampled)
|
82 |
|
83 | Validation :: child
|
84 | ✔ tctx
|
85 | ✔ TraceParent
|
86 |
|
87 | Benchmark :: child
|
88 | tctx x 123,069 ops/sec ±3.40% (69 runs sampled)
|
89 | TraceParent x 39,435 ops/sec ±2.84% (79 runs sampled)
|
90 | ```
|
91 |
|
92 | ## License
|
93 |
|
94 | MIT © [Marais Rossouw](https://marais.io)
|