Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maraisr/tctx
Blazing fast w3c Trace Contexts for any JS runtime
https://github.com/maraisr/tctx
distributed-tracing tracecontext traceparent w3c-trace-context
Last synced: about 2 months ago
JSON representation
Blazing fast w3c Trace Contexts for any JS runtime
- Host: GitHub
- URL: https://github.com/maraisr/tctx
- Owner: maraisr
- License: mit
- Created: 2021-11-18T07:47:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-02T06:14:17.000Z (3 months ago)
- Last Synced: 2024-07-03T19:51:31.562Z (3 months ago)
- Topics: distributed-tracing, tracecontext, traceparent, w3c-trace-context
- Language: TypeScript
- Homepage:
- Size: 195 KB
- Stars: 15
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-blazingly-fast - tctx - Blazing fast traceparents for use in w3c Trace Context (TypeScript)
README
# trace context [![licenses](https://licenses.dev/b/npm/tctx?style=dark)](https://licenses.dev/npm/tctx)
**W3C [Trace Context](https://w3c.github.io/trace-context/)'s made simple**
This is free to use software, but if you do like it, consider supporting me ❤️
[![sponsor me](https://badgen.net/badge/icon/sponsor?icon=github&label&color=gray)](https://github.com/sponsors/maraisr)
[![buy me a coffee](https://badgen.net/badge/icon/buymeacoffee?icon=buymeacoffee&label&color=gray)](https://www.buymeacoffee.com/marais)## ⚙️ Install
> Avaliable on [jsr](https://jsr.io/@mr/tracecontext), [NPM](https://npmjs.com/package/tctx) and
> [deno.land](https://deno.land/x/tracecontext)`npm add tctx`
## 🚀 Usage
```ts
// producerimport * 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`](/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](https://marais.io)