3个版本

0.0.3 2022年11月3日
0.0.2 2022年8月31日
0.0.1 2022年8月24日

#24 in #distributed-tracing

Download history 181/week @ 2024-04-14 6/week @ 2024-04-21 241/week @ 2024-04-28 283/week @ 2024-05-05 67/week @ 2024-05-12 68/week @ 2024-05-19 55/week @ 2024-05-26 145/week @ 2024-06-02 44/week @ 2024-06-09 42/week @ 2024-06-16 57/week @ 2024-06-23 74/week @ 2024-06-30 197/week @ 2024-07-07 48/week @ 2024-07-14 279/week @ 2024-07-21 132/week @ 2024-07-28

660 每月下载量

MIT 许可证

18KB
422 代码行,不包括注释

tctx

npm add tctx makes Trace Contexts simple


⚡ 功能

  • 轻量级查看.

  • 高效 — 子代之间有效利用内存,见 基准测试.

  • 生产友好 — 你是浏览器? make() 然后回家。

⚙️ 安装

npm add tctx

🚀 使用

// 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,
  },
});

💨 基准测试

通过 Node v17.9.0 的 /bench 目录


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)

许可证

MIT © Marais Rossouw

依赖

~165KB