@opentelemetry/instrumentation-mongodb 0.41.0 → 0.43.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
@@ -1,4 +1,4 @@
1
- # OpenTelemetry mongodb Instrumentation for Node.js
1
+ # OpenTelemetry MongoDB Instrumentation for Node.js
2
2
 
3
3
  [![NPM Published Version][npm-img]][npm-url]
4
4
  [![Apache License][license-image]][license-image]
@@ -21,7 +21,7 @@ npm install --save @opentelemetry/instrumentation-mongodb
21
21
 
22
22
  ## Usage
23
23
 
24
- OpenTelemetry Mongodb Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.
24
+ OpenTelemetry MongoDB Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.
25
25
 
26
26
  To load a specific instrumentation (**mongodb** in this case), specify it in the Node Tracer's configuration.
27
27
 
@@ -55,6 +55,22 @@ Mongodb instrumentation has few options available to choose from. You can set th
55
55
  | `responseHook` | `MongoDBInstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response |
56
56
  | `dbStatementSerializer` | `DbStatementSerializer` (function) | Custom serializer function for the db.statement tag |
57
57
 
58
+ ## Semantic Conventions
59
+
60
+ 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)
61
+
62
+ Attributes collected:
63
+
64
+ | Attribute | Short Description |
65
+ | ----------------------- | ------------------------------------------------------------------------------ |
66
+ | `db.system` | An identifier for the database management system (DBMS) product being used. |
67
+ | `db.connection_string` | The connection string used to connect to the database. |
68
+ | `db.name` | This attribute is used to report the name of the database being accessed. |
69
+ | `db.operation` | The name of the operation being executed. |
70
+ | `db.mongodb.collection` | The collection being accessed within the database stated in `db.name`. |
71
+ | `net.peer.name` | Remote hostname or similar. |
72
+ | `net.peer.port` | Remote port number. |
73
+
58
74
  ## Useful links
59
75
 
60
76
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -7,7 +7,7 @@ export declare class MongoDBInstrumentation extends InstrumentationBase {
7
7
  private _poolName;
8
8
  constructor(_config?: MongoDBInstrumentationConfig);
9
9
  _updateMetricInstruments(): void;
10
- init(): InstrumentationNodeModuleDefinition<any>[];
10
+ init(): InstrumentationNodeModuleDefinition[];
11
11
  private _getV3ConnectionPatches;
12
12
  private _getV4SessionsPatches;
13
13
  private _getV4AcquireCommand;
@@ -22,7 +22,8 @@ export declare class MongoDBInstrumentation extends InstrumentationBase {
22
22
  /** Creates spans for command operation */
23
23
  private _getV3PatchCommand;
24
24
  /** Creates spans for command operation */
25
- private _getV4PatchCommand;
25
+ private _getV4PatchCommandCallback;
26
+ private _getV4PatchCommandPromise;
26
27
  /** Creates spans for find operation */
27
28
  private _getV3PatchFind;
28
29
  /** Creates spans for find operation */
@@ -36,25 +36,25 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
36
36
  init() {
37
37
  const { v3PatchConnection: v3PatchConnection, v3UnpatchConnection: v3UnpatchConnection, } = this._getV3ConnectionPatches();
38
38
  const { v4PatchConnect, v4UnpatchConnect } = this._getV4ConnectPatches();
39
- const { v4PatchConnection, v4UnpatchConnection } = this._getV4ConnectionPatches();
39
+ const { v4PatchConnectionCallback, v4PatchConnectionPromise, v4UnpatchConnection, } = this._getV4ConnectionPatches();
40
40
  const { v4PatchConnectionPool, v4UnpatchConnectionPool } = this._getV4ConnectionPoolPatches();
41
41
  const { v4PatchSessions, v4UnpatchSessions } = this._getV4SessionsPatches();
42
42
  return [
43
43
  new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['>=3.3 <4'], undefined, undefined, [
44
44
  new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/core/wireprotocol/index.js', ['>=3.3 <4'], v3PatchConnection, v3UnpatchConnection),
45
45
  ]),
46
- new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['4.*', '5.*', '>=6 <6.4'], undefined, undefined, [
47
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnection, v4UnpatchConnection),
46
+ new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['4.*', '5.*', '6.*'], undefined, undefined, [
47
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnectionCallback, v4UnpatchConnection),
48
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['>=6.4'], v4PatchConnectionPromise, v4UnpatchConnection),
48
49
  new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection_pool.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnectionPool, v4UnpatchConnectionPool),
49
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnect, v4UnpatchConnect),
50
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchSessions, v4UnpatchSessions),
50
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['4.*', '5.*', '6.*'], v4PatchConnect, v4UnpatchConnect),
51
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['4.*', '5.*', '6.*'], v4PatchSessions, v4UnpatchSessions),
51
52
  ]),
52
53
  ];
53
54
  }
54
55
  _getV3ConnectionPatches() {
55
56
  return {
56
- v3PatchConnection: (moduleExports, moduleVersion) => {
57
- api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`);
57
+ v3PatchConnection: (moduleExports) => {
58
58
  // patch insert operation
59
59
  if ((0, instrumentation_1.isWrapped)(moduleExports.insert)) {
60
60
  this._unwrap(moduleExports, 'insert');
@@ -87,10 +87,9 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
87
87
  this._wrap(moduleExports, 'getMore', this._getV3PatchCursor());
88
88
  return moduleExports;
89
89
  },
90
- v3UnpatchConnection: (moduleExports, moduleVersion) => {
90
+ v3UnpatchConnection: (moduleExports) => {
91
91
  if (moduleExports === undefined)
92
92
  return;
93
- api_1.diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);
94
93
  this._unwrap(moduleExports, 'insert');
95
94
  this._unwrap(moduleExports, 'remove');
96
95
  this._unwrap(moduleExports, 'update');
@@ -102,8 +101,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
102
101
  }
103
102
  _getV4SessionsPatches() {
104
103
  return {
105
- v4PatchSessions: (moduleExports, moduleVersion) => {
106
- api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`);
104
+ v4PatchSessions: (moduleExports) => {
107
105
  if ((0, instrumentation_1.isWrapped)(moduleExports.acquire)) {
108
106
  this._unwrap(moduleExports, 'acquire');
109
107
  }
@@ -114,8 +112,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
114
112
  this._wrap(moduleExports.ServerSessionPool.prototype, 'release', this._getV4ReleaseCommand());
115
113
  return moduleExports;
116
114
  },
117
- v4UnpatchSessions: (moduleExports, moduleVersion) => {
118
- api_1.diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);
115
+ v4UnpatchSessions: (moduleExports) => {
119
116
  if (moduleExports === undefined)
120
117
  return;
121
118
  if ((0, instrumentation_1.isWrapped)(moduleExports.acquire)) {
@@ -175,8 +172,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
175
172
  }
176
173
  _getV4ConnectionPoolPatches() {
177
174
  return {
178
- v4PatchConnectionPool: (moduleExports, moduleVersion) => {
179
- api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`);
175
+ v4PatchConnectionPool: (moduleExports) => {
180
176
  const poolPrototype = moduleExports.ConnectionPool.prototype;
181
177
  if ((0, instrumentation_1.isWrapped)(poolPrototype.checkOut)) {
182
178
  this._unwrap(poolPrototype, 'checkOut');
@@ -184,8 +180,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
184
180
  this._wrap(poolPrototype, 'checkOut', this._getV4ConnectionPoolCheckOut());
185
181
  return moduleExports;
186
182
  },
187
- v4UnpatchConnectionPool: (moduleExports, moduleVersion) => {
188
- api_1.diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);
183
+ v4UnpatchConnectionPool: (moduleExports) => {
189
184
  if (moduleExports === undefined)
190
185
  return;
191
186
  this._unwrap(moduleExports.ConnectionPool.prototype, 'checkOut');
@@ -194,16 +189,14 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
194
189
  }
195
190
  _getV4ConnectPatches() {
196
191
  return {
197
- v4PatchConnect: (moduleExports, moduleVersion) => {
198
- api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`);
192
+ v4PatchConnect: (moduleExports) => {
199
193
  if ((0, instrumentation_1.isWrapped)(moduleExports.connect)) {
200
194
  this._unwrap(moduleExports, 'connect');
201
195
  }
202
196
  this._wrap(moduleExports, 'connect', this._getV4ConnectCommand());
203
197
  return moduleExports;
204
198
  },
205
- v4UnpatchConnect: (moduleExports, moduleVersion) => {
206
- api_1.diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);
199
+ v4UnpatchConnect: (moduleExports) => {
207
200
  if (moduleExports === undefined)
208
201
  return;
209
202
  this._unwrap(moduleExports, 'connect');
@@ -224,6 +217,18 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
224
217
  const instrumentation = this;
225
218
  return (original) => {
226
219
  return function patchedConnect(options, callback) {
220
+ // from v6.4 `connect` method only accepts an options param and returns a promise
221
+ // with the connection
222
+ if (original.length === 1) {
223
+ const result = original.call(this, options);
224
+ if (result && typeof result.then === 'function') {
225
+ result.then(() => instrumentation.setPoolName(options),
226
+ // this handler is set to pass the lint rules
227
+ () => undefined);
228
+ }
229
+ return result;
230
+ }
231
+ // Earlier versions expects a callback param and return void
227
232
  const patchedCallback = function (err, conn) {
228
233
  if (err || !conn) {
229
234
  callback(err, conn);
@@ -239,19 +244,25 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
239
244
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
240
245
  _getV4ConnectionPatches() {
241
246
  return {
242
- v4PatchConnection: (moduleExports, moduleVersion) => {
243
- api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`);
247
+ v4PatchConnectionCallback: (moduleExports) => {
248
+ // patch insert operation
249
+ if ((0, instrumentation_1.isWrapped)(moduleExports.Connection.prototype.command)) {
250
+ this._unwrap(moduleExports.Connection.prototype, 'command');
251
+ }
252
+ this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommandCallback());
253
+ return moduleExports;
254
+ },
255
+ v4PatchConnectionPromise: (moduleExports) => {
244
256
  // patch insert operation
245
257
  if ((0, instrumentation_1.isWrapped)(moduleExports.Connection.prototype.command)) {
246
258
  this._unwrap(moduleExports.Connection.prototype, 'command');
247
259
  }
248
- this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommand());
260
+ this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommandPromise());
249
261
  return moduleExports;
250
262
  },
251
- v4UnpatchConnection: (moduleExports, moduleVersion) => {
263
+ v4UnpatchConnection: (moduleExports) => {
252
264
  if (moduleExports === undefined)
253
265
  return;
254
- api_1.diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);
255
266
  this._unwrap(moduleExports.Connection.prototype, 'command');
256
267
  },
257
268
  };
@@ -326,7 +337,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
326
337
  };
327
338
  }
328
339
  /** Creates spans for command operation */
329
- _getV4PatchCommand() {
340
+ _getV4PatchCommandCallback() {
330
341
  const instrumentation = this;
331
342
  return (original) => {
332
343
  return function patchedV4ServerCommand(ns, cmd, options, callback) {
@@ -339,18 +350,39 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
339
350
  cmd.hello) {
340
351
  return original.call(this, ns, cmd, options, callback);
341
352
  }
342
- if (!currentSpan) {
343
- const patchedCallback = instrumentation._patchEnd(undefined, resultHandler, this.id, commandType);
344
- return original.call(this, ns, cmd, options, patchedCallback);
353
+ let span = undefined;
354
+ if (currentSpan) {
355
+ span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {
356
+ kind: api_1.SpanKind.CLIENT,
357
+ });
358
+ instrumentation._populateV4Attributes(span, this, ns, cmd, commandType);
359
+ }
360
+ const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType);
361
+ return original.call(this, ns, cmd, options, patchedCallback);
362
+ };
363
+ };
364
+ }
365
+ _getV4PatchCommandPromise() {
366
+ const instrumentation = this;
367
+ return (original) => {
368
+ return function patchedV4ServerCommand(ns, cmd, options) {
369
+ const currentSpan = api_1.trace.getSpan(api_1.context.active());
370
+ const commandType = Object.keys(cmd)[0];
371
+ const resultHandler = () => undefined;
372
+ if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {
373
+ return original.call(this, ns, cmd, options);
345
374
  }
346
- else {
347
- const span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {
375
+ let span = undefined;
376
+ if (currentSpan) {
377
+ span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {
348
378
  kind: api_1.SpanKind.CLIENT,
349
379
  });
350
380
  instrumentation._populateV4Attributes(span, this, ns, cmd, commandType);
351
- const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType);
352
- return original.call(this, ns, cmd, options, patchedCallback);
353
381
  }
382
+ const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType);
383
+ const result = original.call(this, ns, cmd, options);
384
+ result.then((res) => patchedCallback(null, res), (err) => patchedCallback(err));
385
+ return result;
354
386
  };
355
387
  };
356
388
  }
@@ -504,17 +536,17 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
504
536
  _addAllSpanAttributes(span, dbName, dbCollection, host, port, commandObj, operation) {
505
537
  // add database related attributes
506
538
  span.setAttributes({
507
- [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.MONGODB,
508
- [semantic_conventions_1.SemanticAttributes.DB_NAME]: dbName,
509
- [semantic_conventions_1.SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection,
510
- [semantic_conventions_1.SemanticAttributes.DB_OPERATION]: operation,
511
- [semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,
539
+ [semantic_conventions_1.SEMATTRS_DB_SYSTEM]: semantic_conventions_1.DBSYSTEMVALUES_MONGODB,
540
+ [semantic_conventions_1.SEMATTRS_DB_NAME]: dbName,
541
+ [semantic_conventions_1.SEMATTRS_DB_MONGODB_COLLECTION]: dbCollection,
542
+ [semantic_conventions_1.SEMATTRS_DB_OPERATION]: operation,
543
+ [semantic_conventions_1.SEMATTRS_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,
512
544
  });
513
545
  if (host && port) {
514
- span.setAttribute(semantic_conventions_1.SemanticAttributes.NET_PEER_NAME, host);
546
+ span.setAttribute(semantic_conventions_1.SEMATTRS_NET_PEER_NAME, host);
515
547
  const portNumber = parseInt(port, 10);
516
548
  if (!isNaN(portNumber)) {
517
- span.setAttribute(semantic_conventions_1.SemanticAttributes.NET_PEER_PORT, portNumber);
549
+ span.setAttribute(semantic_conventions_1.SEMATTRS_NET_PEER_PORT, portNumber);
518
550
  }
519
551
  }
520
552
  if (!commandObj)
@@ -524,7 +556,7 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
524
556
  : this._defaultDbStatementSerializer.bind(this);
525
557
  (0, instrumentation_1.safeExecuteInTheMiddle)(() => {
526
558
  const query = dbStatementSerializer(commandObj);
527
- span.setAttribute(semantic_conventions_1.SemanticAttributes.DB_STATEMENT, query);
559
+ span.setAttribute(semantic_conventions_1.SEMATTRS_DB_STATEMENT, query);
528
560
  }, err => {
529
561
  if (err) {
530
562
  this._diag.error('Error running dbStatementSerializer hook', err);
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,oEAMwC;AACxC,8EAG6C;AAE7C,qDAS0B;AAE1B,uCAAoC;AAGpC,uDAAuD;AACvD,MAAa,sBAAuB,SAAQ,qCAAmB;IAI7D,YAA+B,UAAwC,EAAE;QACvE,KAAK,CAAC,wCAAwC,EAAE,iBAAO,EAAE,OAAO,CAAC,CAAC;QADrC,YAAO,GAAP,OAAO,CAAmC;IAEzE,CAAC;IAEQ,wBAAwB;QAC/B,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CACrD,6BAA6B,EAC7B;YACE,WAAW,EACT,yFAAyF;YAC3F,IAAI,EAAE,cAAc;SACrB,CACF,CAAC;IACJ,CAAC;IAED,IAAI;QACF,MAAM,EACJ,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,mBAAmB,GACzC,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEnC,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACzE,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,GAC9C,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACjC,MAAM,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,GACtD,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACrC,MAAM,EAAE,eAAe,EAAE,iBAAiB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AC;aACZ;YAED,OAAO,aAAO,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;gBACtC,IAAI,WAAW,KAAK,aAAa,EAAE;oBACjC,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;wBACxC,KAAK,EAAE,MAAM;wBACb,WAAW,EAAE,eAAe,CAAC,SAAS;qBACvC,CAAC,CAAC;iBACJ;gBACD,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IACO,WAAW,CAAC,OAAY;;QAC9B,MAAM,IAAI,GAAG,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC;QACvC,MAAM,IAAI,GAAG,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC;QACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;QAChC,MAAM,QAAQ,GAAG,aAAa,IAAI,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;CACF;AAz2BD,wDAy2BC","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 trace,\n Span,\n SpanKind,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n DbSystemValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport { MongoDBInstrumentationConfig, CommandResult } from './types';\nimport {\n CursorState,\n ServerSession,\n MongodbCommandType,\n MongoInternalCommand,\n MongoInternalTopology,\n WireProtocolInternal,\n V4Connection,\n V4ConnectionPool,\n} from './internal-types';\nimport { V4Connect, V4Session } from './internal-types';\nimport { VERSION } from './version';\nimport { UpDownCounter } from '@opentelemetry/api';\n\n/** mongodb instrumentation plugin for OpenTelemetry */\nexport class MongoDBInstrumentation extends InstrumentationBase {\n private _connectionsUsage!: UpDownCounter;\n private _poolName!: string;\n\n constructor(protected override _config: MongoDBInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-mongodb', VERSION, _config);\n }\n\n override _updateMetricInstruments() {\n this._connectionsUsage = this.meter.createUpDownCounter(\n 'db.client.connections.usage',\n {\n description:\n 'The number of connections that are currently in state described by the state attribute.',\n unit: '{connection}',\n }\n );\n }\n\n init() {\n const {\n v3PatchConnection: v3PatchConnection,\n v3UnpatchConnection: v3UnpatchConnection,\n } = this._getV3ConnectionPatches();\n\n const { v4PatchConnect, v4UnpatchConnect } = this._getV4ConnectPatches();\n const { v4PatchConnection, v4UnpatchConnection } =\n this._getV4ConnectionPatches();\n const { v4PatchConnectionPool, v4UnpatchConnectionPool } =\n this._getV4ConnectionPoolPatches();\n const { v4PatchSessions, v4UnpatchSessions } = this._getV4SessionsPatches();\n\n return [\n new InstrumentationNodeModuleDefinition<any>(\n 'mongodb',\n ['>=3.3 <4'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile<WireProtocolInternal>(\n 'mongodb/lib/core/wireprotocol/index.js',\n ['>=3.3 <4'],\n v3PatchConnection,\n v3UnpatchConnection\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition<any>(\n 'mongodb',\n ['4.*', '5.*', '>=6 <6.4'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile<V4Connection>(\n 'mongodb/lib/cmap/connection.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchConnection,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile<V4ConnectionPool>(\n 'mongodb/lib/cmap/connection_pool.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchConnectionPool,\n v4UnpatchConnectionPool\n ),\n new InstrumentationNodeModuleFile<V4Connect>(\n 'mongodb/lib/cmap/connect.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchConnect,\n v4UnpatchConnect\n ),\n new InstrumentationNodeModuleFile<V4Session>(\n 'mongodb/lib/sessions.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchSessions,\n v4UnpatchSessions\n ),\n ]\n ),\n ];\n }\n\n private _getV3ConnectionPatches<T extends WireProtocolInternal>() {\n return {\n v3PatchConnection: (moduleExports: T, moduleVersion?: string) => {\n diag.debug(`Applying patch for mongodb@${moduleVersion}`);\n // patch insert operation\n if (isWrapped(moduleExports.insert)) {\n this._unwrap(moduleExports, 'insert');\n }\n this._wrap(\n moduleExports,\n 'insert',\n this._getV3PatchOperation('insert')\n );\n // patch remove operation\n if (isWrapped(moduleExports.remove)) {\n this._unwrap(moduleExports, 'remove');\n }\n this._wrap(\n moduleExports,\n 'remove',\n this._getV3PatchOperation('remove')\n );\n // patch update operation\n if (isWrapped(moduleExports.update)) {\n this._unwrap(moduleExports, 'update');\n }\n this._wrap(\n moduleExports,\n 'update',\n this._getV3PatchOperation('update')\n );\n // patch other command\n if (isWrapped(moduleExports.command)) {\n this._unwrap(moduleExports, 'command');\n }\n this._wrap(moduleExports, 'command', this._getV3PatchCommand());\n // patch query\n if (isWrapped(moduleExports.query)) {\n this._unwrap(moduleExports, 'query');\n }\n this._wrap(moduleExports, 'query', this._getV3PatchFind());\n // patch get more operation on cursor\n if (isWrapped(moduleExports.getMore)) {\n this._unwrap(moduleExports, 'getMore');\n }\n this._wrap(moduleExports, 'getMore', this._getV3PatchCursor());\n return moduleExports;\n },\n v3UnpatchConnection: (moduleExports?: T, moduleVersion?: string) => {\n if (moduleExports === undefined) return;\n diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);\n this._unwrap(moduleExports, 'insert');\n this._unwrap(moduleExports, 'remove');\n this._unwrap(moduleExports, 'update');\n this._unwrap(moduleExports, 'command');\n this._unwrap(moduleExports, 'query');\n this._unwrap(moduleExports, 'getMore');\n },\n };\n }\n\n private _getV4SessionsPatches<T extends V4Session>() {\n return {\n v4PatchSessions: (moduleExports: any, moduleVersion?: string) => {\n diag.debug(`Applying patch for mongodb@${moduleVersion}`);\n if (isWrapped(moduleExports.acquire)) {\n this._unwrap(moduleExports, 'acquire');\n }\n this._wrap(\n moduleExports.ServerSessionPool.prototype,\n 'acquire',\n this._getV4AcquireCommand()\n );\n\n if (isWrapped(moduleExports.release)) {\n this._unwrap(moduleExports, 'release');\n }\n this._wrap(\n moduleExports.ServerSessionPool.prototype,\n 'release',\n this._getV4ReleaseCommand()\n );\n return moduleExports;\n },\n v4UnpatchSessions: (moduleExports?: T, moduleVersion?: string) => {\n diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);\n if (moduleExports === undefined) return;\n if (isWrapped(moduleExports.acquire)) {\n this._unwrap(moduleExports, 'acquire');\n }\n if (isWrapped(moduleExports.release)) {\n this._unwrap(moduleExports, 'release');\n }\n },\n };\n }\n\n private _getV4AcquireCommand() {\n const instrumentation = this;\n return (original: V4Session['acquire']) => {\n return function patchAcquire(this: any) {\n const nSessionsBeforeAcquire = this.sessions.length;\n const session = original.call(this);\n const nSessionsAfterAcquire = this.sessions.length;\n\n if (nSessionsBeforeAcquire === nSessionsAfterAcquire) {\n //no session in the pool. a new session was created and used\n instrumentation._connectionsUsage.add(1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n } else if (nSessionsBeforeAcquire - 1 === nSessionsAfterAcquire) {\n //a session was already in the pool. remove it from the pool and use it.\n instrumentation._connectionsUsage.add(-1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n instrumentation._connectionsUsage.add(1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n }\n return session;\n };\n };\n }\n\n private _getV4ReleaseCommand() {\n const instrumentation = this;\n return (original: V4Session['release']) => {\n return function patchRelease(this: any, session: ServerSession) {\n const cmdPromise = original.call(this, session);\n\n instrumentation._connectionsUsage.add(-1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n instrumentation._connectionsUsage.add(1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n return cmdPromise;\n };\n };\n }\n\n private _getV4ConnectionPoolPatches<T extends V4ConnectionPool>() {\n return {\n v4PatchConnectionPool: (moduleExports: any, moduleVersion?: string) => {\n diag.debug(`Applying patch for mongodb@${moduleVersion}`);\n const poolPrototype = moduleExports.ConnectionPool.prototype;\n\n if (isWrapped(poolPrototype.checkOut)) {\n this._unwrap(poolPrototype, 'checkOut');\n }\n\n this._wrap(\n poolPrototype,\n 'checkOut',\n this._getV4ConnectionPoolCheckOut()\n );\n return moduleExports;\n },\n v4UnpatchConnectionPool: (\n moduleExports?: any,\n moduleVersion?: string\n ) => {\n diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports.ConnectionPool.prototype, 'checkOut');\n },\n };\n }\n\n private _getV4ConnectPatches<T extends V4Connect>() {\n return {\n v4PatchConnect: (moduleExports: any, moduleVersion?: string) => {\n diag.debug(`Applying patch for mongodb@${moduleVersion}`);\n if (isWrapped(moduleExports.connect)) {\n this._unwrap(moduleExports, 'connect');\n }\n\n this._wrap(moduleExports, 'connect', this._getV4ConnectCommand());\n return moduleExports;\n },\n v4UnpatchConnect: (moduleExports?: T, moduleVersion?: string) => {\n diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports, 'connect');\n },\n };\n }\n\n // This patch will become unnecessary once\n // https://jira.mongodb.org/browse/NODE-5639 is done.\n private _getV4ConnectionPoolCheckOut() {\n return (original: V4ConnectionPool['checkOut']) => {\n return function patchedCheckout(this: unknown, callback: any) {\n const patchedCallback = context.bind(context.active(), callback);\n return original.call(this, patchedCallback);\n };\n };\n }\n\n private _getV4ConnectCommand() {\n const instrumentation = this;\n\n return (original: V4Connect['connect']) => {\n return function patchedConnect(\n this: unknown,\n options: any,\n callback: any\n ) {\n const patchedCallback = function (err: any, conn: any) {\n if (err || !conn) {\n callback(err, conn);\n return;\n }\n instrumentation.setPoolName(options);\n callback(err, conn);\n };\n return original.call(this, options, patchedCallback);\n };\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n private _getV4ConnectionPatches<T extends V4Connection>() {\n return {\n v4PatchConnection: (moduleExports: any, moduleVersion?: string) => {\n diag.debug(`Applying patch for mongodb@${moduleVersion}`);\n // patch insert operation\n if (isWrapped(moduleExports.Connection.prototype.command)) {\n this._unwrap(moduleExports.Connection.prototype, 'command');\n }\n\n this._wrap(\n moduleExports.Connection.prototype,\n 'command',\n this._getV4PatchCommand()\n );\n return moduleExports;\n },\n v4UnpatchConnection: (moduleExports?: any, moduleVersion?: string) => {\n if (moduleExports === undefined) return;\n diag.debug(`Removing internal patch for mongodb@${moduleVersion}`);\n this._unwrap(moduleExports.Connection.prototype, 'command');\n },\n };\n }\n\n /** Creates spans for common operations */\n private _getV3PatchOperation(operationName: 'insert' | 'update' | 'remove') {\n const instrumentation = this;\n return (original: WireProtocolInternal[typeof operationName]) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof ops !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, ops, options);\n } else {\n return original.call(this, server, ns, ops, options, callback);\n }\n }\n const span = instrumentation.tracer.startSpan(\n `mongodb.${operationName}`,\n {\n kind: SpanKind.CLIENT,\n }\n );\n\n instrumentation._populateV3Attributes(\n span,\n ns,\n server,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ops[0] as any,\n operationName\n );\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(this, server, ns, ops, patchedCallback);\n } else {\n return original.call(this, server, ns, ops, options, patchedCallback);\n }\n };\n };\n }\n\n /** Creates spans for command operation */\n private _getV3PatchCommand() {\n const instrumentation = this;\n return (original: WireProtocolInternal['command']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, options);\n } else {\n return original.call(this, server, ns, cmd, options, callback);\n }\n }\n const commandType = MongoDBInstrumentation._getCommandType(cmd);\n const type =\n commandType === MongodbCommandType.UNKNOWN ? 'command' : commandType;\n const span = instrumentation.tracer.startSpan(`mongodb.${type}`, {\n kind: SpanKind.CLIENT,\n });\n const operation =\n commandType === MongodbCommandType.UNKNOWN ? undefined : commandType;\n instrumentation._populateV3Attributes(span, ns, server, cmd, operation);\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, patchedCallback);\n } else {\n return original.call(this, server, ns, cmd, options, patchedCallback);\n }\n };\n };\n }\n\n /** Creates spans for command operation */\n private _getV4PatchCommand() {\n const instrumentation = this;\n return (original: V4Connection['command']) => {\n return function patchedV4ServerCommand(\n this: any,\n ns: any,\n cmd: any,\n options: undefined | unknown,\n callback: any\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler = callback;\n const commandType = Object.keys(cmd)[0];\n\n if (\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object' ||\n cmd.ismaster ||\n cmd.hello\n ) {\n return original.call(this, ns, cmd, options, callback);\n }\n if (!currentSpan) {\n const patchedCallback = instrumentation._patchEnd(\n undefined,\n resultHandler,\n this.id,\n commandType\n );\n\n return original.call(this, ns, cmd, options, patchedCallback);\n } else {\n const span = instrumentation.tracer.startSpan(\n `mongodb.${commandType}`,\n {\n kind: SpanKind.CLIENT,\n }\n );\n instrumentation._populateV4Attributes(\n span,\n this,\n ns,\n cmd,\n commandType\n );\n const patchedCallback = instrumentation._patchEnd(\n span,\n resultHandler,\n this.id,\n commandType\n );\n\n return original.call(this, ns, cmd, options, patchedCallback);\n }\n };\n };\n }\n\n /** Creates spans for find operation */\n private _getV3PatchFind() {\n const instrumentation = this;\n return (original: WireProtocolInternal['query']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n cursorState: CursorState,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, cursorState, options);\n } else {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n options,\n callback\n );\n }\n }\n const span = instrumentation.tracer.startSpan('mongodb.find', {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV3Attributes(span, ns, server, cmd, 'find');\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n patchedCallback\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n options,\n patchedCallback\n );\n }\n };\n };\n }\n\n /** Creates spans for find operation */\n private _getV3PatchCursor() {\n const instrumentation = this;\n return (original: WireProtocolInternal['getMore']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n batchSize: number,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (!currentSpan || typeof resultHandler !== 'function') {\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options,\n callback\n );\n }\n }\n const span = instrumentation.tracer.startSpan('mongodb.getMore', {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV3Attributes(\n span,\n ns,\n server,\n cursorState.cmd,\n 'getMore'\n );\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n patchedCallback\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options,\n patchedCallback\n );\n }\n };\n };\n }\n\n /**\n * Get the mongodb command type from the object.\n * @param command Internal mongodb command object\n */\n private static _getCommandType(\n command: MongoInternalCommand\n ): MongodbCommandType {\n if (command.createIndexes !== undefined) {\n return MongodbCommandType.CREATE_INDEXES;\n } else if (command.findandmodify !== undefined) {\n return MongodbCommandType.FIND_AND_MODIFY;\n } else if (command.ismaster !== undefined) {\n return MongodbCommandType.IS_MASTER;\n } else if (command.count !== undefined) {\n return MongodbCommandType.COUNT;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n }\n\n /**\n * Populate span's attributes by fetching related metadata from the context\n * @param span span to add attributes to\n * @param connectionCtx mongodb internal connection context\n * @param ns mongodb namespace\n * @param command mongodb internal representation of a command\n */\n private _populateV4Attributes(\n span: Span,\n connectionCtx: any,\n ns: any,\n command?: any,\n operation?: string\n ) {\n let host, port: undefined | string;\n if (connectionCtx) {\n const hostParts =\n typeof connectionCtx.address === 'string'\n ? connectionCtx.address.split(':')\n : '';\n if (hostParts.length === 2) {\n host = hostParts[0];\n port = hostParts[1];\n }\n }\n // capture parameters within the query as well if enhancedDatabaseReporting is enabled.\n let commandObj: Record<string, unknown>;\n if (command?.documents && command.documents[0]) {\n commandObj = command.documents[0];\n } else if (command?.cursors) {\n commandObj = command.cursors;\n } else {\n commandObj = command;\n }\n\n this._addAllSpanAttributes(\n span,\n ns.db,\n ns.collection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n /**\n * Populate span's attributes by fetching related metadata from the context\n * @param span span to add attributes to\n * @param ns mongodb namespace\n * @param topology mongodb internal representation of the network topology\n * @param command mongodb internal representation of a command\n */\n private _populateV3Attributes(\n span: Span,\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined\n ) {\n // add network attributes to determine the remote server\n let host: undefined | string;\n let port: undefined | string;\n if (topology && topology.s) {\n host = topology.s.options?.host ?? topology.s.host;\n port = (topology.s.options?.port ?? topology.s.port)?.toString();\n if (host == null || port == null) {\n const address = topology.description?.address;\n if (address) {\n const addressSegments = address.split(':');\n host = addressSegments[0];\n port = addressSegments[1];\n }\n }\n }\n\n // The namespace is a combination of the database name and the name of the\n // collection or index, like so: [database-name].[collection-or-index-name].\n // It could be a string or an instance of MongoDBNamespace, as such we\n // always coerce to a string to extract db and collection.\n const [dbName, dbCollection] = ns.toString().split('.');\n // capture parameters within the query as well if enhancedDatabaseReporting is enabled.\n const commandObj = command?.query ?? command?.q ?? command;\n\n this._addAllSpanAttributes(\n span,\n dbName,\n dbCollection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n private _addAllSpanAttributes(\n span: Span,\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined\n ) {\n // add database related attributes\n span.setAttributes({\n [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MONGODB,\n [SemanticAttributes.DB_NAME]: dbName,\n [SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection,\n [SemanticAttributes.DB_OPERATION]: operation,\n [SemanticAttributes.DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n });\n\n if (host && port) {\n span.setAttribute(SemanticAttributes.NET_PEER_NAME, host);\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n span.setAttribute(SemanticAttributes.NET_PEER_PORT, portNumber);\n }\n }\n if (!commandObj) return;\n const dbStatementSerializer =\n typeof this._config.dbStatementSerializer === 'function'\n ? this._config.dbStatementSerializer\n : this._defaultDbStatementSerializer.bind(this);\n\n safeExecuteInTheMiddle(\n () => {\n const query = dbStatementSerializer(commandObj);\n span.setAttribute(SemanticAttributes.DB_STATEMENT, query);\n },\n err => {\n if (err) {\n this._diag.error('Error running dbStatementSerializer hook', err);\n }\n },\n true\n );\n }\n\n private _defaultDbStatementSerializer(commandObj: Record<string, unknown>) {\n const enhancedDbReporting = !!this._config?.enhancedDatabaseReporting;\n const resultObj = enhancedDbReporting\n ? commandObj\n : Object.keys(commandObj).reduce((obj, key) => {\n obj[key] = '?';\n return obj;\n }, {} as { [key: string]: unknown });\n return JSON.stringify(resultObj);\n }\n\n /**\n * Triggers the response hook in case it is defined.\n * @param span The span to add the results to.\n * @param result The command result\n */\n private _handleExecutionResult(span: Span, result: CommandResult) {\n const config: MongoDBInstrumentationConfig = this.getConfig();\n if (typeof config.responseHook === 'function') {\n safeExecuteInTheMiddle(\n () => {\n config.responseHook!(span, { data: result });\n },\n err => {\n if (err) {\n this._diag.error('Error running response hook', err);\n }\n },\n true\n );\n }\n }\n\n /**\n * Ends a created span.\n * @param span The created span to end.\n * @param resultHandler A callback function.\n * @param connectionId: The connection ID of the Command response.\n */\n private _patchEnd(\n span: Span | undefined,\n resultHandler: Function,\n connectionId?: number,\n commandType?: string\n ): Function {\n // mongodb is using \"tick\" when calling a callback, this way the context\n // in final callback (resultHandler) is lost\n const activeContext = context.active();\n const instrumentation = this;\n return function patchedEnd(this: {}, ...args: unknown[]) {\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span?.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n } else {\n const result = args[1] as CommandResult;\n instrumentation._handleExecutionResult(span, result);\n }\n span.end();\n }\n\n return context.with(activeContext, () => {\n if (commandType === 'endSessions') {\n instrumentation._connectionsUsage.add(-1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n }\n return resultHandler.apply(this, args);\n });\n };\n }\n private setPoolName(options: any) {\n const host = options.hostAddress?.host;\n const port = options.hostAddress?.port;\n const database = options.dbName;\n const poolName = `mongodb://${host}:${port}/${database}`;\n this._poolName = poolName;\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAM4B;AAC5B,oEAMwC;AACxC,8EAU6C;AAE7C,qDAS0B;AAE1B,uCAAoC;AAGpC,uDAAuD;AACvD,MAAa,sBAAuB,SAAQ,qCAAmB;IAI7D,YAA+B,UAAwC,EAAE;QACvE,KAAK,CAAC,wCAAwC,EAAE,iBAAO,EAAE,OAAO,CAAC,CAAC;QADrC,YAAO,GAAP,OAAO,CAAmC;IAEzE,CAAC;IAEQ,wBAAwB;QAC/B,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CACrD,6BAA6B,EAC7B;YACE,WAAW,EACT,yFAAyF;YAC3F,IAAI,EAAE,cAAc;SACrB,CACF,CAAC;IACJ,CAAC;IAED,IAAI;QACF,MAAM,EACJ,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,mBAAmB,GACzC,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEnC,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACzE,MAAM,EACJ,yBAAyB,EACzB,wBAAwB,E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eAAe,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;iBACtD;gBACD,IAAI,CAAC,GAAG,EAAE,CAAC;aACZ;YAED,OAAO,aAAO,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;gBACtC,IAAI,WAAW,KAAK,aAAa,EAAE;oBACjC,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;wBACxC,KAAK,EAAE,MAAM;wBACb,WAAW,EAAE,eAAe,CAAC,SAAS;qBACvC,CAAC,CAAC;iBACJ;gBACD,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IACO,WAAW,CAAC,OAAY;;QAC9B,MAAM,IAAI,GAAG,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC;QACvC,MAAM,IAAI,GAAG,MAAA,OAAO,CAAC,WAAW,0CAAE,IAAI,CAAC;QACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;QAChC,MAAM,QAAQ,GAAG,aAAa,IAAI,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;CACF;AAl7BD,wDAk7BC","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 trace,\n Span,\n SpanKind,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n DBSYSTEMVALUES_MONGODB,\n SEMATTRS_DB_CONNECTION_STRING,\n SEMATTRS_DB_MONGODB_COLLECTION,\n SEMATTRS_DB_NAME,\n SEMATTRS_DB_OPERATION,\n SEMATTRS_DB_STATEMENT,\n SEMATTRS_DB_SYSTEM,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport { MongoDBInstrumentationConfig, CommandResult } from './types';\nimport {\n CursorState,\n ServerSession,\n MongodbCommandType,\n MongoInternalCommand,\n MongoInternalTopology,\n WireProtocolInternal,\n V4Connection,\n V4ConnectionPool,\n} from './internal-types';\nimport { V4Connect, V4Session } from './internal-types';\nimport { VERSION } from './version';\nimport { UpDownCounter } from '@opentelemetry/api';\n\n/** mongodb instrumentation plugin for OpenTelemetry */\nexport class MongoDBInstrumentation extends InstrumentationBase {\n private _connectionsUsage!: UpDownCounter;\n private _poolName!: string;\n\n constructor(protected override _config: MongoDBInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-mongodb', VERSION, _config);\n }\n\n override _updateMetricInstruments() {\n this._connectionsUsage = this.meter.createUpDownCounter(\n 'db.client.connections.usage',\n {\n description:\n 'The number of connections that are currently in state described by the state attribute.',\n unit: '{connection}',\n }\n );\n }\n\n init() {\n const {\n v3PatchConnection: v3PatchConnection,\n v3UnpatchConnection: v3UnpatchConnection,\n } = this._getV3ConnectionPatches();\n\n const { v4PatchConnect, v4UnpatchConnect } = this._getV4ConnectPatches();\n const {\n v4PatchConnectionCallback,\n v4PatchConnectionPromise,\n v4UnpatchConnection,\n } = this._getV4ConnectionPatches();\n const { v4PatchConnectionPool, v4UnpatchConnectionPool } =\n this._getV4ConnectionPoolPatches();\n const { v4PatchSessions, v4UnpatchSessions } = this._getV4SessionsPatches();\n\n return [\n new InstrumentationNodeModuleDefinition(\n 'mongodb',\n ['>=3.3 <4'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/core/wireprotocol/index.js',\n ['>=3.3 <4'],\n v3PatchConnection,\n v3UnpatchConnection\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition(\n 'mongodb',\n ['4.*', '5.*', '6.*'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchConnectionCallback,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['>=6.4'],\n v4PatchConnectionPromise,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection_pool.js',\n ['4.*', '5.*', '>=6 <6.4'],\n v4PatchConnectionPool,\n v4UnpatchConnectionPool\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connect.js',\n ['4.*', '5.*', '6.*'],\n v4PatchConnect,\n v4UnpatchConnect\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/sessions.js',\n ['4.*', '5.*', '6.*'],\n v4PatchSessions,\n v4UnpatchSessions\n ),\n ]\n ),\n ];\n }\n\n private _getV3ConnectionPatches<T extends WireProtocolInternal>() {\n return {\n v3PatchConnection: (moduleExports: T) => {\n // patch insert operation\n if (isWrapped(moduleExports.insert)) {\n this._unwrap(moduleExports, 'insert');\n }\n this._wrap(\n moduleExports,\n 'insert',\n this._getV3PatchOperation('insert')\n );\n // patch remove operation\n if (isWrapped(moduleExports.remove)) {\n this._unwrap(moduleExports, 'remove');\n }\n this._wrap(\n moduleExports,\n 'remove',\n this._getV3PatchOperation('remove')\n );\n // patch update operation\n if (isWrapped(moduleExports.update)) {\n this._unwrap(moduleExports, 'update');\n }\n this._wrap(\n moduleExports,\n 'update',\n this._getV3PatchOperation('update')\n );\n // patch other command\n if (isWrapped(moduleExports.command)) {\n this._unwrap(moduleExports, 'command');\n }\n this._wrap(moduleExports, 'command', this._getV3PatchCommand());\n // patch query\n if (isWrapped(moduleExports.query)) {\n this._unwrap(moduleExports, 'query');\n }\n this._wrap(moduleExports, 'query', this._getV3PatchFind());\n // patch get more operation on cursor\n if (isWrapped(moduleExports.getMore)) {\n this._unwrap(moduleExports, 'getMore');\n }\n this._wrap(moduleExports, 'getMore', this._getV3PatchCursor());\n return moduleExports;\n },\n v3UnpatchConnection: (moduleExports?: T) => {\n if (moduleExports === undefined) return;\n this._unwrap(moduleExports, 'insert');\n this._unwrap(moduleExports, 'remove');\n this._unwrap(moduleExports, 'update');\n this._unwrap(moduleExports, 'command');\n this._unwrap(moduleExports, 'query');\n this._unwrap(moduleExports, 'getMore');\n },\n };\n }\n\n private _getV4SessionsPatches<T extends V4Session>() {\n return {\n v4PatchSessions: (moduleExports: any) => {\n if (isWrapped(moduleExports.acquire)) {\n this._unwrap(moduleExports, 'acquire');\n }\n this._wrap(\n moduleExports.ServerSessionPool.prototype,\n 'acquire',\n this._getV4AcquireCommand()\n );\n\n if (isWrapped(moduleExports.release)) {\n this._unwrap(moduleExports, 'release');\n }\n this._wrap(\n moduleExports.ServerSessionPool.prototype,\n 'release',\n this._getV4ReleaseCommand()\n );\n return moduleExports;\n },\n v4UnpatchSessions: (moduleExports?: T) => {\n if (moduleExports === undefined) return;\n if (isWrapped(moduleExports.acquire)) {\n this._unwrap(moduleExports, 'acquire');\n }\n if (isWrapped(moduleExports.release)) {\n this._unwrap(moduleExports, 'release');\n }\n },\n };\n }\n\n private _getV4AcquireCommand() {\n const instrumentation = this;\n return (original: V4Session['acquire']) => {\n return function patchAcquire(this: any) {\n const nSessionsBeforeAcquire = this.sessions.length;\n const session = original.call(this);\n const nSessionsAfterAcquire = this.sessions.length;\n\n if (nSessionsBeforeAcquire === nSessionsAfterAcquire) {\n //no session in the pool. a new session was created and used\n instrumentation._connectionsUsage.add(1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n } else if (nSessionsBeforeAcquire - 1 === nSessionsAfterAcquire) {\n //a session was already in the pool. remove it from the pool and use it.\n instrumentation._connectionsUsage.add(-1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n instrumentation._connectionsUsage.add(1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n }\n return session;\n };\n };\n }\n\n private _getV4ReleaseCommand() {\n const instrumentation = this;\n return (original: V4Session['release']) => {\n return function patchRelease(this: any, session: ServerSession) {\n const cmdPromise = original.call(this, session);\n\n instrumentation._connectionsUsage.add(-1, {\n state: 'used',\n 'pool.name': instrumentation._poolName,\n });\n instrumentation._connectionsUsage.add(1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n return cmdPromise;\n };\n };\n }\n\n private _getV4ConnectionPoolPatches<T extends V4ConnectionPool>() {\n return {\n v4PatchConnectionPool: (moduleExports: any) => {\n const poolPrototype = moduleExports.ConnectionPool.prototype;\n\n if (isWrapped(poolPrototype.checkOut)) {\n this._unwrap(poolPrototype, 'checkOut');\n }\n\n this._wrap(\n poolPrototype,\n 'checkOut',\n this._getV4ConnectionPoolCheckOut()\n );\n return moduleExports;\n },\n v4UnpatchConnectionPool: (moduleExports?: any) => {\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports.ConnectionPool.prototype, 'checkOut');\n },\n };\n }\n\n private _getV4ConnectPatches<T extends V4Connect>() {\n return {\n v4PatchConnect: (moduleExports: any) => {\n if (isWrapped(moduleExports.connect)) {\n this._unwrap(moduleExports, 'connect');\n }\n\n this._wrap(moduleExports, 'connect', this._getV4ConnectCommand());\n return moduleExports;\n },\n v4UnpatchConnect: (moduleExports?: T) => {\n if (moduleExports === undefined) return;\n\n this._unwrap(moduleExports, 'connect');\n },\n };\n }\n\n // This patch will become unnecessary once\n // https://jira.mongodb.org/browse/NODE-5639 is done.\n private _getV4ConnectionPoolCheckOut() {\n return (original: V4ConnectionPool['checkOut']) => {\n return function patchedCheckout(this: unknown, callback: any) {\n const patchedCallback = context.bind(context.active(), callback);\n return original.call(this, patchedCallback);\n };\n };\n }\n\n private _getV4ConnectCommand() {\n const instrumentation = this;\n\n return (\n original: V4Connect['connectCallback'] | V4Connect['connectPromise']\n ) => {\n return function patchedConnect(\n this: unknown,\n options: any,\n callback: any\n ) {\n // from v6.4 `connect` method only accepts an options param and returns a promise\n // with the connection\n if (original.length === 1) {\n const result = (original as V4Connect['connectPromise']).call(\n this,\n options\n );\n if (result && typeof result.then === 'function') {\n result.then(\n () => instrumentation.setPoolName(options),\n // this handler is set to pass the lint rules\n () => undefined\n );\n }\n return result;\n }\n\n // Earlier versions expects a callback param and return void\n const patchedCallback = function (err: any, conn: any) {\n if (err || !conn) {\n callback(err, conn);\n return;\n }\n instrumentation.setPoolName(options);\n callback(err, conn);\n };\n\n return (original as V4Connect['connectCallback']).call(\n this,\n options,\n patchedCallback\n );\n };\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n private _getV4ConnectionPatches<T extends V4Connection>() {\n return {\n v4PatchConnectionCallback: (moduleExports: any) => {\n // patch insert operation\n if (isWrapped(moduleExports.Connection.prototype.command)) {\n this._unwrap(moduleExports.Connection.prototype, 'command');\n }\n\n this._wrap(\n moduleExports.Connection.prototype,\n 'command',\n this._getV4PatchCommandCallback()\n );\n return moduleExports;\n },\n v4PatchConnectionPromise: (moduleExports: any) => {\n // patch insert operation\n if (isWrapped(moduleExports.Connection.prototype.command)) {\n this._unwrap(moduleExports.Connection.prototype, 'command');\n }\n\n this._wrap(\n moduleExports.Connection.prototype,\n 'command',\n this._getV4PatchCommandPromise()\n );\n return moduleExports;\n },\n v4UnpatchConnection: (moduleExports?: any) => {\n if (moduleExports === undefined) return;\n this._unwrap(moduleExports.Connection.prototype, 'command');\n },\n };\n }\n\n /** Creates spans for common operations */\n private _getV3PatchOperation(operationName: 'insert' | 'update' | 'remove') {\n const instrumentation = this;\n return (original: WireProtocolInternal[typeof operationName]) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof ops !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, ops, options);\n } else {\n return original.call(this, server, ns, ops, options, callback);\n }\n }\n const span = instrumentation.tracer.startSpan(\n `mongodb.${operationName}`,\n {\n kind: SpanKind.CLIENT,\n }\n );\n\n instrumentation._populateV3Attributes(\n span,\n ns,\n server,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ops[0] as any,\n operationName\n );\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(this, server, ns, ops, patchedCallback);\n } else {\n return original.call(this, server, ns, ops, options, patchedCallback);\n }\n };\n };\n }\n\n /** Creates spans for command operation */\n private _getV3PatchCommand() {\n const instrumentation = this;\n return (original: WireProtocolInternal['command']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, options);\n } else {\n return original.call(this, server, ns, cmd, options, callback);\n }\n }\n const commandType = MongoDBInstrumentation._getCommandType(cmd);\n const type =\n commandType === MongodbCommandType.UNKNOWN ? 'command' : commandType;\n const span = instrumentation.tracer.startSpan(`mongodb.${type}`, {\n kind: SpanKind.CLIENT,\n });\n const operation =\n commandType === MongodbCommandType.UNKNOWN ? undefined : commandType;\n instrumentation._populateV3Attributes(span, ns, server, cmd, operation);\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, patchedCallback);\n } else {\n return original.call(this, server, ns, cmd, options, patchedCallback);\n }\n };\n };\n }\n\n /** Creates spans for command operation */\n private _getV4PatchCommandCallback() {\n const instrumentation = this;\n return (original: V4Connection['commandCallback']) => {\n return function patchedV4ServerCommand(\n this: any,\n ns: any,\n cmd: any,\n options: undefined | unknown,\n callback: any\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler = callback;\n const commandType = Object.keys(cmd)[0];\n\n if (\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object' ||\n cmd.ismaster ||\n cmd.hello\n ) {\n return original.call(this, ns, cmd, options, callback);\n }\n\n let span = undefined;\n if (currentSpan) {\n span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV4Attributes(\n span,\n this,\n ns,\n cmd,\n commandType\n );\n }\n const patchedCallback = instrumentation._patchEnd(\n span,\n resultHandler,\n this.id,\n commandType\n );\n\n return original.call(this, ns, cmd, options, patchedCallback);\n };\n };\n }\n\n private _getV4PatchCommandPromise() {\n const instrumentation = this;\n return (original: V4Connection['commandPromise']) => {\n return function patchedV4ServerCommand(\n this: any,\n ns: any,\n cmd: any,\n options: undefined | unknown\n ) {\n const currentSpan = trace.getSpan(context.active());\n const commandType = Object.keys(cmd)[0];\n const resultHandler = () => undefined;\n\n if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {\n return original.call(this, ns, cmd, options);\n }\n\n let span = undefined;\n if (currentSpan) {\n span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV4Attributes(\n span,\n this,\n ns,\n cmd,\n commandType\n );\n }\n\n const patchedCallback = instrumentation._patchEnd(\n span,\n resultHandler,\n this.id,\n commandType\n );\n\n const result = original.call(this, ns, cmd, options);\n result.then(\n (res: any) => patchedCallback(null, res),\n (err: any) => patchedCallback(err)\n );\n\n return result;\n };\n };\n }\n\n /** Creates spans for find operation */\n private _getV3PatchFind() {\n const instrumentation = this;\n return (original: WireProtocolInternal['query']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n cursorState: CursorState,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n !currentSpan ||\n typeof resultHandler !== 'function' ||\n typeof cmd !== 'object'\n ) {\n if (typeof options === 'function') {\n return original.call(this, server, ns, cmd, cursorState, options);\n } else {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n options,\n callback\n );\n }\n }\n const span = instrumentation.tracer.startSpan('mongodb.find', {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV3Attributes(span, ns, server, cmd, 'find');\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n patchedCallback\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cmd,\n cursorState,\n options,\n patchedCallback\n );\n }\n };\n };\n }\n\n /** Creates spans for find operation */\n private _getV3PatchCursor() {\n const instrumentation = this;\n return (original: WireProtocolInternal['getMore']) => {\n return function patchedServerCommand(\n this: unknown,\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n batchSize: number,\n options: unknown | Function,\n callback?: Function\n ) {\n const currentSpan = trace.getSpan(context.active());\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (!currentSpan || typeof resultHandler !== 'function') {\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options,\n callback\n );\n }\n }\n const span = instrumentation.tracer.startSpan('mongodb.getMore', {\n kind: SpanKind.CLIENT,\n });\n instrumentation._populateV3Attributes(\n span,\n ns,\n server,\n cursorState.cmd,\n 'getMore'\n );\n const patchedCallback = instrumentation._patchEnd(span, resultHandler);\n // handle when options is the callback to send the correct number of args\n if (typeof options === 'function') {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n patchedCallback\n );\n } else {\n return original.call(\n this,\n server,\n ns,\n cursorState,\n batchSize,\n options,\n patchedCallback\n );\n }\n };\n };\n }\n\n /**\n * Get the mongodb command type from the object.\n * @param command Internal mongodb command object\n */\n private static _getCommandType(\n command: MongoInternalCommand\n ): MongodbCommandType {\n if (command.createIndexes !== undefined) {\n return MongodbCommandType.CREATE_INDEXES;\n } else if (command.findandmodify !== undefined) {\n return MongodbCommandType.FIND_AND_MODIFY;\n } else if (command.ismaster !== undefined) {\n return MongodbCommandType.IS_MASTER;\n } else if (command.count !== undefined) {\n return MongodbCommandType.COUNT;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n }\n\n /**\n * Populate span's attributes by fetching related metadata from the context\n * @param span span to add attributes to\n * @param connectionCtx mongodb internal connection context\n * @param ns mongodb namespace\n * @param command mongodb internal representation of a command\n */\n private _populateV4Attributes(\n span: Span,\n connectionCtx: any,\n ns: any,\n command?: any,\n operation?: string\n ) {\n let host, port: undefined | string;\n if (connectionCtx) {\n const hostParts =\n typeof connectionCtx.address === 'string'\n ? connectionCtx.address.split(':')\n : '';\n if (hostParts.length === 2) {\n host = hostParts[0];\n port = hostParts[1];\n }\n }\n // capture parameters within the query as well if enhancedDatabaseReporting is enabled.\n let commandObj: Record<string, unknown>;\n if (command?.documents && command.documents[0]) {\n commandObj = command.documents[0];\n } else if (command?.cursors) {\n commandObj = command.cursors;\n } else {\n commandObj = command;\n }\n\n this._addAllSpanAttributes(\n span,\n ns.db,\n ns.collection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n /**\n * Populate span's attributes by fetching related metadata from the context\n * @param span span to add attributes to\n * @param ns mongodb namespace\n * @param topology mongodb internal representation of the network topology\n * @param command mongodb internal representation of a command\n */\n private _populateV3Attributes(\n span: Span,\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined\n ) {\n // add network attributes to determine the remote server\n let host: undefined | string;\n let port: undefined | string;\n if (topology && topology.s) {\n host = topology.s.options?.host ?? topology.s.host;\n port = (topology.s.options?.port ?? topology.s.port)?.toString();\n if (host == null || port == null) {\n const address = topology.description?.address;\n if (address) {\n const addressSegments = address.split(':');\n host = addressSegments[0];\n port = addressSegments[1];\n }\n }\n }\n\n // The namespace is a combination of the database name and the name of the\n // collection or index, like so: [database-name].[collection-or-index-name].\n // It could be a string or an instance of MongoDBNamespace, as such we\n // always coerce to a string to extract db and collection.\n const [dbName, dbCollection] = ns.toString().split('.');\n // capture parameters within the query as well if enhancedDatabaseReporting is enabled.\n const commandObj = command?.query ?? command?.q ?? command;\n\n this._addAllSpanAttributes(\n span,\n dbName,\n dbCollection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n private _addAllSpanAttributes(\n span: Span,\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined\n ) {\n // add database related attributes\n span.setAttributes({\n [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MONGODB,\n [SEMATTRS_DB_NAME]: dbName,\n [SEMATTRS_DB_MONGODB_COLLECTION]: dbCollection,\n [SEMATTRS_DB_OPERATION]: operation,\n [SEMATTRS_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n });\n\n if (host && port) {\n span.setAttribute(SEMATTRS_NET_PEER_NAME, host);\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n span.setAttribute(SEMATTRS_NET_PEER_PORT, portNumber);\n }\n }\n if (!commandObj) return;\n const dbStatementSerializer =\n typeof this._config.dbStatementSerializer === 'function'\n ? this._config.dbStatementSerializer\n : this._defaultDbStatementSerializer.bind(this);\n\n safeExecuteInTheMiddle(\n () => {\n const query = dbStatementSerializer(commandObj);\n span.setAttribute(SEMATTRS_DB_STATEMENT, query);\n },\n err => {\n if (err) {\n this._diag.error('Error running dbStatementSerializer hook', err);\n }\n },\n true\n );\n }\n\n private _defaultDbStatementSerializer(commandObj: Record<string, unknown>) {\n const enhancedDbReporting = !!this._config?.enhancedDatabaseReporting;\n const resultObj = enhancedDbReporting\n ? commandObj\n : Object.keys(commandObj).reduce((obj, key) => {\n obj[key] = '?';\n return obj;\n }, {} as { [key: string]: unknown });\n return JSON.stringify(resultObj);\n }\n\n /**\n * Triggers the response hook in case it is defined.\n * @param span The span to add the results to.\n * @param result The command result\n */\n private _handleExecutionResult(span: Span, result: CommandResult) {\n const config: MongoDBInstrumentationConfig = this.getConfig();\n if (typeof config.responseHook === 'function') {\n safeExecuteInTheMiddle(\n () => {\n config.responseHook!(span, { data: result });\n },\n err => {\n if (err) {\n this._diag.error('Error running response hook', err);\n }\n },\n true\n );\n }\n }\n\n /**\n * Ends a created span.\n * @param span The created span to end.\n * @param resultHandler A callback function.\n * @param connectionId: The connection ID of the Command response.\n */\n private _patchEnd(\n span: Span | undefined,\n resultHandler: Function,\n connectionId?: number,\n commandType?: string\n ): Function {\n // mongodb is using \"tick\" when calling a callback, this way the context\n // in final callback (resultHandler) is lost\n const activeContext = context.active();\n const instrumentation = this;\n return function patchedEnd(this: {}, ...args: unknown[]) {\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span?.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n } else {\n const result = args[1] as CommandResult;\n instrumentation._handleExecutionResult(span, result);\n }\n span.end();\n }\n\n return context.with(activeContext, () => {\n if (commandType === 'endSessions') {\n instrumentation._connectionsUsage.add(-1, {\n state: 'idle',\n 'pool.name': instrumentation._poolName,\n });\n }\n return resultHandler.apply(this, args);\n });\n };\n }\n private setPoolName(options: any) {\n const host = options.hostAddress?.host;\n const port = options.hostAddress?.port;\n const database = options.dbName;\n const poolName = `mongodb://${host}:${port}/${database}`;\n this._poolName = poolName;\n }\n}\n"]}
@@ -92,13 +92,17 @@ export declare type Document = {
92
92
  [key: string]: any;
93
93
  };
94
94
  export declare type V4Connection = {
95
- command(ns: any, cmd: Document, options: undefined | unknown, callback: any): void;
95
+ command: Function;
96
+ commandPromise(ns: any, cmd: Document, options: undefined | unknown): Promise<any>;
97
+ commandCallback(ns: any, cmd: Document, options: undefined | unknown, callback: any): void;
96
98
  };
97
99
  export declare type V4ConnectionPool = {
98
100
  checkOut: (callback: (error: any, connection: any) => void) => void;
99
101
  };
100
102
  export declare type V4Connect = {
101
- connect: (options: any, callback: any) => void;
103
+ connect: Function;
104
+ connectPromise: (options: any) => Promise<any>;
105
+ connectCallback: (options: any, callback: any) => void;
102
106
  };
103
107
  export declare type V4Session = {
104
108
  acquire: () => ServerSession;
@@ -1 +1 @@
1
- {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../src/internal-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAqJH,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,sDAAgC,CAAA;IAChC,uDAAiC,CAAA;IACjC,4CAAsB,CAAA;IACtB,qCAAe,CAAA;IACf,yCAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAM7B","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\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { Span } from '@opentelemetry/api';\n\nexport interface MongoDBInstrumentationExecutionResponseHook {\n (span: Span, responseInfo: MongoResponseHookInformation): void;\n}\n\n/**\n * Function that can be used to serialize db.statement tag\n * @param cmd - MongoDB command object\n *\n * @returns serialized string that will be used as the db.statement attribute.\n */\nexport type DbStatementSerializer = (cmd: Record<string, unknown>) => string;\n\nexport interface MongoDBInstrumentationConfig extends InstrumentationConfig {\n /**\n * If true, additional information about query parameters and\n * results will be attached (as `attributes`) to spans representing\n * database operations.\n */\n enhancedDatabaseReporting?: boolean;\n\n /**\n * Hook that allows adding custom span attributes based on the data\n * returned from MongoDB actions.\n *\n * @default undefined\n */\n responseHook?: MongoDBInstrumentationExecutionResponseHook;\n\n /**\n * Custom serializer function for the db.statement tag\n */\n dbStatementSerializer?: DbStatementSerializer;\n}\n\nexport type Func<T> = (...args: unknown[]) => T;\nexport type MongoInternalCommand = {\n findandmodify: boolean;\n createIndexes: boolean;\n count: boolean;\n ismaster: boolean;\n indexes?: unknown[];\n query?: Record<string, unknown>;\n limit?: number;\n q?: Record<string, unknown>;\n u?: Record<string, unknown>;\n};\n\nexport type ServerSession = {\n id: any;\n lastUse: number;\n txnNumber: number;\n isDirty: boolean;\n};\n\nexport type CursorState = { cmd: MongoInternalCommand } & Record<\n string,\n unknown\n>;\n\nexport interface MongoResponseHookInformation {\n data: CommandResult;\n}\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/core/connection/command_result.js\nexport type CommandResult = {\n result?: unknown;\n connection?: unknown;\n message?: unknown;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/core/wireprotocol/index.js\nexport type WireProtocolInternal = {\n insert: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n update: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n remove: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n killCursors: (\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n callback: Function\n ) => unknown;\n getMore: (\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n batchSize: number,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n query: (\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n cursorState: CursorState,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n command: (\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/topologies/server.js#L172\n// https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/server.js#L174\nexport type MongoInternalTopology = {\n s?: {\n // those are for mongodb@3\n options?: {\n host?: string;\n port?: number;\n servername?: string;\n };\n // those are for mongodb@2\n host?: string;\n port?: number;\n };\n // mongodb@3 with useUnifiedTopology option\n description?: {\n address?: string;\n };\n};\n\nexport enum MongodbCommandType {\n CREATE_INDEXES = 'createIndexes',\n FIND_AND_MODIFY = 'findAndModify',\n IS_MASTER = 'isMaster',\n COUNT = 'count',\n UNKNOWN = 'unknown',\n}\n\n// https://github.com/mongodb/js-bson/blob/main/src/bson.ts\nexport type Document = {\n [key: string]: any;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connection.ts\nexport type V4Connection = {\n command(\n ns: any,\n cmd: Document,\n options: undefined | unknown,\n callback: any\n ): void;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connection_pool.ts\nexport type V4ConnectionPool = {\n // Instrumentation just cares about carrying the async context so\n // types of callback params are not needed\n checkOut: (callback: (error: any, connection: any) => void) => void;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connect.ts\nexport type V4Connect = {\n connect: (options: any, callback: any) => void;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/sessions.ts\nexport type V4Session = {\n acquire: () => ServerSession;\n release: (session: ServerSession) => void;\n};\n"]}
1
+ {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../src/internal-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAqJH,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,sDAAgC,CAAA;IAChC,uDAAiC,CAAA;IACjC,4CAAsB,CAAA;IACtB,qCAAe,CAAA;IACf,yCAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAM7B","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\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { Span } from '@opentelemetry/api';\n\nexport interface MongoDBInstrumentationExecutionResponseHook {\n (span: Span, responseInfo: MongoResponseHookInformation): void;\n}\n\n/**\n * Function that can be used to serialize db.statement tag\n * @param cmd - MongoDB command object\n *\n * @returns serialized string that will be used as the db.statement attribute.\n */\nexport type DbStatementSerializer = (cmd: Record<string, unknown>) => string;\n\nexport interface MongoDBInstrumentationConfig extends InstrumentationConfig {\n /**\n * If true, additional information about query parameters and\n * results will be attached (as `attributes`) to spans representing\n * database operations.\n */\n enhancedDatabaseReporting?: boolean;\n\n /**\n * Hook that allows adding custom span attributes based on the data\n * returned from MongoDB actions.\n *\n * @default undefined\n */\n responseHook?: MongoDBInstrumentationExecutionResponseHook;\n\n /**\n * Custom serializer function for the db.statement tag\n */\n dbStatementSerializer?: DbStatementSerializer;\n}\n\nexport type Func<T> = (...args: unknown[]) => T;\nexport type MongoInternalCommand = {\n findandmodify: boolean;\n createIndexes: boolean;\n count: boolean;\n ismaster: boolean;\n indexes?: unknown[];\n query?: Record<string, unknown>;\n limit?: number;\n q?: Record<string, unknown>;\n u?: Record<string, unknown>;\n};\n\nexport type ServerSession = {\n id: any;\n lastUse: number;\n txnNumber: number;\n isDirty: boolean;\n};\n\nexport type CursorState = { cmd: MongoInternalCommand } & Record<\n string,\n unknown\n>;\n\nexport interface MongoResponseHookInformation {\n data: CommandResult;\n}\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/core/connection/command_result.js\nexport type CommandResult = {\n result?: unknown;\n connection?: unknown;\n message?: unknown;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/core/wireprotocol/index.js\nexport type WireProtocolInternal = {\n insert: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n update: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n remove: (\n server: MongoInternalTopology,\n ns: string,\n ops: unknown[],\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n killCursors: (\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n callback: Function\n ) => unknown;\n getMore: (\n server: MongoInternalTopology,\n ns: string,\n cursorState: CursorState,\n batchSize: number,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n query: (\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n cursorState: CursorState,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n command: (\n server: MongoInternalTopology,\n ns: string,\n cmd: MongoInternalCommand,\n options: unknown | Function,\n callback?: Function\n ) => unknown;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/3.6/lib/topologies/server.js#L172\n// https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/server.js#L174\nexport type MongoInternalTopology = {\n s?: {\n // those are for mongodb@3\n options?: {\n host?: string;\n port?: number;\n servername?: string;\n };\n // those are for mongodb@2\n host?: string;\n port?: number;\n };\n // mongodb@3 with useUnifiedTopology option\n description?: {\n address?: string;\n };\n};\n\nexport enum MongodbCommandType {\n CREATE_INDEXES = 'createIndexes',\n FIND_AND_MODIFY = 'findAndModify',\n IS_MASTER = 'isMaster',\n COUNT = 'count',\n UNKNOWN = 'unknown',\n}\n\n// https://github.com/mongodb/js-bson/blob/main/src/bson.ts\nexport type Document = {\n [key: string]: any;\n};\n\nexport type V4Connection = {\n command: Function;\n // From version 6.4.0 the method does not expect a callback and returns a promise\n // https://github.com/mongodb/node-mongodb-native/blob/v6.4.2/src/cmap/connection.ts\n commandPromise(\n ns: any,\n cmd: Document,\n options: undefined | unknown\n ): Promise<any>;\n // Earlier versions expect a callback param and return void\n // https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connection.ts\n commandCallback(\n ns: any,\n cmd: Document,\n options: undefined | unknown,\n callback: any\n ): void;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connection_pool.ts\nexport type V4ConnectionPool = {\n // Instrumentation just cares about carrying the async context so\n // types of callback params are not needed\n checkOut: (callback: (error: any, connection: any) => void) => void;\n};\n\nexport type V4Connect = {\n connect: Function;\n // From version 6.4.0 the method does not expect a callback and returns a promise\n // https://github.com/mongodb/node-mongodb-native/blob/v6.4.0/src/cmap/connect.ts\n connectPromise: (options: any) => Promise<any>;\n // Earlier versions expect a callback param and return void\n // https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/cmap/connect.ts\n connectCallback: (options: any, callback: any) => void;\n};\n\n// https://github.com/mongodb/node-mongodb-native/blob/v4.2.2/src/sessions.ts\nexport type V4Session = {\n acquire: () => ServerSession;\n release: (session: ServerSession) => void;\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.41.0";
1
+ export declare const VERSION = "0.43.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.41.0';
20
+ exports.VERSION = '0.43.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.41.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.43.0';\n"]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-mongodb",
3
- "version": "0.41.0",
3
+ "version": "0.43.0",
4
4
  "description": "OpenTelemetry mongodb automatic instrumentation package.",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
7
7
  "repository": "open-telemetry/opentelemetry-js-contrib",
8
8
  "scripts": {
9
9
  "docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
10
- "test": "npm run test-v3",
10
+ "test": "npm run test-v5-v6",
11
11
  "test-v3": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
12
12
  "test-v4": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
13
13
  "test-v5-v6": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
@@ -50,7 +50,7 @@
50
50
  "devDependencies": {
51
51
  "@opentelemetry/api": "^1.3.0",
52
52
  "@opentelemetry/context-async-hooks": "^1.8.0",
53
- "@opentelemetry/contrib-test-utils": "^0.37.0",
53
+ "@opentelemetry/contrib-test-utils": "^0.39.0",
54
54
  "@opentelemetry/sdk-trace-base": "^1.8.0",
55
55
  "@opentelemetry/sdk-trace-node": "^1.8.0",
56
56
  "@types/bson": "4.0.5",
@@ -58,7 +58,7 @@
58
58
  "@types/mongodb": "3.6.20",
59
59
  "@types/node": "18.6.5",
60
60
  "mocha": "7.2.0",
61
- "mongodb": "3.6.11",
61
+ "mongodb": "6.5.0",
62
62
  "nyc": "15.1.0",
63
63
  "rimraf": "5.0.5",
64
64
  "test-all-versions": "6.1.0",
@@ -66,10 +66,10 @@
66
66
  "typescript": "4.4.4"
67
67
  },
68
68
  "dependencies": {
69
- "@opentelemetry/instrumentation": "^0.49.1",
69
+ "@opentelemetry/instrumentation": "^0.51.0",
70
70
  "@opentelemetry/sdk-metrics": "^1.9.1",
71
- "@opentelemetry/semantic-conventions": "^1.0.0"
71
+ "@opentelemetry/semantic-conventions": "^1.22.0"
72
72
  },
73
73
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme",
74
- "gitHead": "9d19ca4103bc72bd42e28979fee19bd08d85b721"
74
+ "gitHead": "96a87b48934f0afcf1fe637eed6704f35bd8e973"
75
75
  }