@opentelemetry/instrumentation-amqplib 0.38.0 → 0.40.0

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,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-amqplib
17
17
 
18
18
  ## Supported Versions
19
19
 
20
- - `>=0.5.5`
20
+ - [`amqplib`](https://www.npmjs.com/package/amqplib) versions `>=0.5.5 <1`
21
21
 
22
22
  ## Usage
23
23
 
@@ -40,6 +40,7 @@ registerInstrumentations({
40
40
  // publishConfirmHook: (span: Span, publishConfirmedInto: PublishConfirmedInfo) => { },
41
41
  // consumeHook: (span: Span, consumeInfo: ConsumeInfo) => { },
42
42
  // consumeEndHook: (span: Span, consumeEndInfo: ConsumeEndInfo) => { },
43
+ // useLinksForConsume: boolean,
43
44
  }),
44
45
  ],
45
46
  })
@@ -49,13 +50,14 @@ registerInstrumentations({
49
50
 
50
51
  amqplib instrumentation has few options available to choose from. You can set the following:
51
52
 
52
- | Options | Type | Description |
53
- | --------------------------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
54
- | `publishHook` | `AmqplibPublishCustomAttributeFunction` | hook for adding custom attributes before publish message is sent. |
55
- | `publishConfirmHook` | `AmqplibPublishConfirmCustomAttributeFunction` | hook for adding custom attributes after publish message is confirmed by the broker. |
56
- | `consumeHook` | `AmqplibConsumeCustomAttributeFunction` | hook for adding custom attributes before consumer message is processed. |
57
- | `consumeEndHook` | `AmqplibConsumeEndCustomAttributeFunction` | hook for adding custom attributes after consumer message is acked to server. |
58
- | `consumeTimeoutMs` | `number` | read [Consume Timeout](#consume-timeout) below |
53
+ | Options | Type | Description |
54
+ | -------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------- |
55
+ | `publishHook` | `AmqplibPublishCustomAttributeFunction` | hook for adding custom attributes before publish message is sent. |
56
+ | `publishConfirmHook` | `AmqplibPublishConfirmCustomAttributeFunction` | hook for adding custom attributes after publish message is confirmed by the broker. |
57
+ | `consumeHook` | `AmqplibConsumeCustomAttributeFunction` | hook for adding custom attributes before consumer message is processed. |
58
+ | `consumeEndHook` | `AmqplibConsumeEndCustomAttributeFunction` | hook for adding custom attributes after consumer message is acked to server. |
59
+ | `consumeTimeoutMs` | `number` | read [Consume Timeout](#consume-timeout) below |
60
+ | `useLinksForConsume` | `boolean` | read [Links for Consume](#links-for-consume) below |
59
61
 
60
62
  ### Consume Timeout
61
63
 
@@ -69,17 +71,21 @@ If timeout is not big enough, span might be closed with 'InstrumentationTimeout'
69
71
 
70
72
  Default is 1 minute
71
73
 
72
- ## Migration From opentelemetry-instrumentation-amqplib
74
+ ### Links for Consume
73
75
 
74
- This instrumentation was originally published under the name `"opentelemetry-instrumentation-amqplib"` in [this repo](https://github.com/aspecto-io/opentelemetry-ext-js). Few breaking changes were made during porting to the contrib repo to align with conventions:
76
+ By default, consume spans continue the trace where a message was produced. However, per the [spec](https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#consumer-spans), consume spans should be linked to the message's creation context. Setting to true, this will enable the behavior to follow the spec.
75
77
 
76
- ### Hook Info
78
+ Default is false
77
79
 
78
- The instrumentation's config `publishHook`, `publishConfirmHook`, `consumeHook` and `consumeEndHook` functions signature changed, so the second function parameter is info object, containing the relevant hook data.
80
+ ## Running Tests Locally
79
81
 
80
- ### `moduleVersionAttributeName` config option
82
+ To run the tests locally, you need to have a RabbitMQ server running. You can use the following command to start a RabbitMQ server using Docker:
81
83
 
82
- The `moduleVersionAttributeName` config option is removed. To add the amqplib package version to spans, use the `moduleVersion` attribute in hook info for `publishHook` and `consumeHook` functions.
84
+ ```bash
85
+ npm run test:docker:run
86
+ ```
87
+
88
+ By default, the tests that connect to RabbitMQ are skipped. To make sure these tests are run, you can set the `RUN_RABBIT_TESTS` environment variable to `true`
83
89
 
84
90
  ## Semantic Conventions
85
91
 
@@ -1,7 +1,6 @@
1
1
  import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
2
  import { AmqplibInstrumentationConfig } from './types';
3
- export declare class AmqplibInstrumentation extends InstrumentationBase {
4
- protected _config: AmqplibInstrumentationConfig;
3
+ export declare class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumentationConfig> {
5
4
  constructor(config?: AmqplibInstrumentationConfig);
6
5
  setConfig(config?: AmqplibInstrumentationConfig): void;
7
6
  protected init(): InstrumentationNodeModuleDefinition;
@@ -23,18 +23,19 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
23
23
  const types_1 = require("./types");
24
24
  const utils_1 = require("./utils");
25
25
  const version_1 = require("./version");
26
+ const supportedVersions = ['>=0.5.5 <1'];
26
27
  class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
27
28
  constructor(config = {}) {
28
- super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, Object.assign({}, types_1.DEFAULT_CONFIG, config));
29
+ super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, Object.assign(Object.assign({}, types_1.DEFAULT_CONFIG), config));
29
30
  }
30
31
  setConfig(config = {}) {
31
- this._config = Object.assign({}, types_1.DEFAULT_CONFIG, config);
32
+ super.setConfig(Object.assign(Object.assign({}, types_1.DEFAULT_CONFIG), config));
32
33
  }
33
34
  init() {
34
- const channelModelModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/channel_model.js', ['>=0.5.5'], this.patchChannelModel.bind(this), this.unpatchChannelModel.bind(this));
35
- const callbackModelModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/callback_model.js', ['>=0.5.5'], this.patchChannelModel.bind(this), this.unpatchChannelModel.bind(this));
36
- const connectModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/connect.js', ['>=0.5.5'], this.patchConnect.bind(this), this.unpatchConnect.bind(this));
37
- const module = new instrumentation_1.InstrumentationNodeModuleDefinition('amqplib', ['>=0.5.5'], undefined, undefined, [channelModelModuleFile, connectModuleFile, callbackModelModuleFile]);
35
+ const channelModelModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/channel_model.js', supportedVersions, this.patchChannelModel.bind(this), this.unpatchChannelModel.bind(this));
36
+ const callbackModelModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/callback_model.js', supportedVersions, this.patchChannelModel.bind(this), this.unpatchChannelModel.bind(this));
37
+ const connectModuleFile = new instrumentation_1.InstrumentationNodeModuleFile('amqplib/lib/connect.js', supportedVersions, this.patchConnect.bind(this), this.unpatchConnect.bind(this));
38
+ const module = new instrumentation_1.InstrumentationNodeModuleDefinition('amqplib', supportedVersions, undefined, undefined, [channelModelModuleFile, connectModuleFile, callbackModelModuleFile]);
38
39
  return module;
39
40
  }
40
41
  patchConnect(moduleExports) {
@@ -183,17 +184,18 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
183
184
  return function consume(queue, onMessage, options) {
184
185
  const channel = this;
185
186
  if (!Object.prototype.hasOwnProperty.call(channel, utils_1.CHANNEL_SPANS_NOT_ENDED)) {
186
- if (self._config.consumeTimeoutMs) {
187
+ const { consumeTimeoutMs } = self.getConfig();
188
+ if (consumeTimeoutMs) {
187
189
  const timer = setInterval(() => {
188
190
  self.checkConsumeTimeoutOnChannel(channel);
189
- }, self._config.consumeTimeoutMs);
191
+ }, consumeTimeoutMs);
190
192
  timer.unref();
191
193
  channel[utils_1.CHANNEL_CONSUME_TIMEOUT_TIMER] = timer;
192
194
  }
193
195
  channel[utils_1.CHANNEL_SPANS_NOT_ENDED] = [];
194
196
  }
195
197
  const patchedOnMessage = function (msg) {
196
- var _a, _b, _c, _d;
198
+ var _a, _b, _c, _d, _e;
197
199
  // msg is expected to be null for signaling consumer cancel notification
198
200
  // https://www.rabbitmq.com/consumer-cancel.html
199
201
  // in this case, we do not start a span, as this is not a real message.
@@ -201,14 +203,30 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
201
203
  return onMessage.call(this, msg);
202
204
  }
203
205
  const headers = (_a = msg.properties.headers) !== null && _a !== void 0 ? _a : {};
204
- const parentContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, headers);
206
+ let parentContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, headers);
205
207
  const exchange = (_b = msg.fields) === null || _b === void 0 ? void 0 : _b.exchange;
208
+ let links;
209
+ if (self._config.useLinksForConsume) {
210
+ const parentSpanContext = parentContext
211
+ ? (_c = api_1.trace.getSpan(parentContext)) === null || _c === void 0 ? void 0 : _c.spanContext()
212
+ : undefined;
213
+ parentContext = undefined;
214
+ if (parentSpanContext) {
215
+ links = [
216
+ {
217
+ context: parentSpanContext,
218
+ },
219
+ ];
220
+ }
221
+ }
206
222
  const span = self.tracer.startSpan(`${queue} process`, {
207
223
  kind: api_1.SpanKind.CONSUMER,
208
- attributes: Object.assign(Object.assign({}, (_c = channel === null || channel === void 0 ? void 0 : channel.connection) === null || _c === void 0 ? void 0 : _c[utils_1.CONNECTION_ATTRIBUTES]), { [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: exchange, [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION_KIND]: semantic_conventions_1.MESSAGINGDESTINATIONKINDVALUES_TOPIC, [semantic_conventions_1.SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: (_d = msg.fields) === null || _d === void 0 ? void 0 : _d.routingKey, [semantic_conventions_1.SEMATTRS_MESSAGING_OPERATION]: semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, [semantic_conventions_1.SEMATTRS_MESSAGING_MESSAGE_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.messageId, [semantic_conventions_1.SEMATTRS_MESSAGING_CONVERSATION_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.correlationId }),
224
+ attributes: Object.assign(Object.assign({}, (_d = channel === null || channel === void 0 ? void 0 : channel.connection) === null || _d === void 0 ? void 0 : _d[utils_1.CONNECTION_ATTRIBUTES]), { [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: exchange, [semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION_KIND]: semantic_conventions_1.MESSAGINGDESTINATIONKINDVALUES_TOPIC, [semantic_conventions_1.SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: (_e = msg.fields) === null || _e === void 0 ? void 0 : _e.routingKey, [semantic_conventions_1.SEMATTRS_MESSAGING_OPERATION]: semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, [semantic_conventions_1.SEMATTRS_MESSAGING_MESSAGE_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.messageId, [semantic_conventions_1.SEMATTRS_MESSAGING_CONVERSATION_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.correlationId }),
225
+ links,
209
226
  }, parentContext);
210
- if (self._config.consumeHook) {
211
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => self._config.consumeHook(span, { moduleVersion, msg }), e => {
227
+ const { consumeHook } = self.getConfig();
228
+ if (consumeHook) {
229
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => consumeHook(span, { moduleVersion, msg }), e => {
212
230
  if (e) {
213
231
  api_1.diag.error('amqplib instrumentation: consumerHook error', e);
214
232
  }
@@ -223,7 +241,10 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
223
241
  // store the span on the message, so we can end it when user call 'ack' on it
224
242
  msg[utils_1.MESSAGE_STORED_SPAN] = span;
225
243
  }
226
- api_1.context.with(api_1.trace.setSpan(parentContext, span), () => {
244
+ const setContext = parentContext
245
+ ? parentContext
246
+ : api_1.ROOT_CONTEXT;
247
+ api_1.context.with(api_1.trace.setSpan(setContext, span), () => {
227
248
  onMessage.call(this, msg);
228
249
  });
229
250
  if (options === null || options === void 0 ? void 0 : options.noAck) {
@@ -240,8 +261,9 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
240
261
  return function confirmedPublish(exchange, routingKey, content, options, callback) {
241
262
  const channel = this;
242
263
  const { span, modifiedOptions } = self.createPublishSpan(self, exchange, routingKey, channel, options);
243
- if (self._config.publishHook) {
244
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => self._config.publishHook(span, {
264
+ const { publishHook } = self.getConfig();
265
+ if (publishHook) {
266
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => publishHook(span, {
245
267
  moduleVersion,
246
268
  exchange,
247
269
  routingKey,
@@ -259,8 +281,9 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
259
281
  callback === null || callback === void 0 ? void 0 : callback.call(this, err, ok);
260
282
  }
261
283
  finally {
262
- if (self._config.publishConfirmHook) {
263
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => self._config.publishConfirmHook(span, {
284
+ const { publishConfirmHook } = self.getConfig();
285
+ if (publishConfirmHook) {
286
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => publishConfirmHook(span, {
264
287
  moduleVersion,
265
288
  exchange,
266
289
  routingKey,
@@ -302,8 +325,9 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
302
325
  else {
303
326
  const channel = this;
304
327
  const { span, modifiedOptions } = self.createPublishSpan(self, exchange, routingKey, channel, options);
305
- if (self._config.publishHook) {
306
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => self._config.publishHook(span, {
328
+ const { publishHook } = self.getConfig();
329
+ if (publishHook) {
330
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => publishHook(span, {
307
331
  moduleVersion,
308
332
  exchange,
309
333
  routingKey,
@@ -368,9 +392,10 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
368
392
  channel[utils_1.CHANNEL_SPANS_NOT_ENDED] = [];
369
393
  }
370
394
  callConsumeEndHook(span, msg, rejected, endOperation) {
371
- if (!this._config.consumeEndHook)
395
+ const { consumeEndHook } = this.getConfig();
396
+ if (!consumeEndHook)
372
397
  return;
373
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => this._config.consumeEndHook(span, { msg, rejected, endOperation }), e => {
398
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => consumeEndHook(span, { msg, rejected, endOperation }), e => {
374
399
  if (e) {
375
400
  api_1.diag.error('amqplib instrumentation: consumerEndHook error', e);
376
401
  }
@@ -381,10 +406,11 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
381
406
  const currentTime = (0, core_1.hrTime)();
382
407
  const spansNotEnded = (_a = channel[utils_1.CHANNEL_SPANS_NOT_ENDED]) !== null && _a !== void 0 ? _a : [];
383
408
  let i;
409
+ const { consumeTimeoutMs } = this.getConfig();
384
410
  for (i = 0; i < spansNotEnded.length; i++) {
385
411
  const currMessage = spansNotEnded[i];
386
412
  const timeFromConsume = (0, core_1.hrTimeDuration)(currMessage.timeOfConsume, currentTime);
387
- if ((0, core_1.hrTimeToMilliseconds)(timeFromConsume) < this._config.consumeTimeoutMs) {
413
+ if ((0, core_1.hrTimeToMilliseconds)(timeFromConsume) < consumeTimeoutMs) {
388
414
  break;
389
415
  }
390
416
  this.endConsumerSpan(currMessage.msg, null, types_1.EndOperation.InstrumentationTimeout, true);
@@ -1 +1 @@
1
- {"version":3,"file":"amqplib.js","sourceRoot":"","sources":["../../src/amqplib.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAS4B;AAC5B,8CAI6B;AAC7B,oEAMwC;AACxC,8EAS6C;AAQ7C,mCAIiB;AACjB,mCAciB;AACjB,uCAA0D;AAE1D,MAAa,sBAAuB,SAAQ,qCAAmB;IAG7D,YAAY,SAAuC,EAAE;QACnD,KAAK,CACH,sBAAY,EACZ,yBAAe,EACf,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,sBAAc,EAAE,MAAM,CAAC,CAC1C,CAAC;IACJ,CAAC;IAEQ,SAAS,CAAC,SAAuC,EAAE;QAC1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,sBAAc,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IAES,IAAI;QACZ,MAAM,sBAAs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G,aAAa,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,eAAe,GAAG,IAAA,qBAAc,EACpC,WAAW,CAAC,aAAa,EACzB,WAAW,CACZ,CAAC;YACF,IACE,IAAA,2BAAoB,EAAC,eAAe,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAiB,EACtE;gBACA,MAAM;aACP;YACD,IAAI,CAAC,eAAe,CAClB,WAAW,CAAC,GAAG,EACf,IAAI,EACJ,oBAAY,CAAC,sBAAsB,EACnC,IAAI,CACL,CAAC;SACH;QACD,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC;CACF;AA9pBD,wDA8pBC","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 */\nimport {\n context,\n diag,\n propagation,\n trace,\n Span,\n SpanKind,\n SpanStatusCode,\n ROOT_CONTEXT,\n} from '@opentelemetry/api';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n SEMATTRS_MESSAGING_DESTINATION,\n SEMATTRS_MESSAGING_DESTINATION_KIND,\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY,\n SEMATTRS_MESSAGING_OPERATION,\n MESSAGINGOPERATIONVALUES_PROCESS,\n SEMATTRS_MESSAGING_MESSAGE_ID,\n SEMATTRS_MESSAGING_CONVERSATION_ID,\n} from '@opentelemetry/semantic-conventions';\nimport type {\n Connection,\n ConsumeMessage,\n Message,\n Options,\n Replies,\n} from 'amqplib';\nimport {\n AmqplibInstrumentationConfig,\n DEFAULT_CONFIG,\n EndOperation,\n} from './types';\nimport {\n CHANNEL_CONSUME_TIMEOUT_TIMER,\n CHANNEL_SPANS_NOT_ENDED,\n CONNECTION_ATTRIBUTES,\n getConnectionAttributesFromServer,\n getConnectionAttributesFromUrl,\n InstrumentationConsumeChannel,\n InstrumentationMessage,\n InstrumentationPublishChannel,\n isConfirmChannelTracing,\n markConfirmChannelTracing,\n MESSAGE_STORED_SPAN,\n normalizeExchange,\n unmarkConfirmChannelTracing,\n} from './utils';\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nexport class AmqplibInstrumentation extends InstrumentationBase {\n protected override _config!: AmqplibInstrumentationConfig;\n\n constructor(config: AmqplibInstrumentationConfig = {}) {\n super(\n PACKAGE_NAME,\n PACKAGE_VERSION,\n Object.assign({}, DEFAULT_CONFIG, config)\n );\n }\n\n override setConfig(config: AmqplibInstrumentationConfig = {}) {\n this._config = Object.assign({}, DEFAULT_CONFIG, config);\n }\n\n protected init() {\n const channelModelModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/channel_model.js',\n ['>=0.5.5'],\n this.patchChannelModel.bind(this),\n this.unpatchChannelModel.bind(this)\n );\n\n const callbackModelModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/callback_model.js',\n ['>=0.5.5'],\n this.patchChannelModel.bind(this),\n this.unpatchChannelModel.bind(this)\n );\n\n const connectModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/connect.js',\n ['>=0.5.5'],\n this.patchConnect.bind(this),\n this.unpatchConnect.bind(this)\n );\n\n const module = new InstrumentationNodeModuleDefinition(\n 'amqplib',\n ['>=0.5.5'],\n undefined,\n undefined,\n [channelModelModuleFile, connectModuleFile, callbackModelModuleFile]\n );\n return module;\n }\n\n private patchConnect(moduleExports: any) {\n moduleExports = this.unpatchConnect(moduleExports);\n if (!isWrapped(moduleExports.connect)) {\n this._wrap(moduleExports, 'connect', this.getConnectPatch.bind(this));\n }\n return moduleExports;\n }\n\n private unpatchConnect(moduleExports: any) {\n if (isWrapped(moduleExports.connect)) {\n this._unwrap(moduleExports, 'connect');\n }\n return moduleExports;\n }\n\n private patchChannelModel(\n moduleExports: any,\n moduleVersion: string | undefined\n ) {\n if (!isWrapped(moduleExports.Channel.prototype.publish)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'publish',\n this.getPublishPatch.bind(this, moduleVersion)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.consume)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'consume',\n this.getConsumePatch.bind(this, moduleVersion)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.ack)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'ack',\n this.getAckPatch.bind(this, false, EndOperation.Ack)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.nack)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'nack',\n this.getAckPatch.bind(this, true, EndOperation.Nack)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.reject)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'reject',\n this.getAckPatch.bind(this, true, EndOperation.Reject)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.ackAll)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'ackAll',\n this.getAckAllPatch.bind(this, false, EndOperation.AckAll)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.nackAll)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'nackAll',\n this.getAckAllPatch.bind(this, true, EndOperation.NackAll)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.emit)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'emit',\n this.getChannelEmitPatch.bind(this)\n );\n }\n if (!isWrapped(moduleExports.ConfirmChannel.prototype.publish)) {\n this._wrap(\n moduleExports.ConfirmChannel.prototype,\n 'publish',\n this.getConfirmedPublishPatch.bind(this, moduleVersion)\n );\n }\n return moduleExports;\n }\n\n private unpatchChannelModel(moduleExports: any) {\n if (isWrapped(moduleExports.Channel.prototype.publish)) {\n this._unwrap(moduleExports.Channel.prototype, 'publish');\n }\n if (isWrapped(moduleExports.Channel.prototype.consume)) {\n this._unwrap(moduleExports.Channel.prototype, 'consume');\n }\n if (isWrapped(moduleExports.Channel.prototype.ack)) {\n this._unwrap(moduleExports.Channel.prototype, 'ack');\n }\n if (isWrapped(moduleExports.Channel.prototype.nack)) {\n this._unwrap(moduleExports.Channel.prototype, 'nack');\n }\n if (isWrapped(moduleExports.Channel.prototype.reject)) {\n this._unwrap(moduleExports.Channel.prototype, 'reject');\n }\n if (isWrapped(moduleExports.Channel.prototype.ackAll)) {\n this._unwrap(moduleExports.Channel.prototype, 'ackAll');\n }\n if (isWrapped(moduleExports.Channel.prototype.nackAll)) {\n this._unwrap(moduleExports.Channel.prototype, 'nackAll');\n }\n if (isWrapped(moduleExports.Channel.prototype.emit)) {\n this._unwrap(moduleExports.Channel.prototype, 'emit');\n }\n if (isWrapped(moduleExports.ConfirmChannel.prototype.publish)) {\n this._unwrap(moduleExports.ConfirmChannel.prototype, 'publish');\n }\n return moduleExports;\n }\n\n private getConnectPatch(\n original: (\n url: string | Options.Connect,\n socketOptions: any,\n openCallback: (err: any, connection: Connection) => void\n ) => Connection\n ) {\n return function patchedConnect(\n this: unknown,\n url: string | Options.Connect,\n socketOptions: any,\n openCallback: Function\n ) {\n return original.call(\n this,\n url,\n socketOptions,\n function (this: unknown, err, conn: Connection) {\n if (err == null) {\n const urlAttributes = getConnectionAttributesFromUrl(url);\n // the type of conn in @types/amqplib is amqp.Connection, but in practice the library send the\n // `serverProperties` on the `conn` and not in a property `connection`.\n // I don't have capacity to debug it currently but it should probably be fixed in @types or\n // in the package itself\n // currently setting as any to calm typescript\n const serverAttributes = getConnectionAttributesFromServer(\n conn as any\n );\n (conn as any)[CONNECTION_ATTRIBUTES] = {\n ...urlAttributes,\n ...serverAttributes,\n };\n }\n openCallback.apply(this, arguments);\n }\n );\n };\n }\n\n private getChannelEmitPatch(original: Function) {\n const self = this;\n return function emit(\n this: InstrumentationConsumeChannel,\n eventName: string\n ) {\n if (eventName === 'close') {\n self.endAllSpansOnChannel(\n this,\n true,\n EndOperation.ChannelClosed,\n undefined\n );\n const activeTimer = this[CHANNEL_CONSUME_TIMEOUT_TIMER];\n if (activeTimer) {\n clearInterval(activeTimer);\n }\n this[CHANNEL_CONSUME_TIMEOUT_TIMER] = undefined;\n } else if (eventName === 'error') {\n self.endAllSpansOnChannel(\n this,\n true,\n EndOperation.ChannelError,\n undefined\n );\n }\n return original.apply(this, arguments);\n };\n }\n\n private getAckAllPatch(\n isRejected: boolean,\n endOperation: EndOperation,\n original: Function\n ) {\n const self = this;\n return function ackAll(\n this: InstrumentationConsumeChannel,\n requeueOrEmpty?: boolean\n ): void {\n self.endAllSpansOnChannel(this, isRejected, endOperation, requeueOrEmpty);\n return original.apply(this, arguments);\n };\n }\n\n private getAckPatch(\n isRejected: boolean,\n endOperation: EndOperation,\n original: Function\n ) {\n const self = this;\n return function ack(\n this: InstrumentationConsumeChannel,\n message: Message,\n allUpToOrRequeue?: boolean,\n requeue?: boolean\n ): void {\n const channel = this;\n // we use this patch in reject function as well, but it has different signature\n const requeueResolved =\n endOperation === EndOperation.Reject ? allUpToOrRequeue : requeue;\n\n const spansNotEnded: { msg: Message }[] =\n channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n const msgIndex = spansNotEnded.findIndex(\n msgDetails => msgDetails.msg === message\n );\n if (msgIndex < 0) {\n // should not happen in happy flow\n // but possible if user is calling the api function ack twice with same message\n self.endConsumerSpan(\n message,\n isRejected,\n endOperation,\n requeueResolved\n );\n } else if (endOperation !== EndOperation.Reject && allUpToOrRequeue) {\n for (let i = 0; i <= msgIndex; i++) {\n self.endConsumerSpan(\n spansNotEnded[i].msg,\n isRejected,\n endOperation,\n requeueResolved\n );\n }\n spansNotEnded.splice(0, msgIndex + 1);\n } else {\n self.endConsumerSpan(\n message,\n isRejected,\n endOperation,\n requeueResolved\n );\n spansNotEnded.splice(msgIndex, 1);\n }\n return original.apply(this, arguments);\n };\n }\n\n private getConsumePatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function consume(\n this: InstrumentationConsumeChannel,\n queue: string,\n onMessage: (msg: ConsumeMessage | null) => void,\n options?: Options.Consume\n ): Promise<Replies.Consume> {\n const channel = this;\n if (\n !Object.prototype.hasOwnProperty.call(channel, CHANNEL_SPANS_NOT_ENDED)\n ) {\n if (self._config.consumeTimeoutMs) {\n const timer = setInterval(() => {\n self.checkConsumeTimeoutOnChannel(channel);\n }, self._config.consumeTimeoutMs);\n timer.unref();\n channel[CHANNEL_CONSUME_TIMEOUT_TIMER] = timer;\n }\n channel[CHANNEL_SPANS_NOT_ENDED] = [];\n }\n\n const patchedOnMessage = function (\n this: unknown,\n msg: InstrumentationMessage | null\n ) {\n // msg is expected to be null for signaling consumer cancel notification\n // https://www.rabbitmq.com/consumer-cancel.html\n // in this case, we do not start a span, as this is not a real message.\n if (!msg) {\n return onMessage.call(this, msg);\n }\n\n const headers = msg.properties.headers ?? {};\n const parentContext = propagation.extract(ROOT_CONTEXT, headers);\n const exchange = msg.fields?.exchange;\n const span = self.tracer.startSpan(\n `${queue} process`,\n {\n kind: SpanKind.CONSUMER,\n attributes: {\n ...channel?.connection?.[CONNECTION_ATTRIBUTES],\n [SEMATTRS_MESSAGING_DESTINATION]: exchange,\n [SEMATTRS_MESSAGING_DESTINATION_KIND]:\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: msg.fields?.routingKey,\n [SEMATTRS_MESSAGING_OPERATION]: MESSAGINGOPERATIONVALUES_PROCESS,\n [SEMATTRS_MESSAGING_MESSAGE_ID]: msg?.properties.messageId,\n [SEMATTRS_MESSAGING_CONVERSATION_ID]:\n msg?.properties.correlationId,\n },\n },\n parentContext\n );\n\n if (self._config.consumeHook) {\n safeExecuteInTheMiddle(\n () => self._config.consumeHook!(span, { moduleVersion, msg }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: consumerHook error', e);\n }\n },\n true\n );\n }\n\n if (!options?.noAck) {\n // store the message on the channel so we can close the span on ackAll etc\n channel[CHANNEL_SPANS_NOT_ENDED]!.push({\n msg,\n timeOfConsume: hrTime(),\n });\n\n // store the span on the message, so we can end it when user call 'ack' on it\n msg[MESSAGE_STORED_SPAN] = span;\n }\n\n context.with(trace.setSpan(parentContext, span), () => {\n onMessage.call(this, msg);\n });\n\n if (options?.noAck) {\n self.callConsumeEndHook(span, msg, false, EndOperation.AutoAck);\n span.end();\n }\n };\n arguments[1] = patchedOnMessage;\n return original.apply(this, arguments);\n };\n }\n\n private getConfirmedPublishPatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function confirmedPublish(\n this: InstrumentationConsumeChannel,\n exchange: string,\n routingKey: string,\n content: Buffer,\n options?: Options.Publish,\n callback?: (err: any, ok: Replies.Empty) => void\n ): boolean {\n const channel = this;\n const { span, modifiedOptions } = self.createPublishSpan(\n self,\n exchange,\n routingKey,\n channel,\n options\n );\n\n if (self._config.publishHook) {\n safeExecuteInTheMiddle(\n () =>\n self._config.publishHook!(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options: modifiedOptions,\n isConfirmChannel: true,\n }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: publishHook error', e);\n }\n },\n true\n );\n }\n\n const patchedOnConfirm = function (\n this: unknown,\n err: any,\n ok: Replies.Empty\n ) {\n try {\n callback?.call(this, err, ok);\n } finally {\n if (self._config.publishConfirmHook) {\n safeExecuteInTheMiddle(\n () =>\n self._config.publishConfirmHook!(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options,\n isConfirmChannel: true,\n confirmError: err,\n }),\n e => {\n if (e) {\n diag.error(\n 'amqplib instrumentation: publishConfirmHook error',\n e\n );\n }\n },\n true\n );\n }\n\n if (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: \"message confirmation has been nack'ed\",\n });\n }\n span.end();\n }\n };\n\n // calling confirm channel publish function is storing the message in queue and registering the callback for broker confirm.\n // span ends in the patched callback.\n const markedContext = markConfirmChannelTracing(context.active());\n const argumentsCopy = [...arguments];\n argumentsCopy[3] = modifiedOptions;\n argumentsCopy[4] = context.bind(\n unmarkConfirmChannelTracing(trace.setSpan(markedContext, span)),\n patchedOnConfirm\n );\n return context.with(markedContext, original.bind(this, ...argumentsCopy));\n };\n }\n\n private getPublishPatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function publish(\n this: InstrumentationPublishChannel,\n exchange: string,\n routingKey: string,\n content: Buffer,\n options?: Options.Publish\n ): boolean {\n if (isConfirmChannelTracing(context.active())) {\n // work already done\n return original.apply(this, arguments);\n } else {\n const channel = this;\n const { span, modifiedOptions } = self.createPublishSpan(\n self,\n exchange,\n routingKey,\n channel,\n options\n );\n\n if (self._config.publishHook) {\n safeExecuteInTheMiddle(\n () =>\n self._config.publishHook!(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options: modifiedOptions,\n isConfirmChannel: false,\n }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: publishHook error', e);\n }\n },\n true\n );\n }\n\n // calling normal channel publish function is only storing the message in queue.\n // it does not send it and waits for an ack, so the span duration is expected to be very short.\n const argumentsCopy = [...arguments];\n argumentsCopy[3] = modifiedOptions;\n const originalRes = original.apply(this, argumentsCopy as any);\n span.end();\n return originalRes;\n }\n };\n }\n\n private createPublishSpan(\n self: this,\n exchange: string,\n routingKey: string,\n channel: InstrumentationPublishChannel,\n options?: Options.Publish\n ) {\n const normalizedExchange = normalizeExchange(exchange);\n\n const span = self.tracer.startSpan(\n `${normalizedExchange} -> ${routingKey} send`,\n {\n kind: SpanKind.PRODUCER,\n attributes: {\n ...channel.connection[CONNECTION_ATTRIBUTES],\n [SEMATTRS_MESSAGING_DESTINATION]: exchange,\n [SEMATTRS_MESSAGING_DESTINATION_KIND]:\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,\n [SEMATTRS_MESSAGING_MESSAGE_ID]: options?.messageId,\n [SEMATTRS_MESSAGING_CONVERSATION_ID]: options?.correlationId,\n },\n }\n );\n const modifiedOptions = options ?? {};\n modifiedOptions.headers = modifiedOptions.headers ?? {};\n\n propagation.inject(\n trace.setSpan(context.active(), span),\n modifiedOptions.headers\n );\n\n return { span, modifiedOptions };\n }\n\n private endConsumerSpan(\n message: InstrumentationMessage,\n isRejected: boolean | null,\n operation: EndOperation,\n requeue: boolean | undefined\n ) {\n const storedSpan: Span | undefined = message[MESSAGE_STORED_SPAN];\n if (!storedSpan) return;\n if (isRejected !== false) {\n storedSpan.setStatus({\n code: SpanStatusCode.ERROR,\n message:\n operation !== EndOperation.ChannelClosed &&\n operation !== EndOperation.ChannelError\n ? `${operation} called on message${\n requeue === true\n ? ' with requeue'\n : requeue === false\n ? ' without requeue'\n : ''\n }`\n : operation,\n });\n }\n this.callConsumeEndHook(storedSpan, message, isRejected, operation);\n storedSpan.end();\n message[MESSAGE_STORED_SPAN] = undefined;\n }\n\n private endAllSpansOnChannel(\n channel: InstrumentationConsumeChannel,\n isRejected: boolean,\n operation: EndOperation,\n requeue: boolean | undefined\n ) {\n const spansNotEnded: { msg: Message }[] =\n channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n spansNotEnded.forEach(msgDetails => {\n this.endConsumerSpan(msgDetails.msg, isRejected, operation, requeue);\n });\n channel[CHANNEL_SPANS_NOT_ENDED] = [];\n }\n\n private callConsumeEndHook(\n span: Span,\n msg: ConsumeMessage,\n rejected: boolean | null,\n endOperation: EndOperation\n ) {\n if (!this._config.consumeEndHook) return;\n\n safeExecuteInTheMiddle(\n () => this._config.consumeEndHook!(span, { msg, rejected, endOperation }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: consumerEndHook error', e);\n }\n },\n true\n );\n }\n\n private checkConsumeTimeoutOnChannel(channel: InstrumentationConsumeChannel) {\n const currentTime = hrTime();\n const spansNotEnded = channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n let i: number;\n for (i = 0; i < spansNotEnded.length; i++) {\n const currMessage = spansNotEnded[i];\n const timeFromConsume = hrTimeDuration(\n currMessage.timeOfConsume,\n currentTime\n );\n if (\n hrTimeToMilliseconds(timeFromConsume) < this._config.consumeTimeoutMs!\n ) {\n break;\n }\n this.endConsumerSpan(\n currMessage.msg,\n null,\n EndOperation.InstrumentationTimeout,\n true\n );\n }\n spansNotEnded.splice(0, i);\n }\n}\n"]}
1
+ {"version":3,"file":"amqplib.js","sourceRoot":"","sources":["../../src/amqplib.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAW4B;AAC5B,8CAI6B;AAC7B,oEAMwC;AACxC,8EAS6C;AAQ7C,mCAIiB;AACjB,mCAciB;AACjB,uCAA0D;AAE1D,MAAM,iBAAiB,GAAG,CAAC,YAAY,CAAC,CAAC;AAEzC,MAAa,sBAAuB,SAAQ,qCAAiD;IAC3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,kCAAO,sBAAc,GAAK,MAAM,EAAG,CAAC;IACzE,CAAC;IAEQ,SAAS,CAAC,SAAuC,EAAE;QAC1D,KAAK,CAAC,SAAS,iCAAM,sBAAc,GAAK,MAAM,EAAG,CAAC;IACpD,CAAC;IAES,IAAI;QACZ,MAAM,sBAAsB,GAAG,IAAI,+CAA6B,CAC9D,8BAA8B,EAC9B,iBAAiB,EACjB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EACjC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;QAEF,MAAM,uB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CAAC,CAAC;aACjE;QACH,CAAC,EACD,IAAI,CACL,CAAC;IACJ,CAAC;IAEO,4BAA4B,CAAC,OAAsC;;QACzE,MAAM,WAAW,GAAG,IAAA,aAAM,GAAE,CAAC;QAC7B,MAAM,aAAa,GAAG,MAAA,OAAO,CAAC,+BAAuB,CAAC,mCAAI,EAAE,CAAC;QAC7D,IAAI,CAAS,CAAC;QACd,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC9C,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACzC,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,eAAe,GAAG,IAAA,qBAAc,EACpC,WAAW,CAAC,aAAa,EACzB,WAAW,CACZ,CAAC;YACF,IAAI,IAAA,2BAAoB,EAAC,eAAe,CAAC,GAAG,gBAAiB,EAAE;gBAC7D,MAAM;aACP;YACD,IAAI,CAAC,eAAe,CAClB,WAAW,CAAC,GAAG,EACf,IAAI,EACJ,oBAAY,CAAC,sBAAsB,EACnC,IAAI,CACL,CAAC;SACH;QACD,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC;CACF;AAjrBD,wDAirBC","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 */\nimport {\n context,\n diag,\n propagation,\n trace,\n Span,\n SpanKind,\n SpanStatusCode,\n ROOT_CONTEXT,\n Link,\n Context,\n} from '@opentelemetry/api';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n SEMATTRS_MESSAGING_DESTINATION,\n SEMATTRS_MESSAGING_DESTINATION_KIND,\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY,\n SEMATTRS_MESSAGING_OPERATION,\n MESSAGINGOPERATIONVALUES_PROCESS,\n SEMATTRS_MESSAGING_MESSAGE_ID,\n SEMATTRS_MESSAGING_CONVERSATION_ID,\n} from '@opentelemetry/semantic-conventions';\nimport type {\n Connection,\n ConsumeMessage,\n Message,\n Options,\n Replies,\n} from 'amqplib';\nimport {\n AmqplibInstrumentationConfig,\n DEFAULT_CONFIG,\n EndOperation,\n} from './types';\nimport {\n CHANNEL_CONSUME_TIMEOUT_TIMER,\n CHANNEL_SPANS_NOT_ENDED,\n CONNECTION_ATTRIBUTES,\n getConnectionAttributesFromServer,\n getConnectionAttributesFromUrl,\n InstrumentationConsumeChannel,\n InstrumentationMessage,\n InstrumentationPublishChannel,\n isConfirmChannelTracing,\n markConfirmChannelTracing,\n MESSAGE_STORED_SPAN,\n normalizeExchange,\n unmarkConfirmChannelTracing,\n} from './utils';\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst supportedVersions = ['>=0.5.5 <1'];\n\nexport class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumentationConfig> {\n constructor(config: AmqplibInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config });\n }\n\n override setConfig(config: AmqplibInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n protected init() {\n const channelModelModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/channel_model.js',\n supportedVersions,\n this.patchChannelModel.bind(this),\n this.unpatchChannelModel.bind(this)\n );\n\n const callbackModelModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/callback_model.js',\n supportedVersions,\n this.patchChannelModel.bind(this),\n this.unpatchChannelModel.bind(this)\n );\n\n const connectModuleFile = new InstrumentationNodeModuleFile(\n 'amqplib/lib/connect.js',\n supportedVersions,\n this.patchConnect.bind(this),\n this.unpatchConnect.bind(this)\n );\n\n const module = new InstrumentationNodeModuleDefinition(\n 'amqplib',\n supportedVersions,\n undefined,\n undefined,\n [channelModelModuleFile, connectModuleFile, callbackModelModuleFile]\n );\n return module;\n }\n\n private patchConnect(moduleExports: any) {\n moduleExports = this.unpatchConnect(moduleExports);\n if (!isWrapped(moduleExports.connect)) {\n this._wrap(moduleExports, 'connect', this.getConnectPatch.bind(this));\n }\n return moduleExports;\n }\n\n private unpatchConnect(moduleExports: any) {\n if (isWrapped(moduleExports.connect)) {\n this._unwrap(moduleExports, 'connect');\n }\n return moduleExports;\n }\n\n private patchChannelModel(\n moduleExports: any,\n moduleVersion: string | undefined\n ) {\n if (!isWrapped(moduleExports.Channel.prototype.publish)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'publish',\n this.getPublishPatch.bind(this, moduleVersion)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.consume)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'consume',\n this.getConsumePatch.bind(this, moduleVersion)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.ack)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'ack',\n this.getAckPatch.bind(this, false, EndOperation.Ack)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.nack)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'nack',\n this.getAckPatch.bind(this, true, EndOperation.Nack)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.reject)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'reject',\n this.getAckPatch.bind(this, true, EndOperation.Reject)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.ackAll)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'ackAll',\n this.getAckAllPatch.bind(this, false, EndOperation.AckAll)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.nackAll)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'nackAll',\n this.getAckAllPatch.bind(this, true, EndOperation.NackAll)\n );\n }\n if (!isWrapped(moduleExports.Channel.prototype.emit)) {\n this._wrap(\n moduleExports.Channel.prototype,\n 'emit',\n this.getChannelEmitPatch.bind(this)\n );\n }\n if (!isWrapped(moduleExports.ConfirmChannel.prototype.publish)) {\n this._wrap(\n moduleExports.ConfirmChannel.prototype,\n 'publish',\n this.getConfirmedPublishPatch.bind(this, moduleVersion)\n );\n }\n return moduleExports;\n }\n\n private unpatchChannelModel(moduleExports: any) {\n if (isWrapped(moduleExports.Channel.prototype.publish)) {\n this._unwrap(moduleExports.Channel.prototype, 'publish');\n }\n if (isWrapped(moduleExports.Channel.prototype.consume)) {\n this._unwrap(moduleExports.Channel.prototype, 'consume');\n }\n if (isWrapped(moduleExports.Channel.prototype.ack)) {\n this._unwrap(moduleExports.Channel.prototype, 'ack');\n }\n if (isWrapped(moduleExports.Channel.prototype.nack)) {\n this._unwrap(moduleExports.Channel.prototype, 'nack');\n }\n if (isWrapped(moduleExports.Channel.prototype.reject)) {\n this._unwrap(moduleExports.Channel.prototype, 'reject');\n }\n if (isWrapped(moduleExports.Channel.prototype.ackAll)) {\n this._unwrap(moduleExports.Channel.prototype, 'ackAll');\n }\n if (isWrapped(moduleExports.Channel.prototype.nackAll)) {\n this._unwrap(moduleExports.Channel.prototype, 'nackAll');\n }\n if (isWrapped(moduleExports.Channel.prototype.emit)) {\n this._unwrap(moduleExports.Channel.prototype, 'emit');\n }\n if (isWrapped(moduleExports.ConfirmChannel.prototype.publish)) {\n this._unwrap(moduleExports.ConfirmChannel.prototype, 'publish');\n }\n return moduleExports;\n }\n\n private getConnectPatch(\n original: (\n url: string | Options.Connect,\n socketOptions: any,\n openCallback: (err: any, connection: Connection) => void\n ) => Connection\n ) {\n return function patchedConnect(\n this: unknown,\n url: string | Options.Connect,\n socketOptions: any,\n openCallback: Function\n ) {\n return original.call(\n this,\n url,\n socketOptions,\n function (this: unknown, err, conn: Connection) {\n if (err == null) {\n const urlAttributes = getConnectionAttributesFromUrl(url);\n // the type of conn in @types/amqplib is amqp.Connection, but in practice the library send the\n // `serverProperties` on the `conn` and not in a property `connection`.\n // I don't have capacity to debug it currently but it should probably be fixed in @types or\n // in the package itself\n // currently setting as any to calm typescript\n const serverAttributes = getConnectionAttributesFromServer(\n conn as any\n );\n (conn as any)[CONNECTION_ATTRIBUTES] = {\n ...urlAttributes,\n ...serverAttributes,\n };\n }\n openCallback.apply(this, arguments);\n }\n );\n };\n }\n\n private getChannelEmitPatch(original: Function) {\n const self = this;\n return function emit(\n this: InstrumentationConsumeChannel,\n eventName: string\n ) {\n if (eventName === 'close') {\n self.endAllSpansOnChannel(\n this,\n true,\n EndOperation.ChannelClosed,\n undefined\n );\n const activeTimer = this[CHANNEL_CONSUME_TIMEOUT_TIMER];\n if (activeTimer) {\n clearInterval(activeTimer);\n }\n this[CHANNEL_CONSUME_TIMEOUT_TIMER] = undefined;\n } else if (eventName === 'error') {\n self.endAllSpansOnChannel(\n this,\n true,\n EndOperation.ChannelError,\n undefined\n );\n }\n return original.apply(this, arguments);\n };\n }\n\n private getAckAllPatch(\n isRejected: boolean,\n endOperation: EndOperation,\n original: Function\n ) {\n const self = this;\n return function ackAll(\n this: InstrumentationConsumeChannel,\n requeueOrEmpty?: boolean\n ): void {\n self.endAllSpansOnChannel(this, isRejected, endOperation, requeueOrEmpty);\n return original.apply(this, arguments);\n };\n }\n\n private getAckPatch(\n isRejected: boolean,\n endOperation: EndOperation,\n original: Function\n ) {\n const self = this;\n return function ack(\n this: InstrumentationConsumeChannel,\n message: Message,\n allUpToOrRequeue?: boolean,\n requeue?: boolean\n ): void {\n const channel = this;\n // we use this patch in reject function as well, but it has different signature\n const requeueResolved =\n endOperation === EndOperation.Reject ? allUpToOrRequeue : requeue;\n\n const spansNotEnded: { msg: Message }[] =\n channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n const msgIndex = spansNotEnded.findIndex(\n msgDetails => msgDetails.msg === message\n );\n if (msgIndex < 0) {\n // should not happen in happy flow\n // but possible if user is calling the api function ack twice with same message\n self.endConsumerSpan(\n message,\n isRejected,\n endOperation,\n requeueResolved\n );\n } else if (endOperation !== EndOperation.Reject && allUpToOrRequeue) {\n for (let i = 0; i <= msgIndex; i++) {\n self.endConsumerSpan(\n spansNotEnded[i].msg,\n isRejected,\n endOperation,\n requeueResolved\n );\n }\n spansNotEnded.splice(0, msgIndex + 1);\n } else {\n self.endConsumerSpan(\n message,\n isRejected,\n endOperation,\n requeueResolved\n );\n spansNotEnded.splice(msgIndex, 1);\n }\n return original.apply(this, arguments);\n };\n }\n\n private getConsumePatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function consume(\n this: InstrumentationConsumeChannel,\n queue: string,\n onMessage: (msg: ConsumeMessage | null) => void,\n options?: Options.Consume\n ): Promise<Replies.Consume> {\n const channel = this;\n if (\n !Object.prototype.hasOwnProperty.call(channel, CHANNEL_SPANS_NOT_ENDED)\n ) {\n const { consumeTimeoutMs } = self.getConfig();\n if (consumeTimeoutMs) {\n const timer = setInterval(() => {\n self.checkConsumeTimeoutOnChannel(channel);\n }, consumeTimeoutMs);\n timer.unref();\n channel[CHANNEL_CONSUME_TIMEOUT_TIMER] = timer;\n }\n channel[CHANNEL_SPANS_NOT_ENDED] = [];\n }\n\n const patchedOnMessage = function (\n this: unknown,\n msg: InstrumentationMessage | null\n ) {\n // msg is expected to be null for signaling consumer cancel notification\n // https://www.rabbitmq.com/consumer-cancel.html\n // in this case, we do not start a span, as this is not a real message.\n if (!msg) {\n return onMessage.call(this, msg);\n }\n\n const headers = msg.properties.headers ?? {};\n let parentContext: Context | undefined = propagation.extract(\n ROOT_CONTEXT,\n headers\n );\n const exchange = msg.fields?.exchange;\n let links: Link[] | undefined;\n if (self._config.useLinksForConsume) {\n const parentSpanContext = parentContext\n ? trace.getSpan(parentContext)?.spanContext()\n : undefined;\n parentContext = undefined;\n if (parentSpanContext) {\n links = [\n {\n context: parentSpanContext,\n },\n ];\n }\n }\n const span = self.tracer.startSpan(\n `${queue} process`,\n {\n kind: SpanKind.CONSUMER,\n attributes: {\n ...channel?.connection?.[CONNECTION_ATTRIBUTES],\n [SEMATTRS_MESSAGING_DESTINATION]: exchange,\n [SEMATTRS_MESSAGING_DESTINATION_KIND]:\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: msg.fields?.routingKey,\n [SEMATTRS_MESSAGING_OPERATION]: MESSAGINGOPERATIONVALUES_PROCESS,\n [SEMATTRS_MESSAGING_MESSAGE_ID]: msg?.properties.messageId,\n [SEMATTRS_MESSAGING_CONVERSATION_ID]:\n msg?.properties.correlationId,\n },\n links,\n },\n parentContext\n );\n\n const { consumeHook } = self.getConfig();\n if (consumeHook) {\n safeExecuteInTheMiddle(\n () => consumeHook(span, { moduleVersion, msg }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: consumerHook error', e);\n }\n },\n true\n );\n }\n\n if (!options?.noAck) {\n // store the message on the channel so we can close the span on ackAll etc\n channel[CHANNEL_SPANS_NOT_ENDED]!.push({\n msg,\n timeOfConsume: hrTime(),\n });\n\n // store the span on the message, so we can end it when user call 'ack' on it\n msg[MESSAGE_STORED_SPAN] = span;\n }\n const setContext: Context = parentContext\n ? parentContext\n : ROOT_CONTEXT;\n context.with(trace.setSpan(setContext, span), () => {\n onMessage.call(this, msg);\n });\n\n if (options?.noAck) {\n self.callConsumeEndHook(span, msg, false, EndOperation.AutoAck);\n span.end();\n }\n };\n arguments[1] = patchedOnMessage;\n return original.apply(this, arguments);\n };\n }\n\n private getConfirmedPublishPatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function confirmedPublish(\n this: InstrumentationConsumeChannel,\n exchange: string,\n routingKey: string,\n content: Buffer,\n options?: Options.Publish,\n callback?: (err: any, ok: Replies.Empty) => void\n ): boolean {\n const channel = this;\n const { span, modifiedOptions } = self.createPublishSpan(\n self,\n exchange,\n routingKey,\n channel,\n options\n );\n\n const { publishHook } = self.getConfig();\n if (publishHook) {\n safeExecuteInTheMiddle(\n () =>\n publishHook(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options: modifiedOptions,\n isConfirmChannel: true,\n }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: publishHook error', e);\n }\n },\n true\n );\n }\n\n const patchedOnConfirm = function (\n this: unknown,\n err: any,\n ok: Replies.Empty\n ) {\n try {\n callback?.call(this, err, ok);\n } finally {\n const { publishConfirmHook } = self.getConfig();\n if (publishConfirmHook) {\n safeExecuteInTheMiddle(\n () =>\n publishConfirmHook(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options,\n isConfirmChannel: true,\n confirmError: err,\n }),\n e => {\n if (e) {\n diag.error(\n 'amqplib instrumentation: publishConfirmHook error',\n e\n );\n }\n },\n true\n );\n }\n\n if (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: \"message confirmation has been nack'ed\",\n });\n }\n span.end();\n }\n };\n\n // calling confirm channel publish function is storing the message in queue and registering the callback for broker confirm.\n // span ends in the patched callback.\n const markedContext = markConfirmChannelTracing(context.active());\n const argumentsCopy = [...arguments];\n argumentsCopy[3] = modifiedOptions;\n argumentsCopy[4] = context.bind(\n unmarkConfirmChannelTracing(trace.setSpan(markedContext, span)),\n patchedOnConfirm\n );\n return context.with(markedContext, original.bind(this, ...argumentsCopy));\n };\n }\n\n private getPublishPatch(\n moduleVersion: string | undefined,\n original: Function\n ) {\n const self = this;\n return function publish(\n this: InstrumentationPublishChannel,\n exchange: string,\n routingKey: string,\n content: Buffer,\n options?: Options.Publish\n ): boolean {\n if (isConfirmChannelTracing(context.active())) {\n // work already done\n return original.apply(this, arguments);\n } else {\n const channel = this;\n const { span, modifiedOptions } = self.createPublishSpan(\n self,\n exchange,\n routingKey,\n channel,\n options\n );\n\n const { publishHook } = self.getConfig();\n if (publishHook) {\n safeExecuteInTheMiddle(\n () =>\n publishHook(span, {\n moduleVersion,\n exchange,\n routingKey,\n content,\n options: modifiedOptions,\n isConfirmChannel: false,\n }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: publishHook error', e);\n }\n },\n true\n );\n }\n\n // calling normal channel publish function is only storing the message in queue.\n // it does not send it and waits for an ack, so the span duration is expected to be very short.\n const argumentsCopy = [...arguments];\n argumentsCopy[3] = modifiedOptions;\n const originalRes = original.apply(this, argumentsCopy as any);\n span.end();\n return originalRes;\n }\n };\n }\n\n private createPublishSpan(\n self: this,\n exchange: string,\n routingKey: string,\n channel: InstrumentationPublishChannel,\n options?: Options.Publish\n ) {\n const normalizedExchange = normalizeExchange(exchange);\n\n const span = self.tracer.startSpan(\n `${normalizedExchange} -> ${routingKey} send`,\n {\n kind: SpanKind.PRODUCER,\n attributes: {\n ...channel.connection[CONNECTION_ATTRIBUTES],\n [SEMATTRS_MESSAGING_DESTINATION]: exchange,\n [SEMATTRS_MESSAGING_DESTINATION_KIND]:\n MESSAGINGDESTINATIONKINDVALUES_TOPIC,\n [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,\n [SEMATTRS_MESSAGING_MESSAGE_ID]: options?.messageId,\n [SEMATTRS_MESSAGING_CONVERSATION_ID]: options?.correlationId,\n },\n }\n );\n const modifiedOptions = options ?? {};\n modifiedOptions.headers = modifiedOptions.headers ?? {};\n\n propagation.inject(\n trace.setSpan(context.active(), span),\n modifiedOptions.headers\n );\n\n return { span, modifiedOptions };\n }\n\n private endConsumerSpan(\n message: InstrumentationMessage,\n isRejected: boolean | null,\n operation: EndOperation,\n requeue: boolean | undefined\n ) {\n const storedSpan: Span | undefined = message[MESSAGE_STORED_SPAN];\n if (!storedSpan) return;\n if (isRejected !== false) {\n storedSpan.setStatus({\n code: SpanStatusCode.ERROR,\n message:\n operation !== EndOperation.ChannelClosed &&\n operation !== EndOperation.ChannelError\n ? `${operation} called on message${\n requeue === true\n ? ' with requeue'\n : requeue === false\n ? ' without requeue'\n : ''\n }`\n : operation,\n });\n }\n this.callConsumeEndHook(storedSpan, message, isRejected, operation);\n storedSpan.end();\n message[MESSAGE_STORED_SPAN] = undefined;\n }\n\n private endAllSpansOnChannel(\n channel: InstrumentationConsumeChannel,\n isRejected: boolean,\n operation: EndOperation,\n requeue: boolean | undefined\n ) {\n const spansNotEnded: { msg: Message }[] =\n channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n spansNotEnded.forEach(msgDetails => {\n this.endConsumerSpan(msgDetails.msg, isRejected, operation, requeue);\n });\n channel[CHANNEL_SPANS_NOT_ENDED] = [];\n }\n\n private callConsumeEndHook(\n span: Span,\n msg: ConsumeMessage,\n rejected: boolean | null,\n endOperation: EndOperation\n ) {\n const { consumeEndHook } = this.getConfig();\n if (!consumeEndHook) return;\n\n safeExecuteInTheMiddle(\n () => consumeEndHook(span, { msg, rejected, endOperation }),\n e => {\n if (e) {\n diag.error('amqplib instrumentation: consumerEndHook error', e);\n }\n },\n true\n );\n }\n\n private checkConsumeTimeoutOnChannel(channel: InstrumentationConsumeChannel) {\n const currentTime = hrTime();\n const spansNotEnded = channel[CHANNEL_SPANS_NOT_ENDED] ?? [];\n let i: number;\n const { consumeTimeoutMs } = this.getConfig();\n for (i = 0; i < spansNotEnded.length; i++) {\n const currMessage = spansNotEnded[i];\n const timeFromConsume = hrTimeDuration(\n currMessage.timeOfConsume,\n currentTime\n );\n if (hrTimeToMilliseconds(timeFromConsume) < consumeTimeoutMs!) {\n break;\n }\n this.endConsumerSpan(\n currMessage.msg,\n null,\n EndOperation.InstrumentationTimeout,\n true\n );\n }\n spansNotEnded.splice(0, i);\n }\n}\n"]}
@@ -68,6 +68,8 @@ export interface AmqplibInstrumentationConfig extends InstrumentationConfig {
68
68
  * Default is 1 minute
69
69
  */
70
70
  consumeTimeoutMs?: number;
71
+ /** option to use a span link for the consume message instead of continuing a trace */
72
+ useLinksForConsume?: boolean;
71
73
  }
72
74
  export declare const DEFAULT_CONFIG: AmqplibInstrumentationConfig;
73
75
  export interface AmqplibPublishOptions {
@@ -14,6 +14,7 @@ var EndOperation;
14
14
  EndOperation["InstrumentationTimeout"] = "instrumentation timeout";
15
15
  })(EndOperation = exports.EndOperation || (exports.EndOperation = {}));
16
16
  exports.DEFAULT_CONFIG = {
17
- consumeTimeoutMs: 1000 * 60, // 1 minute
17
+ consumeTimeoutMs: 1000 * 60,
18
+ useLinksForConsume: false,
18
19
  };
19
20
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA0DA,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,oCAAoB,CAAA;IACpB,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,gDAAgC,CAAA;IAChC,8CAA8B,CAAA;IAC9B,kEAAkD,CAAA;AACpD,CAAC,EAVW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAUvB;AAgCY,QAAA,cAAc,GAAiC;IAC1D,gBAAgB,EAAE,IAAI,GAAG,EAAE,EAAE,WAAW;CACzC,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 */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport interface PublishInfo {\n moduleVersion: string | undefined;\n exchange: string;\n routingKey: string;\n content: Buffer;\n options?: AmqplibPublishOptions;\n isConfirmChannel?: boolean;\n}\n\nexport interface PublishConfirmedInfo extends PublishInfo {\n confirmError?: any;\n}\n\nexport interface ConsumeInfo {\n moduleVersion: string | undefined;\n msg: ConsumeMessage;\n}\n\nexport interface ConsumeEndInfo {\n msg: ConsumeMessage;\n rejected: boolean | null;\n endOperation: EndOperation;\n}\n\nexport interface AmqplibPublishCustomAttributeFunction {\n (span: Span, publishInfo: PublishInfo): void;\n}\n\nexport interface AmqplibPublishConfirmCustomAttributeFunction {\n (span: Span, publishConfirmedInto: PublishConfirmedInfo): void;\n}\n\nexport interface AmqplibConsumeCustomAttributeFunction {\n (span: Span, consumeInfo: ConsumeInfo): void;\n}\n\nexport interface AmqplibConsumeEndCustomAttributeFunction {\n (span: Span, consumeEndInfo: ConsumeEndInfo): void;\n}\n\nexport enum EndOperation {\n AutoAck = 'auto ack',\n Ack = 'ack',\n AckAll = 'ackAll',\n Reject = 'reject',\n Nack = 'nack',\n NackAll = 'nackAll',\n ChannelClosed = 'channel closed',\n ChannelError = 'channel error',\n InstrumentationTimeout = 'instrumentation timeout',\n}\n\nexport interface AmqplibInstrumentationConfig extends InstrumentationConfig {\n /** hook for adding custom attributes before publish message is sent */\n publishHook?: AmqplibPublishCustomAttributeFunction;\n\n /** hook for adding custom attributes after publish message is confirmed by the broker */\n publishConfirmHook?: AmqplibPublishConfirmCustomAttributeFunction;\n\n /** hook for adding custom attributes before consumer message is processed */\n consumeHook?: AmqplibConsumeCustomAttributeFunction;\n\n /** hook for adding custom attributes after consumer message is acked to server */\n consumeEndHook?: AmqplibConsumeEndCustomAttributeFunction;\n\n /**\n * When user is setting up consume callback, it is user's responsibility to call\n * ack/nack etc on the msg to resolve it in the server.\n * If user is not calling the ack, the message will stay in the queue until\n * channel is closed, or until server timeout expires (if configured).\n * While we wait for the ack, a reference to the message is stored in plugin, which\n * will never be garbage collected.\n * To prevent memory leak, plugin has it's own configuration of timeout, which\n * will close the span if user did not call ack after this timeout.\n * If timeout is not big enough, span might be closed with 'InstrumentationTimeout',\n * and then received valid ack from the user later which will not be instrumented.\n *\n * Default is 1 minute\n */\n consumeTimeoutMs?: number;\n}\n\nexport const DEFAULT_CONFIG: AmqplibInstrumentationConfig = {\n consumeTimeoutMs: 1000 * 60, // 1 minute\n};\n\n// The following types are vendored from `@types/amqplib@0.10.1` - commit SHA: 4205e03127692a40b4871709a7134fe4e2ed5510\n\n// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L108\n// This exists in `@types/amqplib` as `Options.Publish`. We're renaming things\n// here to avoid importing the whole Options namespace.\nexport interface AmqplibPublishOptions {\n expiration?: string | number;\n userId?: string;\n CC?: string | string[];\n\n mandatory?: boolean;\n persistent?: boolean;\n deliveryMode?: boolean | number;\n BCC?: string | string[];\n\n contentType?: string;\n contentEncoding?: string;\n headers?: any;\n priority?: number;\n correlationId?: string;\n replyTo?: string;\n messageId?: string;\n timestamp?: number;\n type?: string;\n appId?: string;\n}\n\n// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L142\nexport interface Message {\n content: Buffer;\n fields: MessageFields;\n properties: MessageProperties;\n}\n\nexport interface ConsumeMessage extends Message {\n fields: ConsumeMessageFields;\n}\n\nexport interface CommonMessageFields {\n deliveryTag: number;\n redelivered: boolean;\n exchange: string;\n routingKey: string;\n}\n\nexport interface MessageFields extends CommonMessageFields {\n messageCount?: number;\n consumerTag?: string;\n}\n\nexport interface ConsumeMessageFields extends CommonMessageFields {\n deliveryTag: number;\n}\n\nexport interface MessageProperties {\n contentType: any | undefined;\n contentEncoding: any | undefined;\n headers: any;\n deliveryMode: any | undefined;\n priority: any | undefined;\n correlationId: any | undefined;\n replyTo: any | undefined;\n expiration: any | undefined;\n messageId: any | undefined;\n timestamp: any | undefined;\n type: any | undefined;\n userId: any | undefined;\n appId: any | undefined;\n clusterId: any | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AA0DA,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,oCAAoB,CAAA;IACpB,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,gDAAgC,CAAA;IAChC,8CAA8B,CAAA;IAC9B,kEAAkD,CAAA;AACpD,CAAC,EAVW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAUvB;AAmCY,QAAA,cAAc,GAAiC;IAC1D,gBAAgB,EAAE,IAAI,GAAG,EAAE;IAC3B,kBAAkB,EAAE,KAAK;CAC1B,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 */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport interface PublishInfo {\n moduleVersion: string | undefined;\n exchange: string;\n routingKey: string;\n content: Buffer;\n options?: AmqplibPublishOptions;\n isConfirmChannel?: boolean;\n}\n\nexport interface PublishConfirmedInfo extends PublishInfo {\n confirmError?: any;\n}\n\nexport interface ConsumeInfo {\n moduleVersion: string | undefined;\n msg: ConsumeMessage;\n}\n\nexport interface ConsumeEndInfo {\n msg: ConsumeMessage;\n rejected: boolean | null;\n endOperation: EndOperation;\n}\n\nexport interface AmqplibPublishCustomAttributeFunction {\n (span: Span, publishInfo: PublishInfo): void;\n}\n\nexport interface AmqplibPublishConfirmCustomAttributeFunction {\n (span: Span, publishConfirmedInto: PublishConfirmedInfo): void;\n}\n\nexport interface AmqplibConsumeCustomAttributeFunction {\n (span: Span, consumeInfo: ConsumeInfo): void;\n}\n\nexport interface AmqplibConsumeEndCustomAttributeFunction {\n (span: Span, consumeEndInfo: ConsumeEndInfo): void;\n}\n\nexport enum EndOperation {\n AutoAck = 'auto ack',\n Ack = 'ack',\n AckAll = 'ackAll',\n Reject = 'reject',\n Nack = 'nack',\n NackAll = 'nackAll',\n ChannelClosed = 'channel closed',\n ChannelError = 'channel error',\n InstrumentationTimeout = 'instrumentation timeout',\n}\n\nexport interface AmqplibInstrumentationConfig extends InstrumentationConfig {\n /** hook for adding custom attributes before publish message is sent */\n publishHook?: AmqplibPublishCustomAttributeFunction;\n\n /** hook for adding custom attributes after publish message is confirmed by the broker */\n publishConfirmHook?: AmqplibPublishConfirmCustomAttributeFunction;\n\n /** hook for adding custom attributes before consumer message is processed */\n consumeHook?: AmqplibConsumeCustomAttributeFunction;\n\n /** hook for adding custom attributes after consumer message is acked to server */\n consumeEndHook?: AmqplibConsumeEndCustomAttributeFunction;\n\n /**\n * When user is setting up consume callback, it is user's responsibility to call\n * ack/nack etc on the msg to resolve it in the server.\n * If user is not calling the ack, the message will stay in the queue until\n * channel is closed, or until server timeout expires (if configured).\n * While we wait for the ack, a reference to the message is stored in plugin, which\n * will never be garbage collected.\n * To prevent memory leak, plugin has it's own configuration of timeout, which\n * will close the span if user did not call ack after this timeout.\n * If timeout is not big enough, span might be closed with 'InstrumentationTimeout',\n * and then received valid ack from the user later which will not be instrumented.\n *\n * Default is 1 minute\n */\n consumeTimeoutMs?: number;\n\n /** option to use a span link for the consume message instead of continuing a trace */\n useLinksForConsume?: boolean;\n}\n\nexport const DEFAULT_CONFIG: AmqplibInstrumentationConfig = {\n consumeTimeoutMs: 1000 * 60, // 1 minute\n useLinksForConsume: false,\n};\n\n// The following types are vendored from `@types/amqplib@0.10.1` - commit SHA: 4205e03127692a40b4871709a7134fe4e2ed5510\n\n// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L108\n// This exists in `@types/amqplib` as `Options.Publish`. We're renaming things\n// here to avoid importing the whole Options namespace.\nexport interface AmqplibPublishOptions {\n expiration?: string | number;\n userId?: string;\n CC?: string | string[];\n\n mandatory?: boolean;\n persistent?: boolean;\n deliveryMode?: boolean | number;\n BCC?: string | string[];\n\n contentType?: string;\n contentEncoding?: string;\n headers?: any;\n priority?: number;\n correlationId?: string;\n replyTo?: string;\n messageId?: string;\n timestamp?: number;\n type?: string;\n appId?: string;\n}\n\n// Vendored from: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4205e03127692a40b4871709a7134fe4e2ed5510/types/amqplib/properties.d.ts#L142\nexport interface Message {\n content: Buffer;\n fields: MessageFields;\n properties: MessageProperties;\n}\n\nexport interface ConsumeMessage extends Message {\n fields: ConsumeMessageFields;\n}\n\nexport interface CommonMessageFields {\n deliveryTag: number;\n redelivered: boolean;\n exchange: string;\n routingKey: string;\n}\n\nexport interface MessageFields extends CommonMessageFields {\n messageCount?: number;\n consumerTag?: string;\n}\n\nexport interface ConsumeMessageFields extends CommonMessageFields {\n deliveryTag: number;\n}\n\nexport interface MessageProperties {\n contentType: any | undefined;\n contentEncoding: any | undefined;\n headers: any;\n deliveryMode: any | undefined;\n priority: any | undefined;\n correlationId: any | undefined;\n replyTo: any | undefined;\n expiration: any | undefined;\n messageId: any | undefined;\n timestamp: any | undefined;\n type: any | undefined;\n userId: any | undefined;\n appId: any | undefined;\n clusterId: any | undefined;\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.38.0";
1
+ export declare const PACKAGE_VERSION = "0.40.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-amqplib";
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.38.0';
20
+ exports.PACKAGE_VERSION = '0.40.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-amqplib';
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,QAAQ,CAAC;AAC3B,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.38.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-amqplib';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,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.40.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-amqplib';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-amqplib",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "description": "OpenTelemetry instrumentation for the `amqplib` messaging client for RabbitMQ",
5
5
  "keywords": [
6
6
  "amqplib",
@@ -30,6 +30,7 @@
30
30
  "compile": "tsc -p .",
31
31
  "lint": "eslint . --ext .ts",
32
32
  "lint:fix": "eslint . --ext .ts --fix",
33
+ "lint:readme": "node ../../../scripts/lint-readme.js",
33
34
  "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-amqplib --include-dependencies",
34
35
  "prewatch": "npm run precompile",
35
36
  "prepublishOnly": "npm run compile",
@@ -69,5 +70,5 @@
69
70
  "engines": {
70
71
  "node": ">=14"
71
72
  },
72
- "gitHead": "0af1b70f7c3c9763c85ac51fa5e334c1e1512020"
73
+ "gitHead": "c1d67f8befb716c57bb5083a9d24f154128963df"
73
74
  }