tctx
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

trace context licenses

W3C Trace Context's made simple

This is free to use software, but if you do like it, consider supporting me ❤️

sponsor me buy me a coffee

⚙️ Install

Avaliable on jsr, NPM and deno.land

npm add tctx

🚀 Usage

// producer

import * as traceparent from 'tctx/traceparent';
import * as tracestate from 'tctx/tracestate';

fetch('/api', {
	headers: {
		traceparent: traceparent.make(),
		tracestate: tracestate.make({ key: 'value' }),
	},
});

// consumer

import * as traceparent from 'tctx/traceparent';
import * as tracestate from 'tctx/tracestate';

const parent_key = traceparent.parse(request.headers.traceparent);
const parent_state = tracestate.parse(request.headers.tracestate);
parent_state.set('vendor', 'value');

fetch('/downstream', {
	headers: {
		traceparent: parent.child(),
		tracestate: parent_state,
	},
});

💨 Benchmark

via the /bench directory with deno 1.41.3

#  make
✔  tctx          ~ 1,666,269 ops/sec ± 0.04%
✔  traceparent   ~   156,468 ops/sec ± 0.07%
✔  trace-context ~   691,817 ops/sec ± 0.02%

#  parse
✔  tctx          ~ 3,429,690 ops/sec ± 0.05%
✔  traceparent   ~   186,418 ops/sec ± 0.07%
✔  trace-context ~ 3,327,424 ops/sec ± 0.10%

#  child
✔  tctx          ~ 2,627,467 ops/sec ± 0.04%
✔  traceparent   ~   256,958 ops/sec ± 0.10%
✔  trace-context ~ 1,252,370 ops/sec ± 0.04%

License

MIT © Marais Rossouw

Versions

Current Tags

Version History

Package Sidebar

Install

npm i tctx

Weekly Downloads

654

Version

0.2.0

License

MIT

Unpacked Size

33.2 kB

Total Files

17

Last publish

Collaborators

  • marais