# opentelemetry-instrumentation-kafkajs

> open telemetry instrumentation for the `kafkajs` kafka client

Latest version **0.41.0** (published 2024-05-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install opentelemetry-instrumentation-kafkajs
pnpm add opentelemetry-instrumentation-kafkajs
yarn add opentelemetry-instrumentation-kafkajs
bun add opentelemetry-instrumentation-kafkajs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.41.0 |
| Published | 2024-05-21 |
| First published | 2021-02-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 52.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 168 |
| Maintainers | aspecto-release-bot |
| Keywords | kafka, opentelemetry, kafkajs |

## Links

- npm: https://www.npmjs.com/package/opentelemetry-instrumentation-kafkajs
- Repository: https://github.com/aspecto-io/opentelemetry-ext-js
- Issues: https://github.com/aspecto-io/opentelemetry-ext-js/issues
- npm.io page: https://npm.io/package/opentelemetry-instrumentation-kafkajs

## Dependencies (2)

- [@opentelemetry/instrumentation](https://npm.io/package/@opentelemetry/instrumentation.md) ^0.51.1
- [@opentelemetry/semantic-conventions](https://npm.io/package/@opentelemetry/semantic-conventions.md) ^1.24.1

## Recent versions

- 0.41.0 (latest) — 2024-05-21
- 0.0.0-2024-05-16--12-47 (alpha) — 2024-05-16
- 0.4.1-aws-import-one-serivce.0 (canary) — 2021-04-28
- 0.40.0 — 2023-10-17
- 0.0.0-2023-10-17--13-06 — 2023-10-17
- 0.39.1 — 2023-07-27
- 0.35.1 — 2023-07-27
- 0.0.0-2023-07-26--14-48 — 2023-07-26
- 0.35.0 — 2023-03-01
- 0.34.0 — 2022-11-21
- 0.32.0 — 2022-10-18
- 0.0.0-2022-07-11--08-09 — 2022-07-11
- 0.29.0 — 2022-06-28
- 0.28.0 — 2022-06-02
- 0.27.1 — 2022-04-13
- … 54 more at https://npm.io/package/opentelemetry-instrumentation-kafkajs/versions

## README

# OpenTelemetry kafkajs Instrumentation for Node.js
[![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-kafkajs.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-kafkajs)

This module provides automatic instrumentation for [`kafkajs`](https://kafka.js.org/).

## Installation

```
npm install --save opentelemetry-instrumentation-kafkajs
```

## Usage

For further automatic instrumentation instruction see the [@opentelemetry/instrumentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation) package.

```js
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { KafkaJsInstrumentation } = require('opentelemetry-instrumentation-kafkajs');

const tracerProvider = new NodeTracerProvider({
  // be sure to disable old plugin
  plugins: {
    kafkajs: { enabled: false, path: 'opentelemetry-plugin-kafkajs' }
  }
});

registerInstrumentations({
  tracerProvider,
  instrumentations: [
    new KafkaJsInstrumentation({
      // see under for available configuration
    })
  ]
});
```

### kafkajs Instrumentation Options

kafkajs instrumentation has few options available to choose from. You can set the following:

| Options        | Type                                   | Description                                                                                     |
| -------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `producerHook` | `KafkaProducerCustomAttributeFunction` | Hook called before producer message is sent, which allow to add custom attributes to span.      |
| `consumerHook` | `KafkaConsumerCustomAttributeFunction` | Hook called before consumer message is processed, which allow to add custom attributes to span. |
| `moduleVersionAttributeName` | `string` | If passed, a span attribute will be added to all spans with key of the provided `moduleVersionAttributeName` and value of the patched module version |

---

This extension (and many others) was developed by [Aspecto](https://www.aspecto.io/) with ❤️

---
_Source: https://npm.io/package/opentelemetry-instrumentation-kafkajs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
