{"name":"@opentelemetry/instrumentation-kafkajs","version":"0.15.0","keywords":["kafkajs","instrumentation","nodejs","opentelemetry","profiling","tracing"],"author":"OpenTelemetry Authors","license":"Apache-2.0","_id":"@opentelemetry/instrumentation-kafkajs@0.15.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"}],"homepage":"https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-kafkajs#readme","dist":{"shasum":"4ddca13d8eca96cca5a964b512bbba3fbb41130f","tarball":"http://registry-npm.ywwl.com/@opentelemetry/instrumentation-kafkajs/download/@opentelemetry/instrumentation-kafkajs-0.15.0.tgz","fileCount":24,"integrity":"sha512-bfMRg8ICe8ICZgP8Nezy8xxov/uBQ7518r2h7puwKUZeEqga+5F+hKVL9to0aVlPWTAiHgEjdOAdP1D5eRzvuw==","signatures":[{"sig":"MEYCIQDQAdlu8a3mcjOLlkQfWs8sGYrSSS3CDdLXcbYJ/ZUCQwIhAI+sZwHkJxYVsS7iR6itg25wgNq0i1e46eAYbXYQ+ZmB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2finstrumentation-kafkajs@0.15.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":126411,"size":24997,"noattachment":false,"key":"/@opentelemetry/instrumentation-kafkajs/-/@opentelemetry/instrumentation-kafkajs-0.15.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"f54a1ba1adf19fd2cbf9ddbdb32a3baca2ed328e","scripts":{"tdd":"npm run test -- --watch-extensions ts --watch","lint":"eslint . --ext=ts,js,mjs","test":"nyc --no-clean mocha --require @opentelemetry/contrib-test-utils 'test/**/*.test.ts'","clean":"rimraf build/*","compile":"tsc -p .","lint:fix":"eslint . --ext=ts,js,mjs --fix","lint:readme":"node ../../scripts/lint-readme","prepublishOnly":"npm run compile","version:update":"node ../../scripts/version-update.js","test-all-versions":"tav","test-merge-coverage":"nyc merge .nyc_output coverage/coverage-final.json","compile:with-dependencies":"nx run-many -t compile -p @opentelemetry/instrumentation-kafkajs"},"_npmUser":{"name":"dyladan","email":"dyladan@gmail.com"},"repository":{"url":"https://github.com/open-telemetry/opentelemetry-js-contrib.git","type":"git","directory":"packages/instrumentation-kafkajs"},"_npmVersion":"lerna/8.2.3/node@v18.20.8+x64 (linux)","description":"OpenTelemetry instrumentation for `kafkajs` messaging client for Apache Kafka","directories":{},"_nodeVersion":"18.20.8","dependencies":{"@opentelemetry/instrumentation":"^0.205.0","@opentelemetry/semantic-conventions":"^1.30.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"17.1.0","sinon":"15.2.0","rimraf":"5.0.10","kafkajs":"^2.2.4","typescript":"5.0.4","@types/node":"18.18.14","@types/mocha":"10.0.10","@types/sinon":"^17.0.0","test-all-versions":"6.1.0","@opentelemetry/api":"^1.3.0","@opentelemetry/sdk-trace-base":"^2.0.0","@opentelemetry/contrib-test-utils":"^0.51.0"},"peerDependencies":{"@opentelemetry/api":"^1.3.0"},"_npmOperationalInternal":{"tmp":"tmp/instrumentation-kafkajs_0.15.0_1757520405982_0.4708387016647928","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry `kafkajs` Instrumentation for Node.js\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis module provides automatic instrumentation for the [`kafkajs`](https://www.npmjs.com/package/kafkajs) package.\n\nIf total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](https://www.npmjs.com/package/@opentelemetry/sdk-node) for the most seamless instrumentation experience.\n\nCompatible with OpenTelemetry JS API and SDK `1.0+`.\n\n## Installation\n\n```bash\nnpm install --save @opentelemetry/instrumentation-kafkajs\n```\n\n### Supported versions\n\n- [`kafkajs`](https://www.npmjs.com/package/kafkajs) versions `>=0.3.0 <3`\n\n## Usage\n\n```js\nconst { NodeSDK } = require('@opentelemetry/sdk-node');\nconst { KafkaJsInstrumentation } = require('@opentelemetry/instrumentation-kafkajs');\n\nconst sdk = new NodeSDK({\n  instrumentations: [\n    new KafkaJsInstrumentation({\n      // see below for available configuration\n    }),\n  ],\n});\nsdk.start();\nprocess.once('beforeExit', async () => { await sdk.shutdown(); });\n```\n\n### Instrumentation Options\n\nYou can set the following:\n\n| Options        | Type                                   | Description                                                                                              |\n| -------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------- |\n| `producerHook` | `KafkaProducerCustomAttributeFunction` | Function called before a producer message is sent. Allows for adding custom attributes to the span.      |\n| `consumerHook` | `KafkaConsumerCustomAttributeFunction` | Function called before a consumer message is processed. Allows for adding custom attributes to the span. |\n\n## Semantic Conventions\n\nThis package uses `@opentelemetry/semantic-conventions` version `1.30+`, which implements Semantic Convention [Version 1.30.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.30.0/docs/README.md)\n\n### Spans Emitted\n\n| KafkaJS Object | Action                     | Span Kind | Span Name                  | Operation Type / Name |\n| -------------- | -------------------------- | --------- | -------------------------- | --------------------- |\n| Consumer       | `eachBatch`                | Client    | `poll <topic-name>`        | `receive` / `poll`    |\n| Consumer       | `eachBatch`, `eachMessage` | Consumer  | `process <topic-name>` [1] | `process` / `process` |\n| Producer       | `send`                     | Producer  | `send <topic-name>`        | `send` / `send`       |\n\n**[1] `process <topic-name>`:** In the context of `eachBatch`, this span will be emitted for each message in the batch but the timing (start, end, duration) will reflect the timing of the batch.\n\n### Metrics Emitted\n\n| KafkaJS Object        | Metric Name                           | Short Description                                                                                      |\n| --------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------ |\n| Consumer              | `messaging.process.duration`          | Duration of processing operation. [1]                                                                  |\n| Consumer              | `messaging.client.consumed.messages`  | Number of messages that were delivered to the application.                                             |\n| Consumer and Producer | `messaging.client.operation.duration` | Number of messages that were delivered to the application. (Only emitted for kafkajs@1.5.0 and later.) |\n| Producer              | `messaging.client.sent.messages`      | Number of messages producer attempted to send to the broker.                                           |\n\n**[1] `messaging.process.duration`:** In the context of `eachBatch`, this metric will be emitted once for each message but the value reflects the duration of the entire batch.\n\n### Attributes Collected\n\nThese attributes are added to both spans and metrics, where possible.\n\n| Attribute                            | Short Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `messaging.system`                   | An identifier for the messaging system being used (i.e. `\"kafka\"`).                                                                                                                                                                                                                                                                                                                                                                                                                                                |\n| `messaging.destination.name`         | The message destination name.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |\n| `messaging.operation.type`           | A string identifying the type of messaging operation.                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `messaging.operation.name`           | The system-specific name of the messaging operation.                                                                                                                                                                                                                                                                                                                                                                                                                                                               |\n| `messaging.operation.name`           | The system-specific name of the messaging operation.                                                                                                                                                                                                                                                                                                                                                                                                                                                               |\n| `messaging.kafka.message.key`        | A stringified value representing the key of the Kafka message (if present).                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n| `messaging.kafka.message.tombstone`  | A boolean that is true if the message is a tombstone.                                                                                                                                                                                                                                                                                                                                                                                                                                                              |\n| `messaging.kafka.offset`             | The offset of a record in the corresponding Kafka partition.                                                                                                                                                                                                                                                                                                                                                                                                                                                       |\n| `messaging.kafka.cluster.id`         | The Kafka cluster id, read from the broker metadata kafkajs's own producer/consumer already fetch — no separate connection is opened. On consumer spans this is always present once messages are flowing, since kafkajs refreshes metadata before it can fetch any record. On producer spans it's best-effort: omitted on a freshly created producer's first `send`/`sendBatch` (metadata isn't fetched until then), present on every send after. Also omitted if the broker predates KIP-78 (cluster id support). |\n| `messaging.destination.partition.id` | The identifier of the partition messages are sent to or received from, unique within the `messaging.destination.name`. **Note:** only available on producer spans.                                                                                                                                                                                                                                                                                                                                                 |\n\n## Useful links\n\n- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>\n- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>\n- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]\n\n## License\n\nApache 2.0 - See [LICENSE][license-url] for more information.\n\n[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions\n[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-kafkajs\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-kafkajs.svg\n","publish_time":1757520406158,"_cnpm_publish_time":1757520406158,"dist-tags":{"latest":"0.34.0"}}