@drazke/instrumentation-confluent-kafka-javascript

中文文档
1.0.0发布于 2025/10/23Apache-2.0TypeScriptCommonJS近 30 天下载 4038

OpenTelemetry instrumentation for confluent-kafka-javascript messaging client for Apache Kafka

原始使用文档
文档目录9 节
  1. Installation
  2. Supported versions
  3. Usage
  4. Instrumentation Options
  5. Semantic Conventions
  6. Spans Emitted
  7. Attributes Collected
  8. Useful links
  9. License

OpenTelemetry confluent-kafka-javascript Instrumentation for Node.js

NPM Published Version Apache License

Inspired by @eqxjs/kafka-server-node-rdkafka and @opentelemetry/instrumentation-kafkajs

This module provides automatic instrumentation for the @confluentinc/kafka-javascript package, which may be loaded using the @opentelemetry/sdk-trace-node package and is included in the @opentelemetry/auto-instrumentations-node bundle.

If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.

Compatible with OpenTelemetry JS API and SDK 1.0+.

Installation

npm install --save @drazke/instrumentation-confluent-kafka-javascript

Supported versions

Usage

const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const {
  ConfluentKafkaInstrumentation,
} = require('@drazke/instrumentation-confluent-kafka-javascript');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new ConfluentKafkaInstrumentation({
      // see below for available configuration
    }),
  ],
});

Instrumentation Options

You can set the following:

OptionsTypeDescription
producerHookKafkaProducerCustomAttributeFunctionFunction called before a producer message is sent. Allows for adding custom attributes to the span.
consumerHookKafkaConsumerCustomAttributeFunctionFunction called before a consumer message is processed. Allows for adding custom attributes to the span.

Semantic Conventions

This package uses @opentelemetry/semantic-conventions version 1.30+, which implements Semantic Convention Version 1.30.0

Spans Emitted

KafkaJS ObjectActionSpan KindSpan NameOperation Type / Name
ConsumerdataConsumer<topic-name>receive / received
Producerdelivery-reportProducer<topic-name>deliver / delivery-report
ProducerproduceProducer<topic-name>send / produce

Attributes Collected

These attributes are added to both spans and metrics, where possible.

AttributeShort Description
messaging.systemAn identifier for the messaging system being used (i.e. "kafka").
messaging.destination.nameThe message destination name.
messaging.operation.typeA string identifying the type of messaging operation.
messaging.operation.nameThe system-specific name of the messaging operation.
messaging.client.idThe client id.
messaging.kafka.message.keyA stringified value representing the key of the Kafka message (if present).
messaging.kafka.message.tombstoneA boolean that is true if the message is a tombstone.
messaging.kafka.offsetThe offset of a record in the corresponding Kafka partition.
messaging.destination.partition.idThe identifier of the partition messages are sent to or received from, unique within the messaging.destination.name. Note: only available on producer spans.

License

Apache 2.0 - See LICENSE for more information.

版本与发布记录

@drazke/instrumentation-confluent-kafka-javascript 共发布 8 个版本,首次发布于 2025/06/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2025/10/231.1 年前
0.2.12025/10/201.1 年前
0.2.02025/07/171.3 年前
0.1.42025/07/171.3 年前
0.1.32025/07/011.4 年前
0.1.22025/07/011.4 年前

关于 @drazke/instrumentation-confluent-kafka-javascript 的常见问题

@drazke/instrumentation-confluent-kafka-javascript 是什么?

OpenTelemetry instrumentation for confluent-kafka-javascript messaging client for Apache Kafka

如何安装 @drazke/instrumentation-confluent-kafka-javascript?

在项目目录运行 npm install @drazke/instrumentation-confluent-kafka-javascript,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@opentelemetry/api(^1.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@drazke/instrumentation-confluent-kafka-javascript 支持 TypeScript 吗?

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

@drazke/instrumentation-confluent-kafka-javascript 支持 ESM 还是 CommonJS?

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

@drazke/instrumentation-confluent-kafka-javascript 需要什么版本的 Node.js?

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

@drazke/instrumentation-confluent-kafka-javascript 可以商用吗?

@drazke/instrumentation-confluent-kafka-javascript 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@drazke/instrumentation-confluent-kafka-javascript 的下载量有多少?

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

@drazke/instrumentation-confluent-kafka-javascript 还在维护吗?

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