t-botz / trcprnt

Blazing fast traceparents for use in w3c Trace Context

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trcprnt

npm add trcprnt makes traceparent's simple


Features

  • LightweightBrowser runtime has a single dep, otherwise slim see.

  • Efficient — Effective reuse of memory, and lazy.

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

  • Quick — Get an id super performant.

⚙️ Install

npm add trcprnt

🚀 Usage

// producer

import { make } from 'trcprnt';

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

// consumer

import { parse } from 'trcprnt';

const parent = parse(request.headers.traceparent);
const id = parent.child();

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

💨 Benchmark

via the /bench directory with Node v16.12.0

Validation :: make
✔ trcprnt
✔ TraceParent

Benchmark :: make
  trcprnt                x 117,727 ops/sec ±1.65% (83 runs sampled)
  TraceParent            x 50,297 ops/sec ±3.65% (73 runs sampled)

Validation :: parse
✔ trcprnt
✔ TraceParent

Benchmark :: parse
  trcprnt                x 237,944 ops/sec ±0.56% (95 runs sampled)
  TraceParent            x 116,229 ops/sec ±4.15% (78 runs sampled)

Validation :: child
✔ trcprnt
✔ TraceParent

Benchmark :: child
  trcprnt                x 69,925 ops/sec ±2.35% (77 runs sampled)
  TraceParent            x 36,920 ops/sec ±3.45% (77 runs sampled)

License

MIT © Marais Rossouw

About

Blazing fast traceparents for use in w3c Trace Context

License:MIT License


Languages

Language:TypeScript 79.0%Language:JavaScript 21.0%