@backendkit-labs/agent-otel

中文文档
0.1.10发布于 2026/10/27MITTypeScriptCommonJS零依赖近 30 天下载 2113

OpenTelemetry export for @backendkit-labs/agent-core traces: OTLP/HTTP exporter (no SDK needed) and an adapter for the OpenTelemetry API, with GenAI semantic conventions

原始使用文档
文档目录4 节
  1. What you get
  2. otlpHttpSpanExporter(options)
  3. otelApiSpanExporter(options)
  4. Verified

@backendkit-labs/agent-otel

OpenTelemetry export for the traces of @backendkit-labs/agent-core. Pick the exporter that fits how you run telemetry:

You haveUse
A collector or backend that speaks OTLP/HTTP (Jaeger, Tempo, Langfuse, Datadog, the OpenTelemetry Collector…) and no OpenTelemetry SDKotlpHttpSpanExporter
An OpenTelemetry SDK already registered in the process (auto-instrumentation, your own processors/exporters)otelApiSpanExporter
import { createBaseEngine } from '@backendkit-labs/agent-core';
import { otlpHttpSpanExporter } from '@backendkit-labs/agent-otel';

const exporter = otlpHttpSpanExporter({ endpoint: 'http://localhost:4318', serviceName: 'support-agent' });

const engine = createBaseEngine({
  // ...
  observability: { tracing: { exporter } },
});

// on shutdown
await exporter.shutdown();
import { otelApiSpanExporter } from '@backendkit-labs/agent-otel';   // needs @opentelemetry/api
observability: { tracing: { exporter: otelApiSpanExporter() } }

What you get

One trace per engine.run():

agent.run
└─ invoke_agent Main
   ├─ chat deepseek-chat          (tokens, model, provider, cost, cache tokens)
   ├─ execute_tool read_file      (success, duration — parallel tools overlap in time)
   └─ chat deepseek-chat

Attributes follow the OpenTelemetry GenAI semantic conventions: gen_ai.operation.name (invoke_agent / chat / execute_tool), gen_ai.request.model, gen_ai.provider.name, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.usage.cache_read.input_tokens, gen_ai.usage.cache_creation.input_tokens, gen_ai.agent.id/name, gen_ai.tool.name. Anything specific to agent-core (cost in USD, the original trace id, guardrail actions, why an extra LLM call was made) lives under bk.*, e.g. bk.cost_usd, bk.llm.purpose (context_summary, structured_output), bk.guardrail.<name>.<action>.

Conversation content is never exported. Spans carry names, durations, token counts and ids only: no prompts, answers, tool arguments or tool results.

Requires @backendkit-labs/agent-core with llm_call / tool_call spans (0.28+). With 0.27 you only get agent.run and invoke_agent.

otlpHttpSpanExporter(options)

Sends OTLP/JSON to <endpoint>/v1/traces. No SDK, no dependencies.

OptionDefault
endpointOTEL_EXPORTER_OTLP_ENDPOINT or http://localhost:4318/v1/traces is appended unless already there
headers–e.g. { Authorization: 'Basic …' }
serviceNameagentservice.name resource attribute
resourceAttributes–deployment.environment, service.version…
batchSize64spans buffered before sending
flushIntervalMs2000a partial batch is sent after this long (timer is unref'd)
timeoutMs10000per request
onError–a failed send is reported here and that batch is dropped; it never reaches the agent
fetchglobal fetchfor tests or custom transports

Returns a function with flush() and shutdown(). Sends are serialized, never overlapping. Ids are derived deterministically from agent-core's ids, so parent/child links are preserved.

otelApiSpanExporter(options)

Re-creates the spans through @opentelemetry/api (options.tracer, default trace.getTracer('@backendkit-labs/agent-core')), so they reach whatever your SDK exports to.

The OpenTelemetry API cannot choose a span's id, and a child must be created from its parent's real span. agent-core exports spans as they end (children first), so this adapter holds a trace's spans until the root agent.run ends and then creates the tree parents-first with the original start/end times. Consequences:

  • Spans of a run appear in your backend when the run finishes, not while it runs.
  • A run that never ends (crash) leaves its spans buffered: call exporter.flush() on shutdown (spans whose parent never arrived become roots). maxBufferedSpans (default 5000) bounds memory.
  • @opentelemetry/api is an optional peer dependency; without it the exporter throws a clear error at creation.

Verified

Unit tests plus a run of a real engine through both exporters. The API adapter was also checked against a real @opentelemetry/sdk-trace-base provider: one trace, correct hierarchy, parallel tool spans overlapping in time.

版本与发布记录

@backendkit-labs/agent-otel 共发布 12 个版本,首次发布于 2026/10/22;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.1.10latest2026/10/2712 天前
0.1.92026/10/2712 天前
0.1.82026/10/2712 天前
0.1.72026/10/2712 天前
0.1.62026/10/2612 天前
0.1.52026/10/2414 天前

关于 @backendkit-labs/agent-otel 的常见问题

@backendkit-labs/agent-otel 是什么?

OpenTelemetry export for @backendkit-labs/agent-core traces: OTLP/HTTP exporter (no SDK needed) and an adapter for the OpenTelemetry API, with GenAI semantic conventions

如何安装 @backendkit-labs/agent-otel?

在项目目录运行 npm install @backendkit-labs/agent-otel,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@backendkit-labs/agent-core(>=0.27.0 <0.38.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@backendkit-labs/agent-otel 支持 TypeScript 吗?

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

@backendkit-labs/agent-otel 支持 ESM 还是 CommonJS?

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

@backendkit-labs/agent-otel 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@backendkit-labs/agent-otel 可以商用吗?

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

@backendkit-labs/agent-otel 的下载量有多少?

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

@backendkit-labs/agent-otel 还在维护吗?

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