@opentelemetry/instrumentation-amqplib 0.36.0 → 0.37.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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [2022] OpenTelemetry Authors
189
+ Copyright [yyyy] [name of copyright owner]
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -81,6 +81,27 @@ The instrumentation's config `publishHook`, `publishConfirmHook`, `consumeHook`
81
81
 
82
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.
83
83
 
84
+ ## Semantic Conventions
85
+
86
+ This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
87
+
88
+ Attributes collected:
89
+
90
+ | Attribute | Short Description |
91
+ | -------------------------------- | ---------------------------------------------------------------------- |
92
+ | `messaging.destination` | The message destination name. |
93
+ | `messaging.destination_kind` | The kind of message destination. |
94
+ | `messaging.rabbitmq.routing_key` | RabbitMQ message routing key. |
95
+ | `messaging.operation` | A string identifying the kind of message consumption. |
96
+ | `messaging.message_id` | A value used by the messaging system as an identifier for the message. |
97
+ | `messaging.conversation_id` | The ID identifying the conversation to which the message belongs. |
98
+ | `messaging.protocol` | The name of the transport protocol. |
99
+ | `messaging.protocol_version` | The version of the transport protocol. |
100
+ | `messaging.system` | A string identifying the messaging system. |
101
+ | `messaging.url` | The connection string. |
102
+ | `net.peer.name` | Remote hostname or similar. |
103
+ | `net.peer.port` | Remote port number. |
104
+
84
105
  ## Useful links
85
106
 
86
107
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -4,7 +4,7 @@ export declare class AmqplibInstrumentation extends InstrumentationBase {
4
4
  protected _config: AmqplibInstrumentationConfig;
5
5
  constructor(config?: AmqplibInstrumentationConfig);
6
6
  setConfig(config?: AmqplibInstrumentationConfig): void;
7
- protected init(): InstrumentationNodeModuleDefinition<unknown>;
7
+ protected init(): InstrumentationNodeModuleDefinition;
8
8
  private patchConnect;
9
9
  private unpatchConnect;
10
10
  private patchChannelModel;
@@ -205,7 +205,7 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
205
205
  const exchange = (_b = msg.fields) === null || _b === void 0 ? void 0 : _b.exchange;
206
206
  const span = self.tracer.startSpan(`${queue} process`, {
207
207
  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.SemanticAttributes.MESSAGING_DESTINATION]: exchange, [semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION_KIND]: semantic_conventions_1.MessagingDestinationKindValues.TOPIC, [semantic_conventions_1.SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY]: (_d = msg.fields) === null || _d === void 0 ? void 0 : _d.routingKey, [semantic_conventions_1.SemanticAttributes.MESSAGING_OPERATION]: semantic_conventions_1.MessagingOperationValues.PROCESS, [semantic_conventions_1.SemanticAttributes.MESSAGING_MESSAGE_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.messageId, [semantic_conventions_1.SemanticAttributes.MESSAGING_CONVERSATION_ID]: msg === null || msg === void 0 ? void 0 : msg.properties.correlationId }),
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 }),
209
209
  }, parentContext);
210
210
  if (self._config.consumeHook) {
211
211
  (0, instrumentation_1.safeExecuteInTheMiddle)(() => self._config.consumeHook(span, { moduleVersion, msg }), e => {
@@ -331,7 +331,7 @@ class AmqplibInstrumentation extends instrumentation_1.InstrumentationBase {
331
331
  const normalizedExchange = (0, utils_1.normalizeExchange)(exchange);
332
332
  const span = self.tracer.startSpan(`${normalizedExchange} -> ${routingKey} send`, {
333
333
  kind: api_1.SpanKind.PRODUCER,
334
- attributes: Object.assign(Object.assign({}, channel.connection[utils_1.CONNECTION_ATTRIBUTES]), { [semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION]: exchange, [semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION_KIND]: semantic_conventions_1.MessagingDestinationKindValues.TOPIC, [semantic_conventions_1.SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey, [semantic_conventions_1.SemanticAttributes.MESSAGING_MESSAGE_ID]: options === null || options === void 0 ? void 0 : options.messageId, [semantic_conventions_1.SemanticAttributes.MESSAGING_CONVERSATION_ID]: options === null || options === void 0 ? void 0 : options.correlationId }),
334
+ attributes: Object.assign(Object.assign({}, channel.connection[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]: routingKey, [semantic_conventions_1.SEMATTRS_MESSAGING_MESSAGE_ID]: options === null || options === void 0 ? void 0 : options.messageId, [semantic_conventions_1.SEMATTRS_MESSAGING_CONVERSATION_ID]: options === null || options === void 0 ? void 0 : options.correlationId }),
335
335
  });
336
336
  const modifiedOptions = options !== null && options !== void 0 ? options : {};
337
337
  modifiedOptions.headers = (_a = modifiedOptions.headers) !== null && _a !== void 0 ? _a : {};
@@ -1 +1 @@
1
- {"version":3,"file":"amqplib.js","sourceRoot":"","sources":["../../src/amqplib.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAS4B;AAC5B,8CAI6B;AAC7B,oEAMwC;AACxC,8EAI6C;AAQ7C,mCAIiB;AACjB,mCAciB;AACjB,uCAAoC;AAEpC,MAAa,sBAAuB,SAAQ,qCAAmB;IAG7D,YAAY,MAAqC;QAC/C,KAAK,CACH,wCAAwC,EACxC,iBAAO,EACP,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,sBAAsB,GAAG,IAAI,+CAA6B,CAC9D,8BAA8B,EAC9B,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EACjC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;QAEF,MAAM,uBAAuB,GAAG,IAAI,+CAA6B,CAC/D,+BAA+B,EAC/B,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,iBAAiB,CAAC,I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W,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;AAlqBD,wDAkqBC","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 SemanticAttributes,\n MessagingOperationValues,\n MessagingDestinationKindValues,\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 { VERSION } from './version';\n\nexport class AmqplibInstrumentation extends InstrumentationBase {\n protected override _config!: AmqplibInstrumentationConfig;\n\n constructor(config?: AmqplibInstrumentationConfig) {\n super(\n '@opentelemetry/instrumentation-amqplib',\n 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 [SemanticAttributes.MESSAGING_DESTINATION]: exchange,\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.TOPIC,\n [SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY]:\n msg.fields?.routingKey,\n [SemanticAttributes.MESSAGING_OPERATION]:\n MessagingOperationValues.PROCESS,\n [SemanticAttributes.MESSAGING_MESSAGE_ID]:\n msg?.properties.messageId,\n [SemanticAttributes.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 [SemanticAttributes.MESSAGING_DESTINATION]: exchange,\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.TOPIC,\n [SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,\n [SemanticAttributes.MESSAGING_MESSAGE_ID]: options?.messageId,\n [SemanticAttributes.MESSAGING_CONVERSATION_ID]:\n 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,4CAS4B;AAC5B,8CAI6B;AAC7B,oEAMwC;AACxC,8EAS6C;AAQ7C,mCAIiB;AACjB,mCAciB;AACjB,uCAAoC;AAEpC,MAAa,sBAAuB,SAAQ,qCAAmB;IAG7D,YAAY,MAAqC;QAC/C,KAAK,CACH,wCAAwC,EACxC,iBAAO,EACP,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,sBAAsB,GAAG,IAAI,+CAA6B,CAC9D,8BAA8B,EAC9B,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EACjC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;QAEF,MAAM,uBAAuB,GAAG,IAAI,+CAA6B,CAC/D,+BAA+B,EAC/B,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EACjC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;QAEF,MAAM,iBAAiB,GAAG,IAAI,+CAA6B,CACzD,wBAAwB,EACxB,CAAC,SAAS,CAAC,EACX,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,E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CACxB,IAAU,EACV,GAAmB,EACnB,QAAwB,EACxB,YAA0B;QAE1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc;YAAE,OAAO;QAEzC,IAAA,wCAAsB,EACpB,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,cAAe,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,EACzE,CAAC,CAAC,EAAE;YACF,IAAI,CAAC,EAAE;gBACL,UAAI,CAAC,KAAK,CAAC,gDAAgD,EAAE,CAAC,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,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,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 { VERSION } from './version';\n\nexport class AmqplibInstrumentation extends InstrumentationBase {\n protected override _config!: AmqplibInstrumentationConfig;\n\n constructor(config?: AmqplibInstrumentationConfig) {\n super(\n '@opentelemetry/instrumentation-amqplib',\n 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,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Context, HrTime, Span, SpanAttributes } from '@opentelemetry/api';
2
+ import { Context, HrTime, Span, Attributes } from '@opentelemetry/api';
3
3
  import type * as amqp from 'amqplib';
4
4
  export declare const MESSAGE_STORED_SPAN: unique symbol;
5
5
  export declare const CHANNEL_SPANS_NOT_ENDED: unique symbol;
@@ -7,12 +7,12 @@ export declare const CHANNEL_CONSUME_TIMEOUT_TIMER: unique symbol;
7
7
  export declare const CONNECTION_ATTRIBUTES: unique symbol;
8
8
  export declare type InstrumentationPublishChannel = (amqp.Channel | amqp.ConfirmChannel) & {
9
9
  connection: {
10
- [CONNECTION_ATTRIBUTES]: SpanAttributes;
10
+ [CONNECTION_ATTRIBUTES]: Attributes;
11
11
  };
12
12
  };
13
13
  export declare type InstrumentationConsumeChannel = amqp.Channel & {
14
14
  connection: {
15
- [CONNECTION_ATTRIBUTES]: SpanAttributes;
15
+ [CONNECTION_ATTRIBUTES]: Attributes;
16
16
  };
17
17
  [CHANNEL_SPANS_NOT_ENDED]?: {
18
18
  msg: amqp.ConsumeMessage;
@@ -24,8 +24,8 @@ export declare type InstrumentationMessage = amqp.Message & {
24
24
  [MESSAGE_STORED_SPAN]?: Span;
25
25
  };
26
26
  export declare const normalizeExchange: (exchangeName: string) => string;
27
- export declare const getConnectionAttributesFromServer: (conn: amqp.Connection['connection']) => SpanAttributes;
28
- export declare const getConnectionAttributesFromUrl: (url: string | amqp.Options.Connect) => SpanAttributes;
27
+ export declare const getConnectionAttributesFromServer: (conn: amqp.Connection['connection']) => Attributes;
28
+ export declare const getConnectionAttributesFromUrl: (url: string | amqp.Options.Connect) => Attributes;
29
29
  export declare const markConfirmChannelTracing: (context: Context) => Context;
30
30
  export declare const unmarkConfirmChannelTracing: (context: Context) => Context;
31
31
  export declare const isConfirmChannelTracing: (context: Context) => boolean;
@@ -63,7 +63,7 @@ const getConnectionAttributesFromServer = (conn) => {
63
63
  const product = (_b = (_a = conn.serverProperties.product) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a);
64
64
  if (product) {
65
65
  return {
66
- [semantic_conventions_1.SemanticAttributes.MESSAGING_SYSTEM]: product,
66
+ [semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: product,
67
67
  };
68
68
  }
69
69
  else {
@@ -73,29 +73,29 @@ const getConnectionAttributesFromServer = (conn) => {
73
73
  exports.getConnectionAttributesFromServer = getConnectionAttributesFromServer;
74
74
  const getConnectionAttributesFromUrl = (url) => {
75
75
  const attributes = {
76
- [semantic_conventions_1.SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
76
+ [semantic_conventions_1.SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
77
77
  };
78
78
  url = url || 'amqp://localhost';
79
79
  if (typeof url === 'object') {
80
80
  const connectOptions = url;
81
81
  const protocol = getProtocol(connectOptions === null || connectOptions === void 0 ? void 0 : connectOptions.protocol);
82
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SemanticAttributes.MESSAGING_PROTOCOL, protocol, 'protocol')));
82
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SEMATTRS_MESSAGING_PROTOCOL, protocol, 'protocol')));
83
83
  const hostname = getHostname(connectOptions === null || connectOptions === void 0 ? void 0 : connectOptions.hostname);
84
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SemanticAttributes.NET_PEER_NAME, hostname, 'hostname')));
84
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SEMATTRS_NET_PEER_NAME, hostname, 'hostname')));
85
85
  const port = getPort(connectOptions.port, protocol);
86
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SemanticAttributes.NET_PEER_PORT, port, 'port')));
86
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(url, semantic_conventions_1.SEMATTRS_NET_PEER_PORT, port, 'port')));
87
87
  }
88
88
  else {
89
89
  const censoredUrl = censorPassword(url);
90
- attributes[semantic_conventions_1.SemanticAttributes.MESSAGING_URL] = censoredUrl;
90
+ attributes[semantic_conventions_1.SEMATTRS_MESSAGING_URL] = censoredUrl;
91
91
  try {
92
92
  const urlParts = new URL(censoredUrl);
93
93
  const protocol = getProtocol(urlParts.protocol);
94
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SemanticAttributes.MESSAGING_PROTOCOL, protocol, 'protocol')));
94
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SEMATTRS_MESSAGING_PROTOCOL, protocol, 'protocol')));
95
95
  const hostname = getHostname(urlParts.hostname);
96
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SemanticAttributes.NET_PEER_NAME, hostname, 'hostname')));
96
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SEMATTRS_NET_PEER_NAME, hostname, 'hostname')));
97
97
  const port = getPort(urlParts.port ? parseInt(urlParts.port) : undefined, protocol);
98
- Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SemanticAttributes.NET_PEER_PORT, port, 'port')));
98
+ Object.assign(attributes, Object.assign({}, extractConnectionAttributeOrLog(censoredUrl, semantic_conventions_1.SEMATTRS_NET_PEER_PORT, port, 'port')));
99
99
  }
100
100
  catch (err) {
101
101
  api_1.diag.error('amqplib instrumentation: error while extracting connection details from connection url', {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,8EAAyE;AAG5D,QAAA,mBAAmB,GAAkB,MAAM,CACtD,2CAA2C,CAC5C,CAAC;AACW,QAA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AkB,CAAC,aAAa,EAChC,IAAI,EACJ,MAAM,CACP,EACD,CAAC;SACJ;QAAC,OAAO,GAAG,EAAE;YACZ,UAAI,CAAC,KAAK,CACR,wFAAwF,EACxF;gBACE,WAAW;gBACX,GAAG;aACJ,CACF,CAAC;SACH;KACF;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAzFW,QAAA,8BAA8B,kCAyFzC;AAEK,MAAM,yBAAyB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC5D,OAAO,OAAO,CAAC,QAAQ,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC;AAFW,QAAA,yBAAyB,6BAEpC;AAEK,MAAM,2BAA2B,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC9D,OAAO,OAAO,CAAC,WAAW,CAAC,8BAA8B,CAAC,CAAC;AAC7D,CAAC,CAAC;AAFW,QAAA,2BAA2B,+BAEtC;AAEK,MAAM,uBAAuB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAC,KAAK,IAAI,CAAC;AACnE,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC","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 createContextKey,\n diag,\n HrTime,\n Span,\n SpanAttributes,\n SpanAttributeValue,\n} from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type * as amqp from 'amqplib';\n\nexport const MESSAGE_STORED_SPAN: unique symbol = Symbol(\n 'opentelemetry.amqplib.message.stored-span'\n);\nexport const CHANNEL_SPANS_NOT_ENDED: unique symbol = Symbol(\n 'opentelemetry.amqplib.channel.spans-not-ended'\n);\nexport const CHANNEL_CONSUME_TIMEOUT_TIMER: unique symbol = Symbol(\n 'opentelemetry.amqplib.channel.consumer-timeout-timer'\n);\nexport const CONNECTION_ATTRIBUTES: unique symbol = Symbol(\n 'opentelemetry.amqplib.connection.attributes'\n);\n\nexport type InstrumentationPublishChannel = (\n | amqp.Channel\n | amqp.ConfirmChannel\n) & { connection: { [CONNECTION_ATTRIBUTES]: SpanAttributes } };\nexport type InstrumentationConsumeChannel = amqp.Channel & {\n connection: { [CONNECTION_ATTRIBUTES]: SpanAttributes };\n [CHANNEL_SPANS_NOT_ENDED]?: {\n msg: amqp.ConsumeMessage;\n timeOfConsume: HrTime;\n }[];\n [CHANNEL_CONSUME_TIMEOUT_TIMER]?: NodeJS.Timer;\n};\nexport type InstrumentationMessage = amqp.Message & {\n [MESSAGE_STORED_SPAN]?: Span;\n};\n\nconst IS_CONFIRM_CHANNEL_CONTEXT_KEY: symbol = createContextKey(\n 'opentelemetry.amqplib.channel.is-confirm-channel'\n);\n\nexport const normalizeExchange = (exchangeName: string) =>\n exchangeName !== '' ? exchangeName : '<default>';\n\nconst censorPassword = (url: string): string => {\n return url.replace(/:[^:@/]*@/, ':***@');\n};\n\nconst getPort = (\n portFromUrl: number | undefined,\n resolvedProtocol: string\n): number => {\n // we are using the resolved protocol which is upper case\n // this code mimic the behavior of the amqplib which is used to set connection params\n return portFromUrl || (resolvedProtocol === 'AMQP' ? 5672 : 5671);\n};\n\nconst getProtocol = (protocolFromUrl: string | undefined): string => {\n const resolvedProtocol = protocolFromUrl || 'amqp';\n // the substring removed the ':' part of the protocol ('amqp:' -> 'amqp')\n const noEndingColon = resolvedProtocol.endsWith(':')\n ? resolvedProtocol.substring(0, resolvedProtocol.length - 1)\n : resolvedProtocol;\n // upper cases to match spec\n return noEndingColon.toUpperCase();\n};\n\nconst getHostname = (hostnameFromUrl: string | undefined): string => {\n // if user supplies empty hostname, it gets forwarded to 'net' package which default it to localhost.\n // https://nodejs.org/docs/latest-v12.x/api/net.html#net_socket_connect_options_connectlistener\n return hostnameFromUrl || 'localhost';\n};\n\nconst extractConnectionAttributeOrLog = (\n url: string | amqp.Options.Connect,\n attributeKey: string,\n attributeValue: SpanAttributeValue,\n nameForLog: string\n): SpanAttributes => {\n if (attributeValue) {\n return { [attributeKey]: attributeValue };\n } else {\n diag.error(\n `amqplib instrumentation: could not extract connection attribute ${nameForLog} from user supplied url`,\n {\n url,\n }\n );\n return {};\n }\n};\n\nexport const getConnectionAttributesFromServer = (\n conn: amqp.Connection['connection']\n): SpanAttributes => {\n const product = conn.serverProperties.product?.toLowerCase?.();\n if (product) {\n return {\n [SemanticAttributes.MESSAGING_SYSTEM]: product,\n };\n } else {\n return {};\n }\n};\n\nexport const getConnectionAttributesFromUrl = (\n url: string | amqp.Options.Connect\n): SpanAttributes => {\n const attributes: SpanAttributes = {\n [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library\n };\n\n url = url || 'amqp://localhost';\n if (typeof url === 'object') {\n const connectOptions = url as amqp.Options.Connect;\n\n const protocol = getProtocol(connectOptions?.protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SemanticAttributes.MESSAGING_PROTOCOL,\n protocol,\n 'protocol'\n ),\n });\n\n const hostname = getHostname(connectOptions?.hostname);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SemanticAttributes.NET_PEER_NAME,\n hostname,\n 'hostname'\n ),\n });\n\n const port = getPort(connectOptions.port, protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SemanticAttributes.NET_PEER_PORT,\n port,\n 'port'\n ),\n });\n } else {\n const censoredUrl = censorPassword(url);\n attributes[SemanticAttributes.MESSAGING_URL] = censoredUrl;\n try {\n const urlParts = new URL(censoredUrl);\n\n const protocol = getProtocol(urlParts.protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SemanticAttributes.MESSAGING_PROTOCOL,\n protocol,\n 'protocol'\n ),\n });\n\n const hostname = getHostname(urlParts.hostname);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SemanticAttributes.NET_PEER_NAME,\n hostname,\n 'hostname'\n ),\n });\n\n const port = getPort(\n urlParts.port ? parseInt(urlParts.port) : undefined,\n protocol\n );\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SemanticAttributes.NET_PEER_PORT,\n port,\n 'port'\n ),\n });\n } catch (err) {\n diag.error(\n 'amqplib instrumentation: error while extracting connection details from connection url',\n {\n censoredUrl,\n err,\n }\n );\n }\n }\n return attributes;\n};\n\nexport const markConfirmChannelTracing = (context: Context) => {\n return context.setValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY, true);\n};\n\nexport const unmarkConfirmChannelTracing = (context: Context) => {\n return context.deleteValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY);\n};\n\nexport const isConfirmChannelTracing = (context: Context) => {\n return context.getValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY) === true;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,8EAO6C;AAGhC,QAAA,mBAAmB,GAAkB,MAAM,CACtD,2CAA2C,CAC5C,CAAC;AACW,QAAA,uBAAuB,GAAkB,MAAM,CAC1D,+CAA+C,CAChD,CAAC;AACW,QAAA,6BAA6B,GAAkB,MAAM,CAChE,sDAAsD,CACvD,CAAC;AACW,QAAA,qBAAqB,GAAkB,MAAM,CACxD,6CAA6C,CAC9C,CAAC;AAkBF,MAAM,8BAA8B,GAAW,IAAA,sBAAgB,EAC7D,kDAAkD,CACnD,CAAC;AAEK,MAAM,iBAAi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,CAAC,CAAC;AAFW,QAAA,yBAAyB,6BAEpC;AAEK,MAAM,2BAA2B,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC9D,OAAO,OAAO,CAAC,WAAW,CAAC,8BAA8B,CAAC,CAAC;AAC7D,CAAC,CAAC;AAFW,QAAA,2BAA2B,+BAEtC;AAEK,MAAM,uBAAuB,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAC,KAAK,IAAI,CAAC;AACnE,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC","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 createContextKey,\n diag,\n HrTime,\n Span,\n Attributes,\n AttributeValue,\n} from '@opentelemetry/api';\nimport {\n SEMATTRS_MESSAGING_PROTOCOL,\n SEMATTRS_MESSAGING_PROTOCOL_VERSION,\n SEMATTRS_MESSAGING_SYSTEM,\n SEMATTRS_MESSAGING_URL,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport type * as amqp from 'amqplib';\n\nexport const MESSAGE_STORED_SPAN: unique symbol = Symbol(\n 'opentelemetry.amqplib.message.stored-span'\n);\nexport const CHANNEL_SPANS_NOT_ENDED: unique symbol = Symbol(\n 'opentelemetry.amqplib.channel.spans-not-ended'\n);\nexport const CHANNEL_CONSUME_TIMEOUT_TIMER: unique symbol = Symbol(\n 'opentelemetry.amqplib.channel.consumer-timeout-timer'\n);\nexport const CONNECTION_ATTRIBUTES: unique symbol = Symbol(\n 'opentelemetry.amqplib.connection.attributes'\n);\n\nexport type InstrumentationPublishChannel = (\n | amqp.Channel\n | amqp.ConfirmChannel\n) & { connection: { [CONNECTION_ATTRIBUTES]: Attributes } };\nexport type InstrumentationConsumeChannel = amqp.Channel & {\n connection: { [CONNECTION_ATTRIBUTES]: Attributes };\n [CHANNEL_SPANS_NOT_ENDED]?: {\n msg: amqp.ConsumeMessage;\n timeOfConsume: HrTime;\n }[];\n [CHANNEL_CONSUME_TIMEOUT_TIMER]?: NodeJS.Timer;\n};\nexport type InstrumentationMessage = amqp.Message & {\n [MESSAGE_STORED_SPAN]?: Span;\n};\n\nconst IS_CONFIRM_CHANNEL_CONTEXT_KEY: symbol = createContextKey(\n 'opentelemetry.amqplib.channel.is-confirm-channel'\n);\n\nexport const normalizeExchange = (exchangeName: string) =>\n exchangeName !== '' ? exchangeName : '<default>';\n\nconst censorPassword = (url: string): string => {\n return url.replace(/:[^:@/]*@/, ':***@');\n};\n\nconst getPort = (\n portFromUrl: number | undefined,\n resolvedProtocol: string\n): number => {\n // we are using the resolved protocol which is upper case\n // this code mimic the behavior of the amqplib which is used to set connection params\n return portFromUrl || (resolvedProtocol === 'AMQP' ? 5672 : 5671);\n};\n\nconst getProtocol = (protocolFromUrl: string | undefined): string => {\n const resolvedProtocol = protocolFromUrl || 'amqp';\n // the substring removed the ':' part of the protocol ('amqp:' -> 'amqp')\n const noEndingColon = resolvedProtocol.endsWith(':')\n ? resolvedProtocol.substring(0, resolvedProtocol.length - 1)\n : resolvedProtocol;\n // upper cases to match spec\n return noEndingColon.toUpperCase();\n};\n\nconst getHostname = (hostnameFromUrl: string | undefined): string => {\n // if user supplies empty hostname, it gets forwarded to 'net' package which default it to localhost.\n // https://nodejs.org/docs/latest-v12.x/api/net.html#net_socket_connect_options_connectlistener\n return hostnameFromUrl || 'localhost';\n};\n\nconst extractConnectionAttributeOrLog = (\n url: string | amqp.Options.Connect,\n attributeKey: string,\n attributeValue: AttributeValue,\n nameForLog: string\n): Attributes => {\n if (attributeValue) {\n return { [attributeKey]: attributeValue };\n } else {\n diag.error(\n `amqplib instrumentation: could not extract connection attribute ${nameForLog} from user supplied url`,\n {\n url,\n }\n );\n return {};\n }\n};\n\nexport const getConnectionAttributesFromServer = (\n conn: amqp.Connection['connection']\n): Attributes => {\n const product = conn.serverProperties.product?.toLowerCase?.();\n if (product) {\n return {\n [SEMATTRS_MESSAGING_SYSTEM]: product,\n };\n } else {\n return {};\n }\n};\n\nexport const getConnectionAttributesFromUrl = (\n url: string | amqp.Options.Connect\n): Attributes => {\n const attributes: Attributes = {\n [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library\n };\n\n url = url || 'amqp://localhost';\n if (typeof url === 'object') {\n const connectOptions = url as amqp.Options.Connect;\n\n const protocol = getProtocol(connectOptions?.protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SEMATTRS_MESSAGING_PROTOCOL,\n protocol,\n 'protocol'\n ),\n });\n\n const hostname = getHostname(connectOptions?.hostname);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SEMATTRS_NET_PEER_NAME,\n hostname,\n 'hostname'\n ),\n });\n\n const port = getPort(connectOptions.port, protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n url,\n SEMATTRS_NET_PEER_PORT,\n port,\n 'port'\n ),\n });\n } else {\n const censoredUrl = censorPassword(url);\n attributes[SEMATTRS_MESSAGING_URL] = censoredUrl;\n try {\n const urlParts = new URL(censoredUrl);\n\n const protocol = getProtocol(urlParts.protocol);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SEMATTRS_MESSAGING_PROTOCOL,\n protocol,\n 'protocol'\n ),\n });\n\n const hostname = getHostname(urlParts.hostname);\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SEMATTRS_NET_PEER_NAME,\n hostname,\n 'hostname'\n ),\n });\n\n const port = getPort(\n urlParts.port ? parseInt(urlParts.port) : undefined,\n protocol\n );\n Object.assign(attributes, {\n ...extractConnectionAttributeOrLog(\n censoredUrl,\n SEMATTRS_NET_PEER_PORT,\n port,\n 'port'\n ),\n });\n } catch (err) {\n diag.error(\n 'amqplib instrumentation: error while extracting connection details from connection url',\n {\n censoredUrl,\n err,\n }\n );\n }\n }\n return attributes;\n};\n\nexport const markConfirmChannelTracing = (context: Context) => {\n return context.setValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY, true);\n};\n\nexport const unmarkConfirmChannelTracing = (context: Context) => {\n return context.deleteValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY);\n};\n\nexport const isConfirmChannelTracing = (context: Context) => {\n return context.getValue(IS_CONFIRM_CHANNEL_CONTEXT_KEY) === true;\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.36.0";
1
+ export declare const VERSION = "0.37.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.36.0';
20
+ exports.VERSION = '0.37.0';
21
21
  //# 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,OAAO,GAAG,QAAQ,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 VERSION = '0.36.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,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 VERSION = '0.37.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-amqplib",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "OpenTelemetry automatic instrumentation for the `amqplib` package",
5
5
  "keywords": [
6
6
  "amqplib",
@@ -45,12 +45,12 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@opentelemetry/core": "^1.8.0",
48
- "@opentelemetry/instrumentation": "^0.50.0",
49
- "@opentelemetry/semantic-conventions": "^1.0.0"
48
+ "@opentelemetry/instrumentation": "^0.51.0",
49
+ "@opentelemetry/semantic-conventions": "^1.22.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@opentelemetry/api": "^1.3.0",
53
- "@opentelemetry/contrib-test-utils": "^0.38.0",
53
+ "@opentelemetry/contrib-test-utils": "^0.39.0",
54
54
  "@types/amqplib": "^0.5.17",
55
55
  "@types/lodash": "4.14.199",
56
56
  "@types/mocha": "8.2.3",
@@ -69,5 +69,5 @@
69
69
  "engines": {
70
70
  "node": ">=14"
71
71
  },
72
- "gitHead": "17a0bc1da3baa472ba9b867eee3c60730cc130fb"
72
+ "gitHead": "96a87b48934f0afcf1fe637eed6704f35bd8e973"
73
73
  }