@opentelemetry/instrumentation-kafkajs 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,13 +17,15 @@ npm install --save @opentelemetry/instrumentation-kafkajs
17
17
 
18
18
  ### Supported versions
19
19
 
20
- - [`kafkajs`](https://www.npmjs.com/package/kafkajs) versions `>=0.1.0 <3`
20
+ - [`kafkajs`](https://www.npmjs.com/package/kafkajs) versions `>=0.3.0 <3`
21
21
 
22
22
  ## Usage
23
23
 
24
24
  ```js
25
25
  const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
26
- const { KafkaJsInstrumentation } = require('@opentelemetry/instrumentation-kafkajs');
26
+ const {
27
+ KafkaJsInstrumentation,
28
+ } = require('@opentelemetry/instrumentation-kafkajs');
27
29
  const { registerInstrumentations } = require('@opentelemetry/instrumentation');
28
30
 
29
31
  const provider = new NodeTracerProvider();
@@ -42,22 +44,51 @@ registerInstrumentations({
42
44
 
43
45
  You can set the following:
44
46
 
45
- | Options | Type | Description |
46
- | ---------------------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
47
- | `producerHook` | `KafkaProducerCustomAttributeFunction` | Function called before a producer message is sent. Allows for adding custom attributes to the span. |
48
- | `consumerHook` | `KafkaConsumerCustomAttributeFunction` | Function called before a consumer message is processed. Allows for adding custom attributes to the span. |
47
+ | Options | Type | Description |
48
+ | -------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------- |
49
+ | `producerHook` | `KafkaProducerCustomAttributeFunction` | Function called before a producer message is sent. Allows for adding custom attributes to the span. |
50
+ | `consumerHook` | `KafkaConsumerCustomAttributeFunction` | Function called before a consumer message is processed. Allows for adding custom attributes to the span. |
49
51
 
50
52
  ## Semantic Conventions
51
53
 
52
- This package uses `@opentelemetry/semantic-conventions` version `1.24+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
54
+ This 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)
53
55
 
54
- Attributes collected:
56
+ ### Spans Emitted
55
57
 
56
- | Attribute | Short Description |
57
- | -----------------------------| ----------------------------------------------------- |
58
- | `messaging.system` | An identifier for the messaging system being used. |
59
- | `messaging.destination` | The message destination name. |
60
- | `messaging.operation` | A string identifying the kind of messaging operation. |
58
+ | KafkaJS Object | Action | Span Kind | Span Name | Operation Type / Name |
59
+ | -------------- | -------------------------- | --------- | -------------------------- | --------------------- |
60
+ | Consumer | `eachBatch` | Client | `poll <topic-name>` | `receive` / `poll` |
61
+ | Consumer | `eachBatch`, `eachMessage` | Consumer | `process <topic-name>` [1] | `process` / `process` |
62
+ | Producer | `send` | Producer | `send <topic-name>` | `send` / `send` |
63
+
64
+ **[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.
65
+
66
+ ### Metrics Emitted
67
+
68
+ | KafkaJS Object | Metric Name | Short Description |
69
+ | --------------------- | ------------------------------------- | ------------------------------------------------------------ |
70
+ | Consumer | `messaging.process.duration` | Duration of processing operation. [1] |
71
+ | Consumer | `messaging.client.consumed.messages` | Number of messages that were delivered to the application. |
72
+ | 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.) |
73
+ | Producer | `messaging.client.sent.messages` | Number of messages producer attempted to send to the broker. |
74
+
75
+ **[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.
76
+
77
+ ### Attributes Collected
78
+
79
+ These attributes are added to both spans and metrics, where possible.
80
+
81
+ | Attribute | Short Description |
82
+ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
83
+ | `messaging.system` | An identifier for the messaging system being used (i.e. `"kafka"`). |
84
+ | `messaging.destination.name` | The message destination name. |
85
+ | `messaging.operation.type` | A string identifying the type of messaging operation. |
86
+ | `messaging.operation.name` | The system-specific name of the messaging operation. |
87
+ | `messaging.operation.name` | The system-specific name of the messaging operation. |
88
+ | `messaging.kafka.message.key` | A stringified value representing the key of the Kafka message (if present). |
89
+ | `messaging.kafka.message.tombstone` | A boolean that is true if the message is a tombstone. |
90
+ | `messaging.kafka.offset` | The offset of a record in the corresponding Kafka partition. |
91
+ | `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. |
61
92
 
62
93
  ## Useful links
63
94
 
@@ -1,9 +1,16 @@
1
- import { KafkaJsInstrumentationConfig } from './types';
2
1
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
+ import { KafkaJsInstrumentationConfig } from './types';
3
3
  export declare class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumentationConfig> {
4
+ private _clientDuration;
5
+ private _sentMessages;
6
+ private _consumedMessages;
7
+ private _processDuration;
4
8
  constructor(config?: KafkaJsInstrumentationConfig);
9
+ _updateMetricInstruments(): void;
5
10
  protected init(): InstrumentationNodeModuleDefinition;
6
11
  private _getConsumerPatch;
12
+ private _setKafkaEventListeners;
13
+ private _recordClientDurationMetric;
7
14
  private _getProducerPatch;
8
15
  private _getConsumerRunPatch;
9
16
  private _getConsumerEachMessagePatch;
@@ -17,15 +17,46 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.KafkaJsInstrumentation = void 0;
19
19
  const api_1 = require("@opentelemetry/api");
20
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
20
21
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
22
+ const internal_types_1 = require("./internal-types");
23
+ const propagator_1 = require("./propagator");
24
+ const semconv_1 = require("./semconv");
21
25
  /** @knipignore */
22
26
  const version_1 = require("./version");
23
- const propagator_1 = require("./propagator");
24
- const instrumentation_1 = require("@opentelemetry/instrumentation");
27
+ function prepareCounter(meter, value, attributes) {
28
+ return (errorType) => {
29
+ meter.add(value, {
30
+ ...attributes,
31
+ ...(errorType ? { [semantic_conventions_1.ATTR_ERROR_TYPE]: errorType } : {}),
32
+ });
33
+ };
34
+ }
35
+ function prepareDurationHistogram(meter, value, attributes) {
36
+ return (errorType) => {
37
+ meter.record((Date.now() - value) / 1000, {
38
+ ...attributes,
39
+ ...(errorType ? { [semantic_conventions_1.ATTR_ERROR_TYPE]: errorType } : {}),
40
+ });
41
+ };
42
+ }
43
+ const HISTOGRAM_BUCKET_BOUNDARIES = [
44
+ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10,
45
+ ];
25
46
  class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
47
+ _clientDuration;
48
+ _sentMessages;
49
+ _consumedMessages;
50
+ _processDuration;
26
51
  constructor(config = {}) {
27
52
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
28
53
  }
54
+ _updateMetricInstruments() {
55
+ this._clientDuration = this.meter.createHistogram(semconv_1.METRIC_MESSAGING_CLIENT_OPERATION_DURATION, { advice: { explicitBucketBoundaries: HISTOGRAM_BUCKET_BOUNDARIES } });
56
+ this._sentMessages = this.meter.createCounter(semconv_1.METRIC_MESSAGING_CLIENT_SENT_MESSAGES);
57
+ this._consumedMessages = this.meter.createCounter(semconv_1.METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES);
58
+ this._processDuration = this.meter.createHistogram(semconv_1.METRIC_MESSAGING_PROCESS_DURATION, { advice: { explicitBucketBoundaries: HISTOGRAM_BUCKET_BOUNDARIES } });
59
+ }
29
60
  init() {
30
61
  const unpatch = (moduleExports) => {
31
62
  if ((0, instrumentation_1.isWrapped)(moduleExports?.Kafka?.prototype.producer)) {
@@ -35,7 +66,7 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
35
66
  this._unwrap(moduleExports.Kafka.prototype, 'consumer');
36
67
  }
37
68
  };
38
- const module = new instrumentation_1.InstrumentationNodeModuleDefinition('kafkajs', ['>=0.1.0 <3'], (moduleExports) => {
69
+ const module = new instrumentation_1.InstrumentationNodeModuleDefinition('kafkajs', ['>=0.3.0 <3'], (moduleExports) => {
39
70
  unpatch(moduleExports);
40
71
  this._wrap(moduleExports?.Kafka?.prototype, 'producer', this._getProducerPatch());
41
72
  this._wrap(moduleExports?.Kafka?.prototype, 'consumer', this._getConsumerPatch());
@@ -52,10 +83,29 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
52
83
  instrumentation._unwrap(newConsumer, 'run');
53
84
  }
54
85
  instrumentation._wrap(newConsumer, 'run', instrumentation._getConsumerRunPatch());
86
+ instrumentation._setKafkaEventListeners(newConsumer);
55
87
  return newConsumer;
56
88
  };
57
89
  };
58
90
  }
91
+ _setKafkaEventListeners(kafkaObj) {
92
+ if (kafkaObj[internal_types_1.EVENT_LISTENERS_SET])
93
+ return;
94
+ // The REQUEST Consumer event was added in kafkajs@1.5.0.
95
+ if (kafkaObj.events?.REQUEST) {
96
+ kafkaObj.on(kafkaObj.events.REQUEST, this._recordClientDurationMetric.bind(this));
97
+ }
98
+ kafkaObj[internal_types_1.EVENT_LISTENERS_SET] = true;
99
+ }
100
+ _recordClientDurationMetric(event) {
101
+ const [address, port] = event.payload.broker.split(':');
102
+ this._clientDuration.record(event.payload.duration / 1000, {
103
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
104
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: `${event.payload.apiName}`,
105
+ [semantic_conventions_1.ATTR_SERVER_ADDRESS]: address,
106
+ [semantic_conventions_1.ATTR_SERVER_PORT]: Number.parseInt(port, 10),
107
+ });
108
+ }
59
109
  _getProducerPatch() {
60
110
  const instrumentation = this;
61
111
  return (original) => {
@@ -69,6 +119,7 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
69
119
  instrumentation._unwrap(newProducer, 'send');
70
120
  }
71
121
  instrumentation._wrap(newProducer, 'send', instrumentation._getProducerSendPatch());
122
+ instrumentation._setKafkaEventListeners(newProducer);
72
123
  return newProducer;
73
124
  };
74
125
  };
@@ -100,11 +151,33 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
100
151
  return function eachMessage(...args) {
101
152
  const payload = args[0];
102
153
  const propagatedContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, payload.message.headers, propagator_1.bufferTextMapGetter);
103
- const span = instrumentation._startConsumerSpan(payload.topic, payload.message, semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, propagatedContext);
154
+ const span = instrumentation._startConsumerSpan({
155
+ topic: payload.topic,
156
+ message: payload.message,
157
+ operationType: semconv_1.MESSAGING_OPERATION_TYPE_VALUE_PROCESS,
158
+ ctx: propagatedContext,
159
+ attributes: {
160
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.partition),
161
+ },
162
+ });
163
+ const pendingMetrics = [
164
+ prepareDurationHistogram(instrumentation._processDuration, Date.now(), {
165
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
166
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'process',
167
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: payload.topic,
168
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.partition),
169
+ }),
170
+ prepareCounter(instrumentation._consumedMessages, 1, {
171
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
172
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'process',
173
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: payload.topic,
174
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.partition),
175
+ }),
176
+ ];
104
177
  const eachMessagePromise = api_1.context.with(api_1.trace.setSpan(propagatedContext, span), () => {
105
178
  return original.apply(this, args);
106
179
  });
107
- return instrumentation._endSpansOnPromise([span], eachMessagePromise);
180
+ return instrumentation._endSpansOnPromise([span], pendingMetrics, eachMessagePromise);
108
181
  };
109
182
  };
110
183
  }
@@ -114,9 +187,28 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
114
187
  return function eachBatch(...args) {
115
188
  const payload = args[0];
116
189
  // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers
117
- const receivingSpan = instrumentation._startConsumerSpan(payload.batch.topic, undefined, semantic_conventions_1.MESSAGINGOPERATIONVALUES_RECEIVE, api_1.ROOT_CONTEXT);
190
+ const receivingSpan = instrumentation._startConsumerSpan({
191
+ topic: payload.batch.topic,
192
+ message: undefined,
193
+ operationType: semconv_1.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,
194
+ ctx: api_1.ROOT_CONTEXT,
195
+ attributes: {
196
+ [semconv_1.ATTR_MESSAGING_BATCH_MESSAGE_COUNT]: payload.batch.messages.length,
197
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.batch.partition),
198
+ },
199
+ });
118
200
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), receivingSpan), () => {
119
- const spans = payload.batch.messages.map((message) => {
201
+ const startTime = Date.now();
202
+ const spans = [];
203
+ const pendingMetrics = [
204
+ prepareCounter(instrumentation._consumedMessages, payload.batch.messages.length, {
205
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
206
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'process',
207
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: payload.batch.topic,
208
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.batch.partition),
209
+ }),
210
+ ];
211
+ payload.batch.messages.forEach(message => {
120
212
  const propagatedContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, message.headers, propagator_1.bufferTextMapGetter);
121
213
  const spanContext = api_1.trace
122
214
  .getSpan(propagatedContext)
@@ -127,11 +219,25 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
127
219
  context: spanContext,
128
220
  };
129
221
  }
130
- return instrumentation._startConsumerSpan(payload.batch.topic, message, semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, undefined, origSpanLink);
222
+ spans.push(instrumentation._startConsumerSpan({
223
+ topic: payload.batch.topic,
224
+ message,
225
+ operationType: semconv_1.MESSAGING_OPERATION_TYPE_VALUE_PROCESS,
226
+ link: origSpanLink,
227
+ attributes: {
228
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.batch.partition),
229
+ },
230
+ }));
231
+ pendingMetrics.push(prepareDurationHistogram(instrumentation._processDuration, startTime, {
232
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
233
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'process',
234
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: payload.batch.topic,
235
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(payload.batch.partition),
236
+ }));
131
237
  });
132
238
  const batchMessagePromise = original.apply(this, args);
133
239
  spans.unshift(receivingSpan);
134
- return instrumentation._endSpansOnPromise(spans, batchMessagePromise);
240
+ return instrumentation._endSpansOnPromise(spans, pendingMetrics, batchMessagePromise);
135
241
  });
136
242
  };
137
243
  };
@@ -142,11 +248,25 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
142
248
  return function sendBatch(...args) {
143
249
  const batch = args[0];
144
250
  const messages = batch.topicMessages || [];
145
- const spans = messages
146
- .map(topicMessage => topicMessage.messages.map(message => instrumentation._startProducerSpan(topicMessage.topic, message)))
147
- .reduce((acc, val) => acc.concat(val), []);
251
+ const spans = [];
252
+ const pendingMetrics = [];
253
+ messages.forEach(topicMessage => {
254
+ topicMessage.messages.forEach(message => {
255
+ spans.push(instrumentation._startProducerSpan(topicMessage.topic, message));
256
+ pendingMetrics.push(prepareCounter(instrumentation._sentMessages, 1, {
257
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
258
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'send',
259
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: topicMessage.topic,
260
+ ...(message.partition !== undefined
261
+ ? {
262
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(message.partition),
263
+ }
264
+ : {}),
265
+ }));
266
+ });
267
+ });
148
268
  const origSendResult = original.apply(this, args);
149
- return instrumentation._endSpansOnPromise(spans, origSendResult);
269
+ return instrumentation._endSpansOnPromise(spans, pendingMetrics, origSendResult);
150
270
  };
151
271
  };
152
272
  }
@@ -158,40 +278,74 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
158
278
  const spans = record.messages.map(message => {
159
279
  return instrumentation._startProducerSpan(record.topic, message);
160
280
  });
281
+ const pendingMetrics = record.messages.map(m => prepareCounter(instrumentation._sentMessages, 1, {
282
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
283
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'send',
284
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: record.topic,
285
+ ...(m.partition !== undefined
286
+ ? {
287
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(m.partition),
288
+ }
289
+ : {}),
290
+ }));
161
291
  const origSendResult = original.apply(this, args);
162
- return instrumentation._endSpansOnPromise(spans, origSendResult);
292
+ return instrumentation._endSpansOnPromise(spans, pendingMetrics, origSendResult);
163
293
  };
164
294
  };
165
295
  }
166
- _endSpansOnPromise(spans, sendPromise) {
296
+ _endSpansOnPromise(spans, pendingMetrics, sendPromise) {
167
297
  return Promise.resolve(sendPromise)
298
+ .then(result => {
299
+ pendingMetrics.forEach(m => m());
300
+ return result;
301
+ })
168
302
  .catch(reason => {
169
303
  let errorMessage;
170
- if (typeof reason === 'string')
304
+ let errorType = semantic_conventions_1.ERROR_TYPE_VALUE_OTHER;
305
+ if (typeof reason === 'string' || reason === undefined) {
171
306
  errorMessage = reason;
307
+ }
172
308
  else if (typeof reason === 'object' &&
173
- Object.prototype.hasOwnProperty.call(reason, 'message'))
309
+ Object.prototype.hasOwnProperty.call(reason, 'message')) {
174
310
  errorMessage = reason.message;
175
- spans.forEach(span => span.setStatus({
176
- code: api_1.SpanStatusCode.ERROR,
177
- message: errorMessage,
178
- }));
311
+ errorType = reason.constructor.name;
312
+ }
313
+ pendingMetrics.forEach(m => m(errorType));
314
+ spans.forEach(span => {
315
+ span.setAttribute(semantic_conventions_1.ATTR_ERROR_TYPE, errorType);
316
+ span.setStatus({
317
+ code: api_1.SpanStatusCode.ERROR,
318
+ message: errorMessage,
319
+ });
320
+ });
179
321
  throw reason;
180
322
  })
181
323
  .finally(() => {
182
324
  spans.forEach(span => span.end());
183
325
  });
184
326
  }
185
- _startConsumerSpan(topic, message, operation, context, link) {
186
- const span = this.tracer.startSpan(topic, {
187
- kind: api_1.SpanKind.CONSUMER,
327
+ _startConsumerSpan({ topic, message, operationType, ctx, link, attributes, }) {
328
+ const operationName = operationType === semconv_1.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE
329
+ ? 'poll' // for batch processing spans
330
+ : operationType; // for individual message processing spans
331
+ const span = this.tracer.startSpan(`${operationName} ${topic}`, {
332
+ kind: operationType === semconv_1.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE
333
+ ? api_1.SpanKind.CLIENT
334
+ : api_1.SpanKind.CONSUMER,
188
335
  attributes: {
189
- [semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
190
- [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: topic,
191
- [semantic_conventions_1.SEMATTRS_MESSAGING_OPERATION]: operation,
336
+ ...attributes,
337
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
338
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: topic,
339
+ [semconv_1.ATTR_MESSAGING_OPERATION_TYPE]: operationType,
340
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: operationName,
341
+ [semconv_1.ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key
342
+ ? String(message.key)
343
+ : undefined,
344
+ [semconv_1.ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : undefined,
345
+ [semconv_1.ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,
192
346
  },
193
347
  links: link ? [link] : [],
194
- }, context);
348
+ }, ctx);
195
349
  const { consumerHook } = this.getConfig();
196
350
  if (consumerHook && message) {
197
351
  (0, instrumentation_1.safeExecuteInTheMiddle)(() => consumerHook(span, { topic, message }), e => {
@@ -202,11 +356,20 @@ class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
202
356
  return span;
203
357
  }
204
358
  _startProducerSpan(topic, message) {
205
- const span = this.tracer.startSpan(topic, {
359
+ const span = this.tracer.startSpan(`send ${topic}`, {
206
360
  kind: api_1.SpanKind.PRODUCER,
207
361
  attributes: {
208
- [semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
209
- [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: topic,
362
+ [semconv_1.ATTR_MESSAGING_SYSTEM]: semconv_1.MESSAGING_SYSTEM_VALUE_KAFKA,
363
+ [semconv_1.ATTR_MESSAGING_DESTINATION_NAME]: topic,
364
+ [semconv_1.ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key
365
+ ? String(message.key)
366
+ : undefined,
367
+ [semconv_1.ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : undefined,
368
+ [semconv_1.ATTR_MESSAGING_DESTINATION_PARTITION_ID]: message.partition !== undefined
369
+ ? String(message.partition)
370
+ : undefined,
371
+ [semconv_1.ATTR_MESSAGING_OPERATION_NAME]: 'send',
372
+ [semconv_1.ATTR_MESSAGING_OPERATION_TYPE]: semconv_1.MESSAGING_OPERATION_TYPE_VALUE_SEND,
210
373
  },
211
374
  });
212
375
  message.headers = message.headers ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAU4B;AAC5B,8EAM6C;AAa7C,kBAAkB;AAClB,uCAA0D;AAC1D,6CAAmD;AACnD,oEAKwC;AAExC,MAAa,sBAAuB,SAAQ,qCAAiD;IAC3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAES,IAAI;QACZ,MAAM,OAAO,GAAG,CAAC,aAA6B,EAAE,EAAE;YAChD,IAAI,IAAA,2BAAS,EAAC,aAAa,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE;gBACvD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;aACzD;YACD,IAAI,IAAA,2BAAS,EAAC,aAAa,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE;gBACvD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;aACzD;QACH,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,qDAAmC,CACpD,SAAS,EACT,CAAC,YAAY,CAAC,EACd,CAAC,aAA6B,EAAE,EAAE;YAChC,OAAO,CAAC,aAAa,CA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AC,EACD,IAAI,CACL,CAAC;SACH;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,kBAAkB,CAAC,KAAa,EAAE,OAAgB;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE;YACxC,IAAI,EAAE,cAAQ,CAAC,QAAQ;YACvB,UAAU,EAAE;gBACV,CAAC,gDAAyB,CAAC,EAAE,OAAO;gBACpC,CAAC,qDAA8B,CAAC,EAAE,KAAK;aACxC;SACF,CAAC,CAAC;QAEH,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACxC,iBAAW,CAAC,MAAM,CAAC,WAAK,CAAC,OAAO,CAAC,aAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAE3E,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,YAAY,EAAE;YAChB,IAAA,wCAAsB,EACpB,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAC5C,CAAC,CAAC,EAAE;gBACF,IAAI,CAAC;oBAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC;YACnD,CAAC,EACD,IAAI,CACL,CAAC;SACH;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/VD,wDA+VC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SpanKind,\n Span,\n SpanStatusCode,\n Context,\n propagation,\n Link,\n trace,\n context,\n ROOT_CONTEXT,\n} from '@opentelemetry/api';\nimport {\n MESSAGINGOPERATIONVALUES_PROCESS,\n MESSAGINGOPERATIONVALUES_RECEIVE,\n SEMATTRS_MESSAGING_SYSTEM,\n SEMATTRS_MESSAGING_DESTINATION,\n SEMATTRS_MESSAGING_OPERATION,\n} from '@opentelemetry/semantic-conventions';\nimport type * as kafkaJs from 'kafkajs';\nimport type {\n EachBatchHandler,\n EachMessageHandler,\n Producer,\n RecordMetadata,\n Message,\n ConsumerRunConfig,\n KafkaMessage,\n Consumer,\n} from 'kafkajs';\nimport { KafkaJsInstrumentationConfig } from './types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport { bufferTextMapGetter } from './propagator';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n isWrapped,\n} from '@opentelemetry/instrumentation';\n\nexport class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumentationConfig> {\n constructor(config: KafkaJsInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init() {\n const unpatch = (moduleExports: typeof kafkaJs) => {\n if (isWrapped(moduleExports?.Kafka?.prototype.producer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'producer');\n }\n if (isWrapped(moduleExports?.Kafka?.prototype.consumer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'consumer');\n }\n };\n\n const module = new InstrumentationNodeModuleDefinition(\n 'kafkajs',\n ['>=0.1.0 <3'],\n (moduleExports: typeof kafkaJs) => {\n unpatch(moduleExports);\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'producer',\n this._getProducerPatch()\n );\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'consumer',\n this._getConsumerPatch()\n );\n\n return moduleExports;\n },\n unpatch\n );\n return module;\n }\n\n private _getConsumerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['consumer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['consumer']>\n ) {\n const newConsumer: Consumer = original.apply(this, args);\n\n if (isWrapped(newConsumer.run)) {\n instrumentation._unwrap(newConsumer, 'run');\n }\n\n instrumentation._wrap(\n newConsumer,\n 'run',\n instrumentation._getConsumerRunPatch()\n );\n\n return newConsumer;\n };\n };\n }\n\n private _getProducerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['producer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['producer']>\n ) {\n const newProducer: Producer = original.apply(this, args);\n\n if (isWrapped(newProducer.sendBatch)) {\n instrumentation._unwrap(newProducer, 'sendBatch');\n }\n instrumentation._wrap(\n newProducer,\n 'sendBatch',\n instrumentation._getProducerSendBatchPatch()\n );\n\n if (isWrapped(newProducer.send)) {\n instrumentation._unwrap(newProducer, 'send');\n }\n instrumentation._wrap(\n newProducer,\n 'send',\n instrumentation._getProducerSendPatch()\n );\n\n return newProducer;\n };\n };\n }\n\n private _getConsumerRunPatch() {\n const instrumentation = this;\n return (original: Consumer['run']) => {\n return function run(\n this: Consumer,\n ...args: Parameters<Consumer['run']>\n ): ReturnType<Consumer['run']> {\n const config = args[0];\n if (config?.eachMessage) {\n if (isWrapped(config.eachMessage)) {\n instrumentation._unwrap(config, 'eachMessage');\n }\n instrumentation._wrap(\n config,\n 'eachMessage',\n instrumentation._getConsumerEachMessagePatch()\n );\n }\n if (config?.eachBatch) {\n if (isWrapped(config.eachBatch)) {\n instrumentation._unwrap(config, 'eachBatch');\n }\n instrumentation._wrap(\n config,\n 'eachBatch',\n instrumentation._getConsumerEachBatchPatch()\n );\n }\n return original.call(this, config);\n };\n };\n }\n\n private _getConsumerEachMessagePatch() {\n const instrumentation = this;\n return (original: ConsumerRunConfig['eachMessage']) => {\n return function eachMessage(\n this: unknown,\n ...args: Parameters<EachMessageHandler>\n ): Promise<void> {\n const payload = args[0];\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n payload.message.headers,\n bufferTextMapGetter\n );\n const span = instrumentation._startConsumerSpan(\n payload.topic,\n payload.message,\n MESSAGINGOPERATIONVALUES_PROCESS,\n propagatedContext\n );\n\n const eachMessagePromise = context.with(\n trace.setSpan(propagatedContext, span),\n () => {\n return original!.apply(this, args);\n }\n );\n return instrumentation._endSpansOnPromise([span], eachMessagePromise);\n };\n };\n }\n\n private _getConsumerEachBatchPatch() {\n return (original: ConsumerRunConfig['eachBatch']) => {\n const instrumentation = this;\n return function eachBatch(\n this: unknown,\n ...args: Parameters<EachBatchHandler>\n ): Promise<void> {\n const payload = args[0];\n // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers\n const receivingSpan = instrumentation._startConsumerSpan(\n payload.batch.topic,\n undefined,\n MESSAGINGOPERATIONVALUES_RECEIVE,\n ROOT_CONTEXT\n );\n return context.with(\n trace.setSpan(context.active(), receivingSpan),\n () => {\n const spans = payload.batch.messages.map(\n (message: KafkaMessage) => {\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n message.headers,\n bufferTextMapGetter\n );\n const spanContext = trace\n .getSpan(propagatedContext)\n ?.spanContext();\n let origSpanLink: Link | undefined;\n if (spanContext) {\n origSpanLink = {\n context: spanContext,\n };\n }\n return instrumentation._startConsumerSpan(\n payload.batch.topic,\n message,\n MESSAGINGOPERATIONVALUES_PROCESS,\n undefined,\n origSpanLink\n );\n }\n );\n const batchMessagePromise: Promise<void> = original!.apply(\n this,\n args\n );\n spans.unshift(receivingSpan);\n return instrumentation._endSpansOnPromise(\n spans,\n batchMessagePromise\n );\n }\n );\n };\n };\n }\n\n private _getProducerSendBatchPatch() {\n const instrumentation = this;\n return (original: Producer['sendBatch']) => {\n return function sendBatch(\n this: Producer,\n ...args: Parameters<Producer['sendBatch']>\n ): ReturnType<Producer['sendBatch']> {\n const batch = args[0];\n const messages = batch.topicMessages || [];\n const spans: Span[] = messages\n .map(topicMessage =>\n topicMessage.messages.map(message =>\n instrumentation._startProducerSpan(topicMessage.topic, message)\n )\n )\n .reduce((acc, val) => acc.concat(val), []);\n\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(spans, origSendResult);\n };\n };\n }\n\n private _getProducerSendPatch() {\n const instrumentation = this;\n return (original: Producer['send']) => {\n return function send(\n this: Producer,\n ...args: Parameters<Producer['send']>\n ): ReturnType<Producer['send']> {\n const record = args[0];\n const spans: Span[] = record.messages.map(message => {\n return instrumentation._startProducerSpan(record.topic, message);\n });\n\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(spans, origSendResult);\n };\n };\n }\n\n private _endSpansOnPromise<T>(\n spans: Span[],\n sendPromise: Promise<T>\n ): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string;\n if (typeof reason === 'string') errorMessage = reason;\n else if (\n typeof reason === 'object' &&\n Object.prototype.hasOwnProperty.call(reason, 'message')\n )\n errorMessage = reason.message;\n\n spans.forEach(span =>\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorMessage,\n })\n );\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n }\n\n private _startConsumerSpan(\n topic: string,\n message: KafkaMessage | undefined,\n operation: string,\n context: Context | undefined,\n link?: Link\n ) {\n const span = this.tracer.startSpan(\n topic,\n {\n kind: SpanKind.CONSUMER,\n attributes: {\n [SEMATTRS_MESSAGING_SYSTEM]: 'kafka',\n [SEMATTRS_MESSAGING_DESTINATION]: topic,\n [SEMATTRS_MESSAGING_OPERATION]: operation,\n },\n links: link ? [link] : [],\n },\n context\n );\n\n const { consumerHook } = this.getConfig();\n if (consumerHook && message) {\n safeExecuteInTheMiddle(\n () => consumerHook(span, { topic, message }),\n e => {\n if (e) this._diag.error('consumerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n\n private _startProducerSpan(topic: string, message: Message) {\n const span = this.tracer.startSpan(topic, {\n kind: SpanKind.PRODUCER,\n attributes: {\n [SEMATTRS_MESSAGING_SYSTEM]: 'kafka',\n [SEMATTRS_MESSAGING_DESTINATION]: topic,\n },\n });\n\n message.headers = message.headers ?? {};\n propagation.inject(trace.setSpan(context.active(), span), message.headers);\n\n const { producerHook } = this.getConfig();\n if (producerHook) {\n safeExecuteInTheMiddle(\n () => producerHook(span, { topic, message }),\n e => {\n if (e) this._diag.error('producerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAa4B;AAC5B,oEAKwC;AACxC,8EAK6C;AAY7C,qDAAuD;AACvD,6CAAmD;AACnD,uCAkBmB;AAEnB,kBAAkB;AAClB,uCAA0D;AA2D1D,SAAS,cAAc,CACrB,KAAiB,EACjB,KAAa,EACb,UAAa;IAEb,OAAO,CAAC,SAA8B,EAAE,EAAE;QACxC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE;YACf,GAAG,UAAU;YACb,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,sCAAe,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvD,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAC/B,KAAmB,EACnB,KAAa,EACb,UAAa;IAEb,OAAO,CAAC,SAA8B,EAAE,EAAE;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE;YACxC,GAAG,UAAU;YACb,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,sCAAe,CAAC,EAAE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,CAAC;QAEH,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACxC,iBAAW,CAAC,MAAM,CAAC,WAAK,CAAC,OAAO,CAAC,aAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAE3E,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1C,IAAI,YAAY,EAAE;YAChB,IAAA,wCAAsB,EACpB,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAC5C,CAAC,CAAC,EAAE;gBACF,IAAI,CAAC;oBAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC;YACnD,CAAC,EACD,IAAI,CACL,CAAC;SACH;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1iBD,wDA0iBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Attributes,\n Context,\n context,\n Counter,\n Histogram,\n Link,\n propagation,\n ROOT_CONTEXT,\n Span,\n SpanKind,\n SpanStatusCode,\n trace,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ERROR_TYPE_VALUE_OTHER,\n} from '@opentelemetry/semantic-conventions';\nimport type * as kafkaJs from 'kafkajs';\nimport type {\n Consumer,\n ConsumerRunConfig,\n EachBatchHandler,\n EachMessageHandler,\n KafkaMessage,\n Message,\n Producer,\n RecordMetadata,\n} from 'kafkajs';\nimport { EVENT_LISTENERS_SET } from './internal-types';\nimport { bufferTextMapGetter } from './propagator';\nimport {\n ATTR_MESSAGING_BATCH_MESSAGE_COUNT,\n ATTR_MESSAGING_DESTINATION_NAME,\n ATTR_MESSAGING_DESTINATION_PARTITION_ID,\n ATTR_MESSAGING_KAFKA_MESSAGE_KEY,\n ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE,\n ATTR_MESSAGING_KAFKA_OFFSET,\n ATTR_MESSAGING_OPERATION_NAME,\n ATTR_MESSAGING_OPERATION_TYPE,\n ATTR_MESSAGING_SYSTEM,\n MESSAGING_OPERATION_TYPE_VALUE_PROCESS,\n MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n MESSAGING_OPERATION_TYPE_VALUE_SEND,\n MESSAGING_SYSTEM_VALUE_KAFKA,\n METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES,\n METRIC_MESSAGING_CLIENT_OPERATION_DURATION,\n METRIC_MESSAGING_CLIENT_SENT_MESSAGES,\n METRIC_MESSAGING_PROCESS_DURATION,\n} from './semconv';\nimport { KafkaJsInstrumentationConfig } from './types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\ninterface ConsumerSpanOptions {\n topic: string;\n message: KafkaMessage | undefined;\n operationType: string;\n attributes: Attributes;\n ctx?: Context | undefined;\n link?: Link;\n}\n// This interface acts as a strict subset of the KafkaJS Consumer and\n// Producer interfaces (just for the event we're needing)\ninterface KafkaEventEmitter {\n on(\n eventName:\n | kafkaJs.ConsumerEvents['REQUEST']\n | kafkaJs.ProducerEvents['REQUEST'],\n listener: (event: kafkaJs.RequestEvent) => void\n ): void;\n events: {\n REQUEST:\n | kafkaJs.ConsumerEvents['REQUEST']\n | kafkaJs.ProducerEvents['REQUEST'];\n };\n [EVENT_LISTENERS_SET]?: boolean;\n}\n\ninterface StandardAttributes<OP extends string = string> extends Attributes {\n [ATTR_MESSAGING_SYSTEM]: string;\n [ATTR_MESSAGING_OPERATION_NAME]: OP;\n [ATTR_ERROR_TYPE]?: string;\n}\ninterface TopicAttributes {\n [ATTR_MESSAGING_DESTINATION_NAME]: string;\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]?: string;\n}\n\ninterface ClientDurationAttributes\n extends StandardAttributes,\n Partial<TopicAttributes> {\n [ATTR_SERVER_ADDRESS]: string;\n [ATTR_SERVER_PORT]: number;\n [ATTR_MESSAGING_OPERATION_TYPE]?: string;\n}\ninterface SentMessagesAttributes\n extends StandardAttributes<'send'>,\n TopicAttributes {\n [ATTR_ERROR_TYPE]?: string;\n}\ntype ConsumedMessagesAttributes = StandardAttributes<'receive' | 'process'>;\ninterface MessageProcessDurationAttributes\n extends StandardAttributes<'process'>,\n TopicAttributes {\n [ATTR_MESSAGING_SYSTEM]: string;\n [ATTR_MESSAGING_OPERATION_NAME]: 'process';\n [ATTR_ERROR_TYPE]?: string;\n}\ntype RecordPendingMetric = (errorType?: string | undefined) => void;\n\nfunction prepareCounter<T extends Attributes>(\n meter: Counter<T>,\n value: number,\n attributes: T\n): RecordPendingMetric {\n return (errorType?: string | undefined) => {\n meter.add(value, {\n ...attributes,\n ...(errorType ? { [ATTR_ERROR_TYPE]: errorType } : {}),\n });\n };\n}\n\nfunction prepareDurationHistogram<T extends Attributes>(\n meter: Histogram<T>,\n value: number,\n attributes: T\n): RecordPendingMetric {\n return (errorType?: string | undefined) => {\n meter.record((Date.now() - value) / 1000, {\n ...attributes,\n ...(errorType ? { [ATTR_ERROR_TYPE]: errorType } : {}),\n });\n };\n}\n\nconst HISTOGRAM_BUCKET_BOUNDARIES = [\n 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10,\n];\nexport class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumentationConfig> {\n private _clientDuration!: Histogram<ClientDurationAttributes>;\n private _sentMessages!: Counter<SentMessagesAttributes>;\n private _consumedMessages!: Counter<ConsumedMessagesAttributes>;\n private _processDuration!: Histogram<MessageProcessDurationAttributes>;\n\n constructor(config: KafkaJsInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n override _updateMetricInstruments() {\n this._clientDuration = this.meter.createHistogram(\n METRIC_MESSAGING_CLIENT_OPERATION_DURATION,\n { advice: { explicitBucketBoundaries: HISTOGRAM_BUCKET_BOUNDARIES } }\n );\n this._sentMessages = this.meter.createCounter(\n METRIC_MESSAGING_CLIENT_SENT_MESSAGES\n );\n this._consumedMessages = this.meter.createCounter(\n METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES\n );\n this._processDuration = this.meter.createHistogram(\n METRIC_MESSAGING_PROCESS_DURATION,\n { advice: { explicitBucketBoundaries: HISTOGRAM_BUCKET_BOUNDARIES } }\n );\n }\n\n protected init() {\n const unpatch = (moduleExports: typeof kafkaJs) => {\n if (isWrapped(moduleExports?.Kafka?.prototype.producer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'producer');\n }\n if (isWrapped(moduleExports?.Kafka?.prototype.consumer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'consumer');\n }\n };\n\n const module = new InstrumentationNodeModuleDefinition(\n 'kafkajs',\n ['>=0.3.0 <3'],\n (moduleExports: typeof kafkaJs) => {\n unpatch(moduleExports);\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'producer',\n this._getProducerPatch()\n );\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'consumer',\n this._getConsumerPatch()\n );\n\n return moduleExports;\n },\n unpatch\n );\n return module;\n }\n\n private _getConsumerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['consumer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['consumer']>\n ) {\n const newConsumer: Consumer = original.apply(this, args);\n\n if (isWrapped(newConsumer.run)) {\n instrumentation._unwrap(newConsumer, 'run');\n }\n\n instrumentation._wrap(\n newConsumer,\n 'run',\n instrumentation._getConsumerRunPatch()\n );\n\n instrumentation._setKafkaEventListeners(newConsumer);\n\n return newConsumer;\n };\n };\n }\n\n private _setKafkaEventListeners(kafkaObj: KafkaEventEmitter) {\n if (kafkaObj[EVENT_LISTENERS_SET]) return;\n\n // The REQUEST Consumer event was added in kafkajs@1.5.0.\n if (kafkaObj.events?.REQUEST) {\n kafkaObj.on(\n kafkaObj.events.REQUEST,\n this._recordClientDurationMetric.bind(this)\n );\n }\n\n kafkaObj[EVENT_LISTENERS_SET] = true;\n }\n\n private _recordClientDurationMetric(\n event: Pick<kafkaJs.RequestEvent, 'payload'>\n ) {\n const [address, port] = event.payload.broker.split(':');\n this._clientDuration.record(event.payload.duration / 1000, {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: `${event.payload.apiName}`, // potentially suffix with @v${event.payload.apiVersion}?\n [ATTR_SERVER_ADDRESS]: address,\n [ATTR_SERVER_PORT]: Number.parseInt(port, 10),\n });\n }\n\n private _getProducerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['producer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['producer']>\n ) {\n const newProducer: Producer = original.apply(this, args);\n\n if (isWrapped(newProducer.sendBatch)) {\n instrumentation._unwrap(newProducer, 'sendBatch');\n }\n instrumentation._wrap(\n newProducer,\n 'sendBatch',\n instrumentation._getProducerSendBatchPatch()\n );\n\n if (isWrapped(newProducer.send)) {\n instrumentation._unwrap(newProducer, 'send');\n }\n instrumentation._wrap(\n newProducer,\n 'send',\n instrumentation._getProducerSendPatch()\n );\n\n instrumentation._setKafkaEventListeners(newProducer);\n\n return newProducer;\n };\n };\n }\n\n private _getConsumerRunPatch() {\n const instrumentation = this;\n return (original: Consumer['run']) => {\n return function run(\n this: Consumer,\n ...args: Parameters<Consumer['run']>\n ): ReturnType<Consumer['run']> {\n const config = args[0];\n if (config?.eachMessage) {\n if (isWrapped(config.eachMessage)) {\n instrumentation._unwrap(config, 'eachMessage');\n }\n instrumentation._wrap(\n config,\n 'eachMessage',\n instrumentation._getConsumerEachMessagePatch()\n );\n }\n if (config?.eachBatch) {\n if (isWrapped(config.eachBatch)) {\n instrumentation._unwrap(config, 'eachBatch');\n }\n instrumentation._wrap(\n config,\n 'eachBatch',\n instrumentation._getConsumerEachBatchPatch()\n );\n }\n return original.call(this, config);\n };\n };\n }\n\n private _getConsumerEachMessagePatch() {\n const instrumentation = this;\n return (original: ConsumerRunConfig['eachMessage']) => {\n return function eachMessage(\n this: unknown,\n ...args: Parameters<EachMessageHandler>\n ): Promise<void> {\n const payload = args[0];\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n payload.message.headers,\n bufferTextMapGetter\n );\n const span = instrumentation._startConsumerSpan({\n topic: payload.topic,\n message: payload.message,\n operationType: MESSAGING_OPERATION_TYPE_VALUE_PROCESS,\n ctx: propagatedContext,\n attributes: {\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.partition\n ),\n },\n });\n\n const pendingMetrics: RecordPendingMetric[] = [\n prepareDurationHistogram(\n instrumentation._processDuration,\n Date.now(),\n {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'process',\n [ATTR_MESSAGING_DESTINATION_NAME]: payload.topic,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.partition\n ),\n }\n ),\n prepareCounter(instrumentation._consumedMessages, 1, {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'process',\n [ATTR_MESSAGING_DESTINATION_NAME]: payload.topic,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.partition\n ),\n }),\n ];\n\n const eachMessagePromise = context.with(\n trace.setSpan(propagatedContext, span),\n () => {\n return original!.apply(this, args);\n }\n );\n return instrumentation._endSpansOnPromise(\n [span],\n pendingMetrics,\n eachMessagePromise\n );\n };\n };\n }\n\n private _getConsumerEachBatchPatch() {\n return (original: ConsumerRunConfig['eachBatch']) => {\n const instrumentation = this;\n return function eachBatch(\n this: unknown,\n ...args: Parameters<EachBatchHandler>\n ): Promise<void> {\n const payload = args[0];\n // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers\n const receivingSpan = instrumentation._startConsumerSpan({\n topic: payload.batch.topic,\n message: undefined,\n operationType: MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n ctx: ROOT_CONTEXT,\n attributes: {\n [ATTR_MESSAGING_BATCH_MESSAGE_COUNT]: payload.batch.messages.length,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.batch.partition\n ),\n },\n });\n return context.with(\n trace.setSpan(context.active(), receivingSpan),\n () => {\n const startTime = Date.now();\n const spans: Span[] = [];\n const pendingMetrics: RecordPendingMetric[] = [\n prepareCounter(\n instrumentation._consumedMessages,\n payload.batch.messages.length,\n {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'process',\n [ATTR_MESSAGING_DESTINATION_NAME]: payload.batch.topic,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.batch.partition\n ),\n }\n ),\n ];\n payload.batch.messages.forEach(message => {\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n message.headers,\n bufferTextMapGetter\n );\n const spanContext = trace\n .getSpan(propagatedContext)\n ?.spanContext();\n let origSpanLink: Link | undefined;\n if (spanContext) {\n origSpanLink = {\n context: spanContext,\n };\n }\n spans.push(\n instrumentation._startConsumerSpan({\n topic: payload.batch.topic,\n message,\n operationType: MESSAGING_OPERATION_TYPE_VALUE_PROCESS,\n link: origSpanLink,\n attributes: {\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.batch.partition\n ),\n },\n })\n );\n pendingMetrics.push(\n prepareDurationHistogram(\n instrumentation._processDuration,\n startTime,\n {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'process',\n [ATTR_MESSAGING_DESTINATION_NAME]: payload.batch.topic,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n payload.batch.partition\n ),\n }\n )\n );\n });\n const batchMessagePromise: Promise<void> = original!.apply(\n this,\n args\n );\n spans.unshift(receivingSpan);\n return instrumentation._endSpansOnPromise(\n spans,\n pendingMetrics,\n batchMessagePromise\n );\n }\n );\n };\n };\n }\n\n private _getProducerSendBatchPatch() {\n const instrumentation = this;\n return (original: Producer['sendBatch']) => {\n return function sendBatch(\n this: Producer,\n ...args: Parameters<Producer['sendBatch']>\n ): ReturnType<Producer['sendBatch']> {\n const batch = args[0];\n const messages = batch.topicMessages || [];\n\n const spans: Span[] = [];\n const pendingMetrics: RecordPendingMetric[] = [];\n\n messages.forEach(topicMessage => {\n topicMessage.messages.forEach(message => {\n spans.push(\n instrumentation._startProducerSpan(topicMessage.topic, message)\n );\n pendingMetrics.push(\n prepareCounter(instrumentation._sentMessages, 1, {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_DESTINATION_NAME]: topicMessage.topic,\n ...(message.partition !== undefined\n ? {\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n message.partition\n ),\n }\n : {}),\n })\n );\n });\n });\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(\n spans,\n pendingMetrics,\n origSendResult\n );\n };\n };\n }\n\n private _getProducerSendPatch() {\n const instrumentation = this;\n return (original: Producer['send']) => {\n return function send(\n this: Producer,\n ...args: Parameters<Producer['send']>\n ): ReturnType<Producer['send']> {\n const record = args[0];\n const spans: Span[] = record.messages.map(message => {\n return instrumentation._startProducerSpan(record.topic, message);\n });\n\n const pendingMetrics: RecordPendingMetric[] = record.messages.map(m =>\n prepareCounter(instrumentation._sentMessages, 1, {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_DESTINATION_NAME]: record.topic,\n ...(m.partition !== undefined\n ? {\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(\n m.partition\n ),\n }\n : {}),\n })\n );\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(\n spans,\n pendingMetrics,\n origSendResult\n );\n };\n };\n }\n\n private _endSpansOnPromise<T>(\n spans: Span[],\n pendingMetrics: RecordPendingMetric[],\n sendPromise: Promise<T>\n ): Promise<T> {\n return Promise.resolve(sendPromise)\n .then(result => {\n pendingMetrics.forEach(m => m());\n return result;\n })\n .catch(reason => {\n let errorMessage: string | undefined;\n let errorType: string = ERROR_TYPE_VALUE_OTHER;\n if (typeof reason === 'string' || reason === undefined) {\n errorMessage = reason;\n } else if (\n typeof reason === 'object' &&\n Object.prototype.hasOwnProperty.call(reason, 'message')\n ) {\n errorMessage = reason.message;\n errorType = reason.constructor.name;\n }\n pendingMetrics.forEach(m => m(errorType));\n\n spans.forEach(span => {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorMessage,\n });\n });\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n }\n\n private _startConsumerSpan({\n topic,\n message,\n operationType,\n ctx,\n link,\n attributes,\n }: ConsumerSpanOptions) {\n const operationName =\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? 'poll' // for batch processing spans\n : operationType; // for individual message processing spans\n\n const span = this.tracer.startSpan(\n `${operationName} ${topic}`,\n {\n kind:\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? SpanKind.CLIENT\n : SpanKind.CONSUMER,\n attributes: {\n ...attributes,\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_OPERATION_TYPE]: operationType,\n [ATTR_MESSAGING_OPERATION_NAME]: operationName,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key\n ? String(message.key)\n : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]:\n message?.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,\n },\n links: link ? [link] : [],\n },\n ctx\n );\n\n const { consumerHook } = this.getConfig();\n if (consumerHook && message) {\n safeExecuteInTheMiddle(\n () => consumerHook(span, { topic, message }),\n e => {\n if (e) this._diag.error('consumerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n\n private _startProducerSpan(topic: string, message: Message) {\n const span = this.tracer.startSpan(`send ${topic}`, {\n kind: SpanKind.PRODUCER,\n attributes: {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key\n ? String(message.key)\n : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]:\n message.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]:\n message.partition !== undefined\n ? String(message.partition)\n : undefined,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,\n },\n });\n\n message.headers = message.headers ?? {};\n propagation.inject(trace.setSpan(context.active(), span), message.headers);\n\n const { producerHook } = this.getConfig();\n if (producerHook) {\n safeExecuteInTheMiddle(\n () => producerHook(span, { topic, message }),\n e => {\n if (e) this._diag.error('producerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type * as KafkaJSTypes from 'kafkajs';
2
+ export declare const EVENT_LISTENERS_SET: unique symbol;
3
+ export interface ConsumerExtended extends KafkaJSTypes.Consumer {
4
+ [EVENT_LISTENERS_SET]?: boolean;
5
+ }
6
+ export interface ProducerExtended extends KafkaJSTypes.Producer {
7
+ [EVENT_LISTENERS_SET]?: boolean;
8
+ }
9
+ //# sourceMappingURL=internal-types.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors, Aspecto
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.EVENT_LISTENERS_SET = void 0;
19
+ exports.EVENT_LISTENERS_SET = Symbol('opentelemetry.instrumentation.kafkajs.eventListenersSet');
20
+ //# sourceMappingURL=internal-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../src/internal-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIU,QAAA,mBAAmB,GAAG,MAAM,CACvC,yDAAyD,CAC1D,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as KafkaJSTypes from 'kafkajs';\n\nexport const EVENT_LISTENERS_SET = Symbol(\n 'opentelemetry.instrumentation.kafkajs.eventListenersSet'\n);\n\nexport interface ConsumerExtended extends KafkaJSTypes.Consumer {\n [EVENT_LISTENERS_SET]?: boolean; // flag to identify if the event listeners for instrumentation have been set\n}\n\nexport interface ProducerExtended extends KafkaJSTypes.Producer {\n [EVENT_LISTENERS_SET]?: boolean; // flag to identify if the event listeners for instrumentation have been set\n}\n"]}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The number of messages sent, received, or processed in the scope of the batching operation.
3
+ *
4
+ * @example 0
5
+ * @example 1
6
+ * @example 2
7
+ *
8
+ * @note Instrumentations **SHOULD NOT** set `messaging.batch.message_count` on spans that operate with a single message. When a messaging client library supports both batch and single-message API for the same operation, instrumentations **SHOULD** use `messaging.batch.message_count` for batching APIs and **SHOULD NOT** use it for single-message APIs.
9
+ *
10
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
11
+ */
12
+ export declare const ATTR_MESSAGING_BATCH_MESSAGE_COUNT: "messaging.batch.message_count";
13
+ /**
14
+ * The message destination name
15
+ *
16
+ * @example MyQueue
17
+ * @example MyTopic
18
+ *
19
+ * @note Destination name **SHOULD** uniquely identify a specific queue, topic or other entity within the broker. If
20
+ * the broker doesn't have such notion, the destination name **SHOULD** uniquely identify the broker.
21
+ *
22
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
23
+ */
24
+ export declare const ATTR_MESSAGING_DESTINATION_NAME: "messaging.destination.name";
25
+ /**
26
+ * The identifier of the partition messages are sent to or received from, unique within the `messaging.destination.name`.
27
+ *
28
+ * @example "1"
29
+ *
30
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
31
+ */
32
+ export declare const ATTR_MESSAGING_DESTINATION_PARTITION_ID: "messaging.destination.partition.id";
33
+ /**
34
+ * Message keys in Kafka are used for grouping alike messages to ensure they're processed on the same partition. They differ from `messaging.message.id` in that they're not unique. If the key is `null`, the attribute **MUST NOT** be set.
35
+ *
36
+ * @example "myKey"
37
+ *
38
+ * @note If the key type is not string, it's string representation has to be supplied for the attribute. If the key has no unambiguous, canonical string form, don't include its value.
39
+ *
40
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
41
+ */
42
+ export declare const ATTR_MESSAGING_KAFKA_MESSAGE_KEY: "messaging.kafka.message.key";
43
+ /**
44
+ * A boolean that is true if the message is a tombstone.
45
+ *
46
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
47
+ */
48
+ export declare const ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE: "messaging.kafka.message.tombstone";
49
+ /**
50
+ * The offset of a record in the corresponding Kafka partition.
51
+ *
52
+ * @example 42
53
+ *
54
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
55
+ */
56
+ export declare const ATTR_MESSAGING_KAFKA_OFFSET: "messaging.kafka.offset";
57
+ /**
58
+ * The system-specific name of the messaging operation.
59
+ *
60
+ * @example ack
61
+ * @example nack
62
+ * @example send
63
+ *
64
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
65
+ */
66
+ export declare const ATTR_MESSAGING_OPERATION_NAME: "messaging.operation.name";
67
+ /**
68
+ * A string identifying the type of the messaging operation.
69
+ *
70
+ * @note If a custom value is used, it **MUST** be of low cardinality.
71
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
72
+ */
73
+ export declare const ATTR_MESSAGING_OPERATION_TYPE: "messaging.operation.type";
74
+ /**
75
+ * The messaging system as identified by the client instrumentation.
76
+ *
77
+ * @note The actual messaging system may differ from the one known by the client. For example, when using Kafka client libraries to communicate with Azure Event Hubs, the `messaging.system` is set to `kafka` based on the instrumentation's best knowledge.
78
+ *
79
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
80
+ */
81
+ export declare const ATTR_MESSAGING_SYSTEM: "messaging.system";
82
+ /**
83
+ * Enum value "process" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
84
+ */
85
+ export declare const MESSAGING_OPERATION_TYPE_VALUE_PROCESS: "process";
86
+ /**
87
+ * Enum value "receive" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
88
+ */
89
+ export declare const MESSAGING_OPERATION_TYPE_VALUE_RECEIVE: "receive";
90
+ /**
91
+ * Enum value "send" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
92
+ */
93
+ export declare const MESSAGING_OPERATION_TYPE_VALUE_SEND: "send";
94
+ /**
95
+ * Enum value "kafka" for attribute {@link ATTR_MESSAGING_SYSTEM}.
96
+ */
97
+ export declare const MESSAGING_SYSTEM_VALUE_KAFKA: "kafka";
98
+ /**
99
+ * Number of messages that were delivered to the application.
100
+ *
101
+ * @note Records the number of messages pulled from the broker or number of messages dispatched to the application in push-based scenarios.
102
+ * The metric **SHOULD** be reported once per message delivery. For example, if receiving and processing operations are both instrumented for a single message delivery, this counter is incremented when the message is received and not reported when it is processed.
103
+ *
104
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
105
+ */
106
+ export declare const METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES: "messaging.client.consumed.messages";
107
+ /**
108
+ * Duration of messaging operation initiated by a producer or consumer client.
109
+ *
110
+ * @note This metric **SHOULD NOT** be used to report processing duration - processing duration is reported in `messaging.process.duration` metric.
111
+ *
112
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
113
+ */
114
+ export declare const METRIC_MESSAGING_CLIENT_OPERATION_DURATION: "messaging.client.operation.duration";
115
+ /**
116
+ * Number of messages producer attempted to send to the broker.
117
+ *
118
+ * @note This metric **MUST NOT** count messages that were created but haven't yet been sent.
119
+ *
120
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
121
+ */
122
+ export declare const METRIC_MESSAGING_CLIENT_SENT_MESSAGES: "messaging.client.sent.messages";
123
+ /**
124
+ * Duration of processing operation.
125
+ *
126
+ * @note This metric **MUST** be reported for operations with `messaging.operation.type` that matches `process`.
127
+ *
128
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
129
+ */
130
+ export declare const METRIC_MESSAGING_PROCESS_DURATION: "messaging.process.duration";
131
+ //# sourceMappingURL=semconv.d.ts.map
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.METRIC_MESSAGING_PROCESS_DURATION = exports.METRIC_MESSAGING_CLIENT_SENT_MESSAGES = exports.METRIC_MESSAGING_CLIENT_OPERATION_DURATION = exports.METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES = exports.MESSAGING_SYSTEM_VALUE_KAFKA = exports.MESSAGING_OPERATION_TYPE_VALUE_SEND = exports.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE = exports.MESSAGING_OPERATION_TYPE_VALUE_PROCESS = exports.ATTR_MESSAGING_SYSTEM = exports.ATTR_MESSAGING_OPERATION_TYPE = exports.ATTR_MESSAGING_OPERATION_NAME = exports.ATTR_MESSAGING_KAFKA_OFFSET = exports.ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE = exports.ATTR_MESSAGING_KAFKA_MESSAGE_KEY = exports.ATTR_MESSAGING_DESTINATION_PARTITION_ID = exports.ATTR_MESSAGING_DESTINATION_NAME = exports.ATTR_MESSAGING_BATCH_MESSAGE_COUNT = void 0;
19
+ /*
20
+ * This file contains a copy of unstable semantic convention definitions
21
+ * used by this package.
22
+ * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
23
+ */
24
+ /**
25
+ * The number of messages sent, received, or processed in the scope of the batching operation.
26
+ *
27
+ * @example 0
28
+ * @example 1
29
+ * @example 2
30
+ *
31
+ * @note Instrumentations **SHOULD NOT** set `messaging.batch.message_count` on spans that operate with a single message. When a messaging client library supports both batch and single-message API for the same operation, instrumentations **SHOULD** use `messaging.batch.message_count` for batching APIs and **SHOULD NOT** use it for single-message APIs.
32
+ *
33
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
34
+ */
35
+ exports.ATTR_MESSAGING_BATCH_MESSAGE_COUNT = 'messaging.batch.message_count';
36
+ /**
37
+ * The message destination name
38
+ *
39
+ * @example MyQueue
40
+ * @example MyTopic
41
+ *
42
+ * @note Destination name **SHOULD** uniquely identify a specific queue, topic or other entity within the broker. If
43
+ * the broker doesn't have such notion, the destination name **SHOULD** uniquely identify the broker.
44
+ *
45
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
46
+ */
47
+ exports.ATTR_MESSAGING_DESTINATION_NAME = 'messaging.destination.name';
48
+ /**
49
+ * The identifier of the partition messages are sent to or received from, unique within the `messaging.destination.name`.
50
+ *
51
+ * @example "1"
52
+ *
53
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
54
+ */
55
+ exports.ATTR_MESSAGING_DESTINATION_PARTITION_ID = 'messaging.destination.partition.id';
56
+ /**
57
+ * Message keys in Kafka are used for grouping alike messages to ensure they're processed on the same partition. They differ from `messaging.message.id` in that they're not unique. If the key is `null`, the attribute **MUST NOT** be set.
58
+ *
59
+ * @example "myKey"
60
+ *
61
+ * @note If the key type is not string, it's string representation has to be supplied for the attribute. If the key has no unambiguous, canonical string form, don't include its value.
62
+ *
63
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
64
+ */
65
+ exports.ATTR_MESSAGING_KAFKA_MESSAGE_KEY = 'messaging.kafka.message.key';
66
+ /**
67
+ * A boolean that is true if the message is a tombstone.
68
+ *
69
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
70
+ */
71
+ exports.ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE = 'messaging.kafka.message.tombstone';
72
+ /**
73
+ * The offset of a record in the corresponding Kafka partition.
74
+ *
75
+ * @example 42
76
+ *
77
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
78
+ */
79
+ exports.ATTR_MESSAGING_KAFKA_OFFSET = 'messaging.kafka.offset';
80
+ /**
81
+ * The system-specific name of the messaging operation.
82
+ *
83
+ * @example ack
84
+ * @example nack
85
+ * @example send
86
+ *
87
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
88
+ */
89
+ exports.ATTR_MESSAGING_OPERATION_NAME = 'messaging.operation.name';
90
+ /**
91
+ * A string identifying the type of the messaging operation.
92
+ *
93
+ * @note If a custom value is used, it **MUST** be of low cardinality.
94
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
95
+ */
96
+ exports.ATTR_MESSAGING_OPERATION_TYPE = 'messaging.operation.type';
97
+ /**
98
+ * The messaging system as identified by the client instrumentation.
99
+ *
100
+ * @note The actual messaging system may differ from the one known by the client. For example, when using Kafka client libraries to communicate with Azure Event Hubs, the `messaging.system` is set to `kafka` based on the instrumentation's best knowledge.
101
+ *
102
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
103
+ */
104
+ exports.ATTR_MESSAGING_SYSTEM = 'messaging.system';
105
+ /**
106
+ * Enum value "process" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
107
+ */
108
+ exports.MESSAGING_OPERATION_TYPE_VALUE_PROCESS = 'process';
109
+ /**
110
+ * Enum value "receive" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
111
+ */
112
+ exports.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE = 'receive';
113
+ /**
114
+ * Enum value "send" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.
115
+ */
116
+ exports.MESSAGING_OPERATION_TYPE_VALUE_SEND = 'send';
117
+ /**
118
+ * Enum value "kafka" for attribute {@link ATTR_MESSAGING_SYSTEM}.
119
+ */
120
+ exports.MESSAGING_SYSTEM_VALUE_KAFKA = 'kafka';
121
+ /**
122
+ * Number of messages that were delivered to the application.
123
+ *
124
+ * @note Records the number of messages pulled from the broker or number of messages dispatched to the application in push-based scenarios.
125
+ * The metric **SHOULD** be reported once per message delivery. For example, if receiving and processing operations are both instrumented for a single message delivery, this counter is incremented when the message is received and not reported when it is processed.
126
+ *
127
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
128
+ */
129
+ exports.METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES = 'messaging.client.consumed.messages';
130
+ /**
131
+ * Duration of messaging operation initiated by a producer or consumer client.
132
+ *
133
+ * @note This metric **SHOULD NOT** be used to report processing duration - processing duration is reported in `messaging.process.duration` metric.
134
+ *
135
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
136
+ */
137
+ exports.METRIC_MESSAGING_CLIENT_OPERATION_DURATION = 'messaging.client.operation.duration';
138
+ /**
139
+ * Number of messages producer attempted to send to the broker.
140
+ *
141
+ * @note This metric **MUST NOT** count messages that were created but haven't yet been sent.
142
+ *
143
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
144
+ */
145
+ exports.METRIC_MESSAGING_CLIENT_SENT_MESSAGES = 'messaging.client.sent.messages';
146
+ /**
147
+ * Duration of processing operation.
148
+ *
149
+ * @note This metric **MUST** be reported for operations with `messaging.operation.type` that matches `process`.
150
+ *
151
+ * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
152
+ */
153
+ exports.METRIC_MESSAGING_PROCESS_DURATION = 'messaging.process.duration';
154
+ //# sourceMappingURL=semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACU,QAAA,kCAAkC,GAC7C,+BAAwC,CAAC;AAE3C;;;;;;;;;;GAUG;AACU,QAAA,+BAA+B,GAC1C,4BAAqC,CAAC;AAExC;;;;;;GAMG;AACU,QAAA,uCAAuC,GAClD,oCAA6C,CAAC;AAEhD;;;;;;;;GAQG;AACU,QAAA,gCAAgC,GAC3C,6BAAsC,CAAC;AAEzC;;;;GAIG;AACU,QAAA,sCAAsC,GACjD,mCAA4C,CAAC;AAE/C;;;;;;GAMG;AACU,QAAA,2BAA2B,GAAG,wBAAiC,CAAC;AAE7E;;;;;;;;GAQG;AACU,QAAA,6BAA6B,GACxC,0BAAmC,CAAC;AAEtC;;;;;GAKG;AACU,QAAA,6BAA6B,GACxC,0BAAmC,CAAC;AAEtC;;;;;;GAMG;AACU,QAAA,qBAAqB,GAAG,kBAA2B,CAAC;AAEjE;;GAEG;AACU,QAAA,sCAAsC,GAAG,SAAkB,CAAC;AAEzE;;GAEG;AACU,QAAA,sCAAsC,GAAG,SAAkB,CAAC;AAEzE;;GAEG;AACU,QAAA,mCAAmC,GAAG,MAAe,CAAC;AAEnE;;GAEG;AACU,QAAA,4BAA4B,GAAG,OAAgB,CAAC;AAE7D;;;;;;;GAOG;AACU,QAAA,yCAAyC,GACpD,oCAA6C,CAAC;AAEhD;;;;;;GAMG;AACU,QAAA,0CAA0C,GACrD,qCAA8C,CAAC;AAEjD;;;;;;GAMG;AACU,QAAA,qCAAqC,GAChD,gCAAyC,CAAC;AAE5C;;;;;;GAMG;AACU,QAAA,iCAAiC,GAC5C,4BAAqC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The number of messages sent, received, or processed in the scope of the batching operation.\n *\n * @example 0\n * @example 1\n * @example 2\n *\n * @note Instrumentations **SHOULD NOT** set `messaging.batch.message_count` on spans that operate with a single message. When a messaging client library supports both batch and single-message API for the same operation, instrumentations **SHOULD** use `messaging.batch.message_count` for batching APIs and **SHOULD NOT** use it for single-message APIs.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_BATCH_MESSAGE_COUNT =\n 'messaging.batch.message_count' as const;\n\n/**\n * The message destination name\n *\n * @example MyQueue\n * @example MyTopic\n *\n * @note Destination name **SHOULD** uniquely identify a specific queue, topic or other entity within the broker. If\n * the broker doesn't have such notion, the destination name **SHOULD** uniquely identify the broker.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_DESTINATION_NAME =\n 'messaging.destination.name' as const;\n\n/**\n * The identifier of the partition messages are sent to or received from, unique within the `messaging.destination.name`.\n *\n * @example \"1\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_DESTINATION_PARTITION_ID =\n 'messaging.destination.partition.id' as const;\n\n/**\n * Message keys in Kafka are used for grouping alike messages to ensure they're processed on the same partition. They differ from `messaging.message.id` in that they're not unique. If the key is `null`, the attribute **MUST NOT** be set.\n *\n * @example \"myKey\"\n *\n * @note If the key type is not string, it's string representation has to be supplied for the attribute. If the key has no unambiguous, canonical string form, don't include its value.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_KAFKA_MESSAGE_KEY =\n 'messaging.kafka.message.key' as const;\n\n/**\n * A boolean that is true if the message is a tombstone.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE =\n 'messaging.kafka.message.tombstone' as const;\n\n/**\n * The offset of a record in the corresponding Kafka partition.\n *\n * @example 42\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_KAFKA_OFFSET = 'messaging.kafka.offset' as const;\n\n/**\n * The system-specific name of the messaging operation.\n *\n * @example ack\n * @example nack\n * @example send\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_OPERATION_NAME =\n 'messaging.operation.name' as const;\n\n/**\n * A string identifying the type of the messaging operation.\n *\n * @note If a custom value is used, it **MUST** be of low cardinality.\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_OPERATION_TYPE =\n 'messaging.operation.type' as const;\n\n/**\n * The messaging system as identified by the client instrumentation.\n *\n * @note The actual messaging system may differ from the one known by the client. For example, when using Kafka client libraries to communicate with Azure Event Hubs, the `messaging.system` is set to `kafka` based on the instrumentation's best knowledge.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_MESSAGING_SYSTEM = 'messaging.system' as const;\n\n/**\n * Enum value \"process\" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.\n */\nexport const MESSAGING_OPERATION_TYPE_VALUE_PROCESS = 'process' as const;\n\n/**\n * Enum value \"receive\" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.\n */\nexport const MESSAGING_OPERATION_TYPE_VALUE_RECEIVE = 'receive' as const;\n\n/**\n * Enum value \"send\" for attribute {@link ATTR_MESSAGING_OPERATION_TYPE}.\n */\nexport const MESSAGING_OPERATION_TYPE_VALUE_SEND = 'send' as const;\n\n/**\n * Enum value \"kafka\" for attribute {@link ATTR_MESSAGING_SYSTEM}.\n */\nexport const MESSAGING_SYSTEM_VALUE_KAFKA = 'kafka' as const;\n\n/**\n * Number of messages that were delivered to the application.\n *\n * @note Records the number of messages pulled from the broker or number of messages dispatched to the application in push-based scenarios.\n * The metric **SHOULD** be reported once per message delivery. For example, if receiving and processing operations are both instrumented for a single message delivery, this counter is incremented when the message is received and not reported when it is processed.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const METRIC_MESSAGING_CLIENT_CONSUMED_MESSAGES =\n 'messaging.client.consumed.messages' as const;\n\n/**\n * Duration of messaging operation initiated by a producer or consumer client.\n *\n * @note This metric **SHOULD NOT** be used to report processing duration - processing duration is reported in `messaging.process.duration` metric.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const METRIC_MESSAGING_CLIENT_OPERATION_DURATION =\n 'messaging.client.operation.duration' as const;\n\n/**\n * Number of messages producer attempted to send to the broker.\n *\n * @note This metric **MUST NOT** count messages that were created but haven't yet been sent.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const METRIC_MESSAGING_CLIENT_SENT_MESSAGES =\n 'messaging.client.sent.messages' as const;\n\n/**\n * Duration of processing operation.\n *\n * @note This metric **MUST** be reported for operations with `messaging.operation.type` that matches `process`.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const METRIC_MESSAGING_PROCESS_DURATION =\n 'messaging.process.duration' as const;\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.8.0";
1
+ export declare const PACKAGE_VERSION = "0.9.1";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-kafkajs";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.8.0';
20
+ exports.PACKAGE_VERSION = '0.9.1';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-kafkajs';
22
22
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,OAAO,CAAC;AAC1B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.8.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-kafkajs';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,OAAO,CAAC;AAC1B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.9.1';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-kafkajs';\n"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-kafkajs",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "OpenTelemetry instrumentation for `kafkajs` messaging client for Apache Kafka",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
7
7
  "repository": "open-telemetry/opentelemetry-js-contrib",
8
8
  "scripts": {
9
- "test": "mocha --require @opentelemetry/contrib-test-utils 'test/**/*.test.ts'",
9
+ "test": "nyc mocha --require @opentelemetry/contrib-test-utils 'test/**/*.test.ts'",
10
+ "test-all-versions": "tav",
10
11
  "tdd": "npm run test -- --watch-extensions ts --watch",
11
12
  "clean": "rimraf build/*",
12
13
  "lint": "eslint . --ext .ts",
@@ -52,12 +53,13 @@
52
53
  "nyc": "15.1.0",
53
54
  "rimraf": "5.0.10",
54
55
  "sinon": "15.2.0",
56
+ "test-all-versions": "6.1.0",
55
57
  "typescript": "5.0.4"
56
58
  },
57
59
  "dependencies": {
58
60
  "@opentelemetry/instrumentation": "^0.200.0",
59
- "@opentelemetry/semantic-conventions": "^1.27.0"
61
+ "@opentelemetry/semantic-conventions": "^1.30.0"
60
62
  },
61
63
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-kafkajs#readme",
62
- "gitHead": "32abc4c3c01d0e78e10022c74b6805b06e0e1fe7"
64
+ "gitHead": "0552b0354f67b5d54b8053adfc80bd04bbd356f0"
63
65
  }