3 releases

0.0.3 Nov 3, 2022
0.0.2 Aug 31, 2022
0.0.1 Aug 24, 2022

#23 in #w3c

Download history 279/week @ 2024-07-21 132/week @ 2024-07-28 165/week @ 2024-08-04 153/week @ 2024-08-11 139/week @ 2024-08-18 95/week @ 2024-08-25 53/week @ 2024-09-01 88/week @ 2024-09-08 87/week @ 2024-09-15 87/week @ 2024-09-22 17/week @ 2024-09-29 94/week @ 2024-10-06 22/week @ 2024-10-13 95/week @ 2024-10-20 11/week @ 2024-10-27 16/week @ 2024-11-03

145 downloads per month

MIT license

18KB
422 lines

tctx

npm add tctx makes Trace Contexts simple


⚡ Features

  • Lightweightsee.

  • Efficient — Effective reuse of memory between children see benchmarks.

  • Producer Friendly — Are you a browser? make() and go home.

⚙️ Install

npm add tctx

🚀 Usage

// producer

import { make } from 'tctx';

fetch('/api', {
  headers: {
    traceparent: make(),
  },
});

// consumer

import { parse } from 'tctx';

const parent = parse(request.headers.traceparent);
// Passing true will mark the traceparent as sampled — ends with 01.
const id = parent.child(true);

fetch('/downstream', {
  headers: {
    traceparent: id,
  },
});

💨 Benchmark

via the /bench directory with Node v17.9.0


Validation :: make
✔ tctx
✔ traceparent
✔ trace-context

Benchmark :: make
  tctx                   x 640,126 ops/sec ±0.21% (99 runs sampled)
  traceparent            x 161,062 ops/sec ±0.55% (94 runs sampled)
  trace-context          x 293,268 ops/sec ±0.35% (98 runs sampled)

Validation :: parse
✔ tctx
✔ traceparent
✔ trace-context

Benchmark :: parse
  tctx                   x 5,561,913 ops/sec ±0.14% (100 runs sampled)
  traceparent            x   303,543 ops/sec ±0.42% (91 runs sampled)
  trace-context          x 3,169,835 ops/sec ±0.05% (99 runs sampled)

Validation :: child
✔ tctx
✔ traceparent
✔ trace-context

Benchmark :: child
  tctx                   x 346,827 ops/sec ±0.40% (97 runs sampled)
  traceparent            x 109,942 ops/sec ±0.61% (93 runs sampled)
  trace-context          x 195,381 ops/sec ±0.35% (93 runs sampled)

License

MIT © Marais Rossouw

Dependencies

~170KB