@bondsports/telemetry

中文文档
1.3.0发布于 2026/04/23ISCTypeScriptCommonJS近 30 天下载 2117

Package for everything opentelemetry related in bond sports

原始使用文档
文档目录9 节
  1. Motive
  2. example
  3. Tracing
  4. Metrics
  5. Trace-ID response headers (Express middleware)
  6. Configuration
  7. Common configuration
  8. Tracing configuration
  9. Metric configuration

Telemetry

Motive

This package goal is to make the experience of configuring and working with OpenTelemetry easier.

example

Below are short examples for tracing and metrics. More examples are available at the examples folder, and the various opentelemetry repos.

Tracing

The following code shows a simple example of how to work with tracing. please notice that you need to manually install any auto-instrumentation library that you require.

import { Tracing } from '@bondsports/telemetry';
import { trace } from '@opentelemetry/api';

const tracing = new Tracing();

tracing.start();

const tracer = trace.getTracer('tracing-name')

const span = tracer.startSpan('some-action');

span.setAttribute('some-attribute');

// DO STUFF

span.end();

tracing.stop().then(() => console.log('done'));

Another way for initialize tracing with custom resource:

import { Tracing } from '@bondsports/telemetry';
import { Resource } from '@opentelemetry/resources';

const resource = new Resource({ 'service.version': number, 'service.name': 'my-service-name' });

const tracing = new Tracing([], resource);
...

Metrics

The following code shows a simple example of how to work with metrics.

import { Metrics } from '@bondsports/telemetry';

const metrics = new Metrics('sample-meter');

const meter = metrics.start();

const counter = meter.createCounter('sample_counter');

counter.add(1);

metrics.stop().then(() => console.log('done'));

Trace-ID response headers (Express middleware)

getTraceIdHeaderMiddleware sets three response headers derived from the active OpenTelemetry span so clients and log-aggregation tools can correlate a single request across systems:

HeaderFormatMatches
X-Trace-Id32-char hex (W3C)trace_id field in application logs
Trace_Id32-char hex (W3C)trace_id field in application logs
X-Amzn-Trace-IdRoot=1-<8hex>-<24hex> (AWS X-Ray)the raw X-Amzn-Trace-Id header stored in AWS ALB access logs / OpenSearch

When the inbound request already carries an X-Amzn-Trace-Id header (typical behind an AWS ALB), its value is echoed verbatim so any Self= / Sampled= / custom fields set by intermediate hops are preserved. Otherwise the header is reconstructed from the active span's trace ID.

import express from 'express';
import { getTraceIdHeaderMiddleware } from '@bondsports/telemetry';

const app = express();
app.use(getTraceIdHeaderMiddleware());

Configuration

Common configuration

nameallowed valuedefault valuedescription
TELEMETRY_SERVICE_NAMEstringfrom package.jsonThe service name
TELEMETRY_SERVICE_VERSIONstringfrom package.jsonThe service version
TELEMETRY_HOST_NAMEstringos.hostname()The host name

Tracing configuration

nameallowed valuedefault valuedescription
TELEMETRY_TRACING_ENABLED'true', 'false''false'Should Tracing be enabled
TELEMETRY_TRACING_URL*stringhttp://localhost:55681/v1/traceThe URL to the OpenTelemetry Collector
TELEMETRY_TRACING_RATIOfloat1The amount of traces to sample

* required (only when tracing is enabled).

Metric configuration

nameallowed valuedefault valuedescription
TELEMETRY_METRICS_ENABLED'true', 'false''false'Should Metrics be enabled
TELEMETRY_METRICS_URL*stringhttp://localhost:55681/v1/metricsThe URL to the OpenTelemetry Collector
TELEMETRY_METRICS_INTERVALnumber15000The interval in miliseconds between sending data to the collector

* required (only when tracing is enabled).

版本与发布记录

@bondsports/telemetry 共发布 30 个版本,首次发布于 2022/07/31;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.3.0latest2026/04/236 个月前
1.2.32026/04/216 个月前
1.2.02026/04/216 个月前
1.1.62024/12/041.9 年前
1.1.6-test-new-trace-id-middleware2024/12/041.9 年前
1.1.52024/08/222 年前

其他发布通道:ido → 1.1.3-ido。

关于 @bondsports/telemetry 的常见问题

@bondsports/telemetry 是什么?

Package for everything opentelemetry related in bond sports

如何安装 @bondsports/telemetry?

在项目目录运行 npm install @bondsports/telemetry,或使用 pnpm add / yarn add / bun add。

@bondsports/telemetry 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bondsports/telemetry 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bondsports/telemetry 可以商用吗?

@bondsports/telemetry 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bondsports/telemetry 的下载量有多少?

根据 npm 官方下载统计,@bondsports/telemetry 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,117 次,日均约 71 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bondsports/telemetry 还在维护吗?

最新版本 1.3.0 发布于 2026/04/23(6 个月前);至今共发布 30 个版本,其中过去 12 个月发布了 3 个;首次发布于 2022/07/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。