@opentelemetry/instrumentation-mongodb 0.61.0 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-mongodb
17
17
 
18
18
  ### Supported Versions
19
19
 
20
- - [`mongodb`](https://www.npmjs.com/package/mongodb) version `>=3.3.0 <7`
20
+ - [`mongodb`](https://www.npmjs.com/package/mongodb) version `>=3.3.0 <8`
21
21
 
22
22
  ## Usage
23
23
 
@@ -49,28 +49,44 @@ See [`examples/mongodb`](https://github.com/open-telemetry/opentelemetry-js-cont
49
49
 
50
50
  Mongodb instrumentation has few options available to choose from. You can set the following:
51
51
 
52
- | Options | Type | Description |
53
- | ------- | ---- | ----------- |
54
- | [`enhancedDatabaseReporting`](./src/types.ts#L32) | `string` | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations |
55
- | `responseHook` | `MongoDBInstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response |
56
- | `dbStatementSerializer` | `DbStatementSerializer` (function) | Custom serializer function for the db.statement tag |
57
- | `requireParentSpan` | `boolean` | Require a parent span in order to create mongodb spans, default when unset is `true` |
52
+ | Options | Type | Description |
53
+ | --------------------------- | -------- | ----------- |
54
+ | `enhancedDatabaseReporting` | boolean | If true, additional information about query parameters and results will be attached (as `attributes`) to spans representing database operations. |
55
+ | `responseHook` | function | Function for adding custom attributes from db response. See type `MongoDBInstrumentationExecutionResponseHook`. |
56
+ | `dbStatementSerializer` | function | Custom serializer function for the `db.statement` / `db.query.text` span attribute. See type `DbStatementSerializer`. |
57
+ | `requireParentSpan` | boolean | Require a parent span in order to create mongodb spans, default when unset is `true`. |
58
58
 
59
59
  ## Semantic Conventions
60
60
 
61
- 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
+ This instrumentation implements Semantic Conventions (semconv) v1.7.0. Since then, networking (in semconv v1.23.1) and database (in semconv v1.33.0) semantic conventions were stabilized. As of `@opentelemetry/instrumentation-mongodb@0.63.0` support has been added for migrating to the stable semantic conventions using the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable as follows:
62
62
 
63
- Attributes collected:
63
+ 1. Upgrade to the latest version of this instrumentation package.
64
+ 2. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http/dup,database/dup` to emit both old and stable semantic conventions. (The `http` token is used to control the `net.*` attributes, the `database` token to control to `db.*` attributes.)
65
+ 3. Modify alerts, dashboards, metrics, and other processes in your Observability system to use the stable semantic conventions.
66
+ 4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http,database` to emit only the stable semantic conventions.
64
67
 
65
- | Attribute | Short Description |
66
- | ----------------------- | ------------------------------------------------------------------------------ |
67
- | `db.system` | An identifier for the database management system (DBMS) product being used. |
68
- | `db.connection_string` | The connection string used to connect to the database. |
69
- | `db.name` | This attribute is used to report the name of the database being accessed. |
70
- | `db.operation` | The name of the operation being executed. |
71
- | `db.mongodb.collection` | The collection being accessed within the database stated in `db.name`. |
72
- | `net.peer.name` | Remote hostname or similar. |
73
- | `net.peer.port` | Remote port number. |
68
+ By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used.
69
+ The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new database and networking semconv, after which a new minor version will use the new semconv by default and drop support for the old semconv.
70
+ See [the HTTP migration guide](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/) and the [database migration guide](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/) for details.
71
+
72
+ Span attributes:
73
+
74
+ | Old semconv | Stable semconv | Description |
75
+ | ----------------------- | -------------------- | ----------- |
76
+ | `db.system` | `db.system.name` | 'mongodb' |
77
+ | `db.name` | `db.namespace` | The MongoDB database name. |
78
+ | `db.connection_string` | Removed | |
79
+ | `db.operation` | `db.operation.name` | The name of the MongoDB command being executed. |
80
+ | `db.mongodb.collection` | `db.collection.name` | The MongoDB collection being accessed within the database stated in `db.namespace`. |
81
+ | `db.statement` | `db.query.text` | The database query being executed. |
82
+ | `net.peer.name` | `server.address` | Remote hostname or similar. |
83
+ | `net.peer.port` | `server.port` | Remote port number. |
84
+
85
+ Metrics collected:
86
+
87
+ - [`db.client.connections.usage`](https://github.com/open-telemetry/semantic-conventions/blob/v1.24.0/docs/database/database-metrics.md#metric-dbclientconnectionsusage) - The number of connections currently in a given state.
88
+
89
+ Note: While `db.client.connections.usage` has been deprecated in favor of `db.client.connection.count` in the [semconv database migration](https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count), the new metric is still unstable, so cannot be enabled via `OTEL_SEMCONV_STABILITY_OPT_IN=database`. There is ongoing work to provide an opt-in setting to select the latest experimental semconv.
74
90
 
75
91
  ## Useful links
76
92
 
@@ -2,11 +2,20 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opent
2
2
  import { MongoDBInstrumentationConfig } from './types';
3
3
  /** mongodb instrumentation plugin for OpenTelemetry */
4
4
  export declare class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumentationConfig> {
5
+ private _netSemconvStability;
6
+ private _dbSemconvStability;
5
7
  private _connectionsUsage;
6
8
  private _poolName;
7
9
  constructor(config?: MongoDBInstrumentationConfig);
10
+ private _setSemconvStabilityFromEnv;
8
11
  setConfig(config?: MongoDBInstrumentationConfig): void;
9
12
  _updateMetricInstruments(): void;
13
+ /**
14
+ * Convenience function for updating the `db.client.connections.usage` metric.
15
+ * The name "count" comes from the eventual replacement for this metric per
16
+ * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count
17
+ */
18
+ private _connCountAdd;
10
19
  init(): InstrumentationNodeModuleDefinition[];
11
20
  private _getV3ConnectionPatches;
12
21
  private _getV4SessionsPatches;
@@ -34,22 +43,21 @@ export declare class MongoDBInstrumentation extends InstrumentationBase<MongoDBI
34
43
  */
35
44
  private static _getCommandType;
36
45
  /**
37
- * Populate span's attributes by fetching related metadata from the context
38
- * @param span span to add attributes to
46
+ * Determine a span's attributes by fetching related metadata from the context
39
47
  * @param connectionCtx mongodb internal connection context
40
48
  * @param ns mongodb namespace
41
49
  * @param command mongodb internal representation of a command
42
50
  */
43
- private _populateV4Attributes;
51
+ private _getV4SpanAttributes;
44
52
  /**
45
- * Populate span's attributes by fetching related metadata from the context
46
- * @param span span to add attributes to
53
+ * Determine a span's attributes by fetching related metadata from the context
47
54
  * @param ns mongodb namespace
48
55
  * @param topology mongodb internal representation of the network topology
49
56
  * @param command mongodb internal representation of a command
50
57
  */
51
- private _populateV3Attributes;
52
- private _addAllSpanAttributes;
58
+ private _getV3SpanAttributes;
59
+ private _getSpanAttributes;
60
+ private _spanNameFromAttrs;
53
61
  private _getDefaultDbStatementReplacer;
54
62
  private _defaultDbStatementSerializer;
55
63
  /**
@@ -18,6 +18,7 @@ exports.MongoDBInstrumentation = void 0;
18
18
  */
19
19
  const api_1 = require("@opentelemetry/api");
20
20
  const instrumentation_1 = require("@opentelemetry/instrumentation");
21
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
21
22
  const semconv_1 = require("./semconv");
22
23
  const internal_types_1 = require("./internal-types");
23
24
  /** @knipignore */
@@ -27,8 +28,16 @@ const DEFAULT_CONFIG = {
27
28
  };
28
29
  /** mongodb instrumentation plugin for OpenTelemetry */
29
30
  class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
31
+ _netSemconvStability;
32
+ _dbSemconvStability;
30
33
  constructor(config = {}) {
31
34
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config });
35
+ this._setSemconvStabilityFromEnv();
36
+ }
37
+ // Used for testing.
38
+ _setSemconvStabilityFromEnv() {
39
+ this._netSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
40
+ this._dbSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
32
41
  }
33
42
  setConfig(config = {}) {
34
43
  super.setConfig({ ...DEFAULT_CONFIG, ...config });
@@ -39,6 +48,14 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
39
48
  unit: '{connection}',
40
49
  });
41
50
  }
51
+ /**
52
+ * Convenience function for updating the `db.client.connections.usage` metric.
53
+ * The name "count" comes from the eventual replacement for this metric per
54
+ * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count
55
+ */
56
+ _connCountAdd(n, poolName, state) {
57
+ this._connectionsUsage?.add(n, { 'pool.name': poolName, state });
58
+ }
42
59
  init() {
43
60
  const { v3PatchConnection: v3PatchConnection, v3UnpatchConnection: v3UnpatchConnection, } = this._getV3ConnectionPatches();
44
61
  const { v4PatchConnect, v4UnpatchConnect } = this._getV4ConnectPatches();
@@ -49,12 +66,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
49
66
  new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['>=3.3.0 <4'], undefined, undefined, [
50
67
  new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/core/wireprotocol/index.js', ['>=3.3.0 <4'], v3PatchConnection, v3UnpatchConnection),
51
68
  ]),
52
- new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['>=4.0.0 <7'], undefined, undefined, [
69
+ new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['>=4.0.0 <8'], undefined, undefined, [
53
70
  new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['>=4.0.0 <6.4'], v4PatchConnectionCallback, v4UnpatchConnection),
54
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['>=6.4.0 <7'], v4PatchConnectionPromise, v4UnpatchConnection),
71
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['>=6.4.0 <8'], v4PatchConnectionPromise, v4UnpatchConnection),
55
72
  new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection_pool.js', ['>=4.0.0 <6.4'], v4PatchConnectionPool, v4UnpatchConnectionPool),
56
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['>=4.0.0 <7'], v4PatchConnect, v4UnpatchConnect),
57
- new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['>=4.0.0 <7'], v4PatchSessions, v4UnpatchSessions),
73
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['>=4.0.0 <8'], v4PatchConnect, v4UnpatchConnect),
74
+ new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['>=4.0.0 <8'], v4PatchSessions, v4UnpatchSessions),
58
75
  ]),
59
76
  ];
60
77
  }
@@ -139,21 +156,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
139
156
  const nSessionsAfterAcquire = this.sessions.length;
140
157
  if (nSessionsBeforeAcquire === nSessionsAfterAcquire) {
141
158
  //no session in the pool. a new session was created and used
142
- instrumentation._connectionsUsage.add(1, {
143
- state: 'used',
144
- 'pool.name': instrumentation._poolName,
145
- });
159
+ instrumentation._connCountAdd(1, instrumentation._poolName, 'used');
146
160
  }
147
161
  else if (nSessionsBeforeAcquire - 1 === nSessionsAfterAcquire) {
148
162
  //a session was already in the pool. remove it from the pool and use it.
149
- instrumentation._connectionsUsage.add(-1, {
150
- state: 'idle',
151
- 'pool.name': instrumentation._poolName,
152
- });
153
- instrumentation._connectionsUsage.add(1, {
154
- state: 'used',
155
- 'pool.name': instrumentation._poolName,
156
- });
163
+ instrumentation._connCountAdd(-1, instrumentation._poolName, 'idle');
164
+ instrumentation._connCountAdd(1, instrumentation._poolName, 'used');
157
165
  }
158
166
  return session;
159
167
  };
@@ -164,14 +172,8 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
164
172
  return (original) => {
165
173
  return function patchRelease(session) {
166
174
  const cmdPromise = original.call(this, session);
167
- instrumentation._connectionsUsage.add(-1, {
168
- state: 'used',
169
- 'pool.name': instrumentation._poolName,
170
- });
171
- instrumentation._connectionsUsage.add(1, {
172
- state: 'idle',
173
- 'pool.name': instrumentation._poolName,
174
- });
175
+ instrumentation._connCountAdd(-1, instrumentation._poolName, 'used');
176
+ instrumentation._connCountAdd(1, instrumentation._poolName, 'idle');
175
177
  return cmdPromise;
176
178
  };
177
179
  };
@@ -291,12 +293,14 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
291
293
  return original.call(this, server, ns, ops, options, callback);
292
294
  }
293
295
  }
294
- const span = instrumentation.tracer.startSpan(`mongodb.${operationName}`, {
295
- kind: api_1.SpanKind.CLIENT,
296
- });
297
- instrumentation._populateV3Attributes(span, ns, server,
296
+ const attributes = instrumentation._getV3SpanAttributes(ns, server,
298
297
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
298
  ops[0], operationName);
299
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
300
+ const span = instrumentation.tracer.startSpan(spanName, {
301
+ kind: api_1.SpanKind.CLIENT,
302
+ attributes,
303
+ });
300
304
  const patchedCallback = instrumentation._patchEnd(span, resultHandler);
301
305
  // handle when options is the callback to send the correct number of args
302
306
  if (typeof options === 'function') {
@@ -327,12 +331,13 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
327
331
  }
328
332
  }
329
333
  const commandType = MongoDBInstrumentation._getCommandType(cmd);
330
- const type = commandType === internal_types_1.MongodbCommandType.UNKNOWN ? 'command' : commandType;
331
- const span = instrumentation.tracer.startSpan(`mongodb.${type}`, {
334
+ const operationName = commandType === internal_types_1.MongodbCommandType.UNKNOWN ? undefined : commandType;
335
+ const attributes = instrumentation._getV3SpanAttributes(ns, server, cmd, operationName);
336
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
337
+ const span = instrumentation.tracer.startSpan(spanName, {
332
338
  kind: api_1.SpanKind.CLIENT,
339
+ attributes,
333
340
  });
334
- const operation = commandType === internal_types_1.MongodbCommandType.UNKNOWN ? undefined : commandType;
335
- instrumentation._populateV3Attributes(span, ns, server, cmd, operation);
336
341
  const patchedCallback = instrumentation._patchEnd(span, resultHandler);
337
342
  // handle when options is the callback to send the correct number of args
338
343
  if (typeof options === 'function') {
@@ -358,10 +363,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
358
363
  }
359
364
  let span = undefined;
360
365
  if (!skipInstrumentation) {
361
- span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {
366
+ const attributes = instrumentation._getV4SpanAttributes(this, ns, cmd, commandType);
367
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
368
+ span = instrumentation.tracer.startSpan(spanName, {
362
369
  kind: api_1.SpanKind.CLIENT,
370
+ attributes,
363
371
  });
364
- instrumentation._populateV4Attributes(span, this, ns, cmd, commandType);
365
372
  }
366
373
  const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType);
367
374
  return original.call(this, ns, cmd, options, patchedCallback);
@@ -382,10 +389,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
382
389
  }
383
390
  let span = undefined;
384
391
  if (!skipInstrumentation) {
385
- span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, {
392
+ const attributes = instrumentation._getV4SpanAttributes(this, ns, cmd, commandType);
393
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
394
+ span = instrumentation.tracer.startSpan(spanName, {
386
395
  kind: api_1.SpanKind.CLIENT,
396
+ attributes,
387
397
  });
388
- instrumentation._populateV4Attributes(span, this, ns, cmd, commandType);
389
398
  }
390
399
  const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType);
391
400
  const result = original.apply(this, args);
@@ -412,10 +421,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
412
421
  return original.call(this, server, ns, cmd, cursorState, options, callback);
413
422
  }
414
423
  }
415
- const span = instrumentation.tracer.startSpan('mongodb.find', {
424
+ const attributes = instrumentation._getV3SpanAttributes(ns, server, cmd, 'find');
425
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
426
+ const span = instrumentation.tracer.startSpan(spanName, {
416
427
  kind: api_1.SpanKind.CLIENT,
428
+ attributes,
417
429
  });
418
- instrumentation._populateV3Attributes(span, ns, server, cmd, 'find');
419
430
  const patchedCallback = instrumentation._patchEnd(span, resultHandler);
420
431
  // handle when options is the callback to send the correct number of args
421
432
  if (typeof options === 'function') {
@@ -443,10 +454,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
443
454
  return original.call(this, server, ns, cursorState, batchSize, options, callback);
444
455
  }
445
456
  }
446
- const span = instrumentation.tracer.startSpan('mongodb.getMore', {
457
+ const attributes = instrumentation._getV3SpanAttributes(ns, server, cursorState.cmd, 'getMore');
458
+ const spanName = instrumentation._spanNameFromAttrs(attributes);
459
+ const span = instrumentation.tracer.startSpan(spanName, {
447
460
  kind: api_1.SpanKind.CLIENT,
461
+ attributes,
448
462
  });
449
- instrumentation._populateV3Attributes(span, ns, server, cursorState.cmd, 'getMore');
450
463
  const patchedCallback = instrumentation._patchEnd(span, resultHandler);
451
464
  // handle when options is the callback to send the correct number of args
452
465
  if (typeof options === 'function') {
@@ -483,13 +496,12 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
483
496
  }
484
497
  }
485
498
  /**
486
- * Populate span's attributes by fetching related metadata from the context
487
- * @param span span to add attributes to
499
+ * Determine a span's attributes by fetching related metadata from the context
488
500
  * @param connectionCtx mongodb internal connection context
489
501
  * @param ns mongodb namespace
490
502
  * @param command mongodb internal representation of a command
491
503
  */
492
- _populateV4Attributes(span, connectionCtx, ns, command, operation) {
504
+ _getV4SpanAttributes(connectionCtx, ns, command, operation) {
493
505
  let host, port;
494
506
  if (connectionCtx) {
495
507
  const hostParts = typeof connectionCtx.address === 'string'
@@ -511,17 +523,16 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
511
523
  else {
512
524
  commandObj = command;
513
525
  }
514
- this._addAllSpanAttributes(span, ns.db, ns.collection, host, port, commandObj, operation);
526
+ return this._getSpanAttributes(ns.db, ns.collection, host, port, commandObj, operation);
515
527
  }
516
528
  /**
517
- * Populate span's attributes by fetching related metadata from the context
518
- * @param span span to add attributes to
529
+ * Determine a span's attributes by fetching related metadata from the context
519
530
  * @param ns mongodb namespace
520
531
  * @param topology mongodb internal representation of the network topology
521
532
  * @param command mongodb internal representation of a command
522
533
  */
523
- _populateV3Attributes(span, ns, topology, command, operation) {
524
- // add network attributes to determine the remote server
534
+ _getV3SpanAttributes(ns, topology, command, operation) {
535
+ // Extract host/port info.
525
536
  let host;
526
537
  let port;
527
538
  if (topology && topology.s) {
@@ -543,38 +554,78 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
543
554
  const [dbName, dbCollection] = ns.toString().split('.');
544
555
  // capture parameters within the query as well if enhancedDatabaseReporting is enabled.
545
556
  const commandObj = command?.query ?? command?.q ?? command;
546
- this._addAllSpanAttributes(span, dbName, dbCollection, host, port, commandObj, operation);
547
- }
548
- _addAllSpanAttributes(span, dbName, dbCollection, host, port, commandObj, operation) {
549
- // add database related attributes
550
- span.setAttributes({
551
- [semconv_1.ATTR_DB_SYSTEM]: semconv_1.DB_SYSTEM_VALUE_MONGODB,
552
- [semconv_1.ATTR_DB_NAME]: dbName,
553
- [semconv_1.ATTR_DB_MONGODB_COLLECTION]: dbCollection,
554
- [semconv_1.ATTR_DB_OPERATION]: operation,
555
- [semconv_1.ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,
556
- });
557
+ return this._getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation);
558
+ }
559
+ _getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation) {
560
+ const attributes = {};
561
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
562
+ attributes[semconv_1.ATTR_DB_SYSTEM] = semconv_1.DB_SYSTEM_VALUE_MONGODB;
563
+ attributes[semconv_1.ATTR_DB_NAME] = dbName;
564
+ attributes[semconv_1.ATTR_DB_MONGODB_COLLECTION] = dbCollection;
565
+ attributes[semconv_1.ATTR_DB_OPERATION] = operation;
566
+ attributes[semconv_1.ATTR_DB_CONNECTION_STRING] =
567
+ `mongodb://${host}:${port}/${dbName}`;
568
+ }
569
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
570
+ attributes[semantic_conventions_1.ATTR_DB_SYSTEM_NAME] = semconv_1.DB_SYSTEM_NAME_VALUE_MONGODB;
571
+ attributes[semantic_conventions_1.ATTR_DB_NAMESPACE] = dbName;
572
+ attributes[semantic_conventions_1.ATTR_DB_OPERATION_NAME] = operation;
573
+ attributes[semantic_conventions_1.ATTR_DB_COLLECTION_NAME] = dbCollection;
574
+ }
557
575
  if (host && port) {
558
- span.setAttribute(semconv_1.ATTR_NET_PEER_NAME, host);
576
+ if (this._netSemconvStability & instrumentation_1.SemconvStability.OLD) {
577
+ attributes[semconv_1.ATTR_NET_PEER_NAME] = host;
578
+ }
579
+ if (this._netSemconvStability & instrumentation_1.SemconvStability.STABLE) {
580
+ attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS] = host;
581
+ }
559
582
  const portNumber = parseInt(port, 10);
560
583
  if (!isNaN(portNumber)) {
561
- span.setAttribute(semconv_1.ATTR_NET_PEER_PORT, portNumber);
584
+ if (this._netSemconvStability & instrumentation_1.SemconvStability.OLD) {
585
+ attributes[semconv_1.ATTR_NET_PEER_PORT] = portNumber;
586
+ }
587
+ if (this._netSemconvStability & instrumentation_1.SemconvStability.STABLE) {
588
+ attributes[semantic_conventions_1.ATTR_SERVER_PORT] = portNumber;
589
+ }
562
590
  }
563
591
  }
564
- if (!commandObj)
565
- return;
566
- const { dbStatementSerializer: configDbStatementSerializer } = this.getConfig();
567
- const dbStatementSerializer = typeof configDbStatementSerializer === 'function'
568
- ? configDbStatementSerializer
569
- : this._defaultDbStatementSerializer.bind(this);
570
- (0, instrumentation_1.safeExecuteInTheMiddle)(() => {
571
- const query = dbStatementSerializer(commandObj);
572
- span.setAttribute(semconv_1.ATTR_DB_STATEMENT, query);
573
- }, err => {
574
- if (err) {
575
- this._diag.error('Error running dbStatementSerializer hook', err);
576
- }
577
- }, true);
592
+ if (commandObj) {
593
+ const { dbStatementSerializer: configDbStatementSerializer } = this.getConfig();
594
+ const dbStatementSerializer = typeof configDbStatementSerializer === 'function'
595
+ ? configDbStatementSerializer
596
+ : this._defaultDbStatementSerializer.bind(this);
597
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => {
598
+ const query = dbStatementSerializer(commandObj);
599
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
600
+ attributes[semconv_1.ATTR_DB_STATEMENT] = query;
601
+ }
602
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
603
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = query;
604
+ }
605
+ }, err => {
606
+ if (err) {
607
+ this._diag.error('Error running dbStatementSerializer hook', err);
608
+ }
609
+ }, true);
610
+ }
611
+ return attributes;
612
+ }
613
+ _spanNameFromAttrs(attributes) {
614
+ let spanName;
615
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
616
+ // https://opentelemetry.io/docs/specs/semconv/database/database-spans/#name
617
+ spanName =
618
+ [
619
+ attributes[semantic_conventions_1.ATTR_DB_OPERATION_NAME],
620
+ attributes[semantic_conventions_1.ATTR_DB_COLLECTION_NAME],
621
+ ]
622
+ .filter(attr => attr)
623
+ .join(' ') || semconv_1.DB_SYSTEM_NAME_VALUE_MONGODB;
624
+ }
625
+ else {
626
+ spanName = `mongodb.${attributes[semconv_1.ATTR_DB_OPERATION] || 'command'}`;
627
+ }
628
+ return spanName;
578
629
  }
579
630
  _getDefaultDbStatementReplacer() {
580
631
  const seen = new WeakSet();
@@ -624,28 +675,29 @@ class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase {
624
675
  // in final callback (resultHandler) is lost
625
676
  const activeContext = api_1.context.active();
626
677
  const instrumentation = this;
678
+ let spanEnded = false;
627
679
  return function patchedEnd(...args) {
628
- const error = args[0];
629
- if (span) {
630
- if (error instanceof Error) {
631
- span?.setStatus({
632
- code: api_1.SpanStatusCode.ERROR,
633
- message: error.message,
634
- });
680
+ if (!spanEnded) {
681
+ spanEnded = true;
682
+ const error = args[0];
683
+ if (span) {
684
+ if (error instanceof Error) {
685
+ span.setStatus({
686
+ code: api_1.SpanStatusCode.ERROR,
687
+ message: error.message,
688
+ });
689
+ }
690
+ else {
691
+ const result = args[1];
692
+ instrumentation._handleExecutionResult(span, result);
693
+ }
694
+ span.end();
635
695
  }
636
- else {
637
- const result = args[1];
638
- instrumentation._handleExecutionResult(span, result);
696
+ if (commandType === 'endSessions') {
697
+ instrumentation._connCountAdd(-1, instrumentation._poolName, 'idle');
639
698
  }
640
- span.end();
641
699
  }
642
700
  return api_1.context.with(activeContext, () => {
643
- if (commandType === 'endSessions') {
644
- instrumentation._connectionsUsage.add(-1, {
645
- state: 'idle',
646
- 'pool.name': instrumentation._poolName,
647
- });
648
- }
649
701
  return resultHandler.apply(this, args);
650
702
  });
651
703
  };
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAM4B;AAC5B,oEAMwC;AACxC,uCAWmB;AAEnB,qDAW0B;AAE1B,kBAAkB;AAClB,uCAA0D;AAG1D,MAAM,cAAc,GAAiC;IACnD,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,uDAAuD;AACvD,MAAa,sBAAuB,SAAQ,qCAAiD;IAI3F,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAEQ,SAAS,C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AE;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,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,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;IAEO,yBAAyB,CAAC,WAA6B;QAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC;QAC7D,MAAM,eAAe,GAAG,WAAW,KAAK,SAAS,CAAC;QAClD,OAAO,iBAAiB,KAAK,IAAI,IAAI,eAAe,CAAC;IACvD,CAAC;CACF;AA99BD,wDA89BC","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 ATTR_DB_CONNECTION_STRING,\n ATTR_DB_MONGODB_COLLECTION,\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n DB_SYSTEM_VALUE_MONGODB,\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n} from './semconv';\nimport { MongoDBInstrumentationConfig, CommandResult } from './types';\nimport {\n CursorState,\n ServerSession,\n MongodbCommandType,\n MongoInternalCommand,\n MongodbNamespace,\n MongoInternalTopology,\n WireProtocolInternal,\n V4Connection,\n V4ConnectionPool,\n Replacer,\n} from './internal-types';\nimport { V4Connect, V4Session } from './internal-types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport { UpDownCounter } from '@opentelemetry/api';\n\nconst DEFAULT_CONFIG: MongoDBInstrumentationConfig = {\n requireParentSpan: true,\n};\n\n/** mongodb instrumentation plugin for OpenTelemetry */\nexport class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumentationConfig> {\n private declare _connectionsUsage: UpDownCounter;\n private declare _poolName: string;\n\n constructor(config: MongoDBInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config });\n }\n\n override setConfig(config: MongoDBInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n override _updateMetricInstruments() {\n this._connectionsUsage = this.meter.createUpDownCounter(\n METRIC_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.0 <4'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/core/wireprotocol/index.js',\n ['>=3.3.0 <4'],\n v3PatchConnection,\n v3UnpatchConnection\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition(\n 'mongodb',\n ['>=4.0.0 <7'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['>=4.0.0 <6.4'],\n v4PatchConnectionCallback,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['>=6.4.0 <7'],\n v4PatchConnectionPromise,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection_pool.js',\n ['>=4.0.0 <6.4'],\n v4PatchConnectionPool,\n v4UnpatchConnectionPool\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connect.js',\n ['>=4.0.0 <7'],\n v4PatchConnect,\n v4UnpatchConnect\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/sessions.js',\n ['>=4.0.0 <7'],\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n skipInstrumentation ||\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\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (\n skipInstrumentation ||\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\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: MongodbNamespace,\n cmd: any,\n options: undefined | unknown,\n callback: any\n ) {\n const currentSpan = trace.getSpan(context.active());\n const skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n const resultHandler = callback;\n const commandType = Object.keys(cmd)[0];\n\n if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {\n return original.call(this, ns, cmd, options, callback);\n }\n\n let span = undefined;\n if (!skipInstrumentation) {\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 ...args: Parameters<V4Connection['commandPromise']>\n ) {\n const [ns, cmd] = args;\n const currentSpan = trace.getSpan(context.active());\n const skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const commandType = Object.keys(cmd)[0];\n const resultHandler = () => undefined;\n\n if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {\n return original.apply(this, args);\n }\n\n let span = undefined;\n if (!skipInstrumentation) {\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.apply(this, args);\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (\n skipInstrumentation ||\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\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (skipInstrumentation || 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\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 if (command.aggregate !== undefined) {\n return MongodbCommandType.AGGREGATE;\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: MongodbNamespace,\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 [ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,\n [ATTR_DB_NAME]: dbName,\n [ATTR_DB_MONGODB_COLLECTION]: dbCollection,\n [ATTR_DB_OPERATION]: operation,\n [ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n });\n\n if (host && port) {\n span.setAttribute(ATTR_NET_PEER_NAME, host);\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n span.setAttribute(ATTR_NET_PEER_PORT, portNumber);\n }\n }\n if (!commandObj) return;\n\n const { dbStatementSerializer: configDbStatementSerializer } =\n this.getConfig();\n const dbStatementSerializer =\n typeof configDbStatementSerializer === 'function'\n ? configDbStatementSerializer\n : this._defaultDbStatementSerializer.bind(this);\n\n safeExecuteInTheMiddle(\n () => {\n const query = dbStatementSerializer(commandObj);\n span.setAttribute(ATTR_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 _getDefaultDbStatementReplacer(): Replacer {\n const seen = new WeakSet();\n return (_key, value) => {\n // undefined, boolean, number, bigint, string, symbol, function || null\n if (typeof value !== 'object' || !value) return '?';\n\n // objects (including arrays)\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return value;\n };\n }\n\n private _defaultDbStatementSerializer(commandObj: Record<string, unknown>) {\n const { enhancedDatabaseReporting } = this.getConfig();\n\n if (enhancedDatabaseReporting) {\n return JSON.stringify(commandObj);\n }\n\n return JSON.stringify(commandObj, this._getDefaultDbStatementReplacer());\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 { responseHook } = this.getConfig();\n if (typeof responseHook === 'function') {\n safeExecuteInTheMiddle(\n () => {\n 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 private _checkSkipInstrumentation(currentSpan: Span | undefined) {\n const requireParentSpan = this.getConfig().requireParentSpan;\n const hasNoParentSpan = currentSpan === undefined;\n return requireParentSpan === true && hasNoParentSpan;\n }\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,oEAQwC;AACxC,8EAQ6C;AAC7C,uCAYmB;AAEnB,qDAW0B;AAE1B,kBAAkB;AAClB,uCAA0D;AAE1D,MAAM,cAAc,GAAiC;IACnD,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,uDAAuD;AACvD,MAAa,sBAAuB,SAAQ,qCAAiD;IACnF,oBAAoB,CAAoB;IACxC,mBAAmB,CAAoB;IAI/C,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG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CAAC;QAChC,MAAM,QAAQ,GAAG,aAAa,IAAI,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEO,yBAAyB,CAAC,WAA6B;QAC7D,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC;QAC7D,MAAM,eAAe,GAAG,WAAW,KAAK,SAAS,CAAC;QAClD,OAAO,iBAAiB,KAAK,IAAI,IAAI,eAAe,CAAC;IACvD,CAAC;CACF;AA9hCD,wDA8hCC","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 UpDownCounter,\n type Attributes,\n} from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_DB_CONNECTION_STRING,\n ATTR_DB_MONGODB_COLLECTION,\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n DB_SYSTEM_NAME_VALUE_MONGODB,\n DB_SYSTEM_VALUE_MONGODB,\n METRIC_DB_CLIENT_CONNECTIONS_USAGE,\n} from './semconv';\nimport { MongoDBInstrumentationConfig, CommandResult } from './types';\nimport {\n CursorState,\n ServerSession,\n MongodbCommandType,\n MongoInternalCommand,\n MongodbNamespace,\n MongoInternalTopology,\n WireProtocolInternal,\n V4Connection,\n V4ConnectionPool,\n Replacer,\n} from './internal-types';\nimport { V4Connect, V4Session } from './internal-types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst DEFAULT_CONFIG: MongoDBInstrumentationConfig = {\n requireParentSpan: true,\n};\n\n/** mongodb instrumentation plugin for OpenTelemetry */\nexport class MongoDBInstrumentation extends InstrumentationBase<MongoDBInstrumentationConfig> {\n private _netSemconvStability!: SemconvStability;\n private _dbSemconvStability!: SemconvStability;\n declare private _connectionsUsage: UpDownCounter;\n declare private _poolName: string;\n\n constructor(config: MongoDBInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config });\n this._setSemconvStabilityFromEnv();\n }\n\n // Used for testing.\n private _setSemconvStabilityFromEnv() {\n this._netSemconvStability = semconvStabilityFromStr(\n 'http',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n this._dbSemconvStability = semconvStabilityFromStr(\n 'database',\n process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n );\n }\n\n override setConfig(config: MongoDBInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n override _updateMetricInstruments() {\n this._connectionsUsage = this.meter.createUpDownCounter(\n METRIC_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 /**\n * Convenience function for updating the `db.client.connections.usage` metric.\n * The name \"count\" comes from the eventual replacement for this metric per\n * https://opentelemetry.io/docs/specs/semconv/non-normative/db-migration/#database-client-connection-count\n */\n private _connCountAdd(n: number, poolName: string, state: string) {\n this._connectionsUsage?.add(n, { 'pool.name': poolName, state });\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.0 <4'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/core/wireprotocol/index.js',\n ['>=3.3.0 <4'],\n v3PatchConnection,\n v3UnpatchConnection\n ),\n ]\n ),\n new InstrumentationNodeModuleDefinition(\n 'mongodb',\n ['>=4.0.0 <8'],\n undefined,\n undefined,\n [\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['>=4.0.0 <6.4'],\n v4PatchConnectionCallback,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection.js',\n ['>=6.4.0 <8'],\n v4PatchConnectionPromise,\n v4UnpatchConnection\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connection_pool.js',\n ['>=4.0.0 <6.4'],\n v4PatchConnectionPool,\n v4UnpatchConnectionPool\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/cmap/connect.js',\n ['>=4.0.0 <8'],\n v4PatchConnect,\n v4UnpatchConnect\n ),\n new InstrumentationNodeModuleFile(\n 'mongodb/lib/sessions.js',\n ['>=4.0.0 <8'],\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._connCountAdd(1, instrumentation._poolName, 'used');\n } else if (nSessionsBeforeAcquire - 1 === nSessionsAfterAcquire) {\n //a session was already in the pool. remove it from the pool and use it.\n instrumentation._connCountAdd(-1, instrumentation._poolName, 'idle');\n instrumentation._connCountAdd(1, instrumentation._poolName, 'used');\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._connCountAdd(-1, instrumentation._poolName, 'used');\n instrumentation._connCountAdd(1, instrumentation._poolName, 'idle');\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n if (\n skipInstrumentation ||\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\n const attributes = instrumentation._getV3SpanAttributes(\n ns,\n server,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ops[0] as any,\n operationName\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n const span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\n });\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (\n skipInstrumentation ||\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\n const commandType = MongoDBInstrumentation._getCommandType(cmd);\n const operationName =\n commandType === MongodbCommandType.UNKNOWN ? undefined : commandType;\n const attributes = instrumentation._getV3SpanAttributes(\n ns,\n server,\n cmd,\n operationName\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n const span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\n });\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, 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: MongodbNamespace,\n cmd: any,\n options: undefined | unknown,\n callback: any\n ) {\n const currentSpan = trace.getSpan(context.active());\n const skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n const resultHandler = callback;\n const commandType = Object.keys(cmd)[0];\n\n if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {\n return original.call(this, ns, cmd, options, callback);\n }\n\n let span = undefined;\n if (!skipInstrumentation) {\n const attributes = instrumentation._getV4SpanAttributes(\n this,\n ns,\n cmd,\n commandType\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\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 ...args: Parameters<V4Connection['commandPromise']>\n ) {\n const [ns, cmd] = args;\n const currentSpan = trace.getSpan(context.active());\n const skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const commandType = Object.keys(cmd)[0];\n const resultHandler = () => undefined;\n\n if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) {\n return original.apply(this, args);\n }\n\n let span = undefined;\n if (!skipInstrumentation) {\n const attributes = instrumentation._getV4SpanAttributes(\n this,\n ns,\n cmd,\n commandType\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\n });\n }\n\n const patchedCallback = instrumentation._patchEnd(\n span,\n resultHandler,\n this.id,\n commandType\n );\n\n const result = original.apply(this, args);\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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (\n skipInstrumentation ||\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\n const attributes = instrumentation._getV3SpanAttributes(\n ns,\n server,\n cmd,\n 'find'\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n const span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\n });\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 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 skipInstrumentation =\n instrumentation._checkSkipInstrumentation(currentSpan);\n\n const resultHandler =\n typeof options === 'function' ? options : callback;\n\n if (skipInstrumentation || 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\n const attributes = instrumentation._getV3SpanAttributes(\n ns,\n server,\n cursorState.cmd,\n 'getMore'\n );\n const spanName = instrumentation._spanNameFromAttrs(attributes);\n const span = instrumentation.tracer.startSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes,\n });\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 if (command.aggregate !== undefined) {\n return MongodbCommandType.AGGREGATE;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n }\n\n /**\n * Determine a span's attributes by fetching related metadata from the context\n * @param connectionCtx mongodb internal connection context\n * @param ns mongodb namespace\n * @param command mongodb internal representation of a command\n */\n private _getV4SpanAttributes(\n connectionCtx: any,\n ns: MongodbNamespace,\n command?: any,\n operation?: string\n ): Attributes {\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 return this._getSpanAttributes(\n ns.db,\n ns.collection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n /**\n * Determine a span's attributes by fetching related metadata from the context\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 _getV3SpanAttributes(\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined\n ): Attributes {\n // Extract host/port info.\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 return this._getSpanAttributes(\n dbName,\n dbCollection,\n host,\n port,\n commandObj,\n operation\n );\n }\n\n private _getSpanAttributes(\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined\n ): Attributes {\n const attributes: Attributes = {};\n\n if (this._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_SYSTEM] = DB_SYSTEM_VALUE_MONGODB;\n attributes[ATTR_DB_NAME] = dbName;\n attributes[ATTR_DB_MONGODB_COLLECTION] = dbCollection;\n attributes[ATTR_DB_OPERATION] = operation;\n attributes[ATTR_DB_CONNECTION_STRING] =\n `mongodb://${host}:${port}/${dbName}`;\n }\n if (this._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_SYSTEM_NAME] = DB_SYSTEM_NAME_VALUE_MONGODB;\n attributes[ATTR_DB_NAMESPACE] = dbName;\n attributes[ATTR_DB_OPERATION_NAME] = operation;\n attributes[ATTR_DB_COLLECTION_NAME] = dbCollection;\n }\n\n if (host && port) {\n if (this._netSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_NET_PEER_NAME] = host;\n }\n if (this._netSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_SERVER_ADDRESS] = host;\n }\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n if (this._netSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_NET_PEER_PORT] = portNumber;\n }\n if (this._netSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_SERVER_PORT] = portNumber;\n }\n }\n }\n\n if (commandObj) {\n const { dbStatementSerializer: configDbStatementSerializer } =\n this.getConfig();\n const dbStatementSerializer =\n typeof configDbStatementSerializer === 'function'\n ? configDbStatementSerializer\n : this._defaultDbStatementSerializer.bind(this);\n\n safeExecuteInTheMiddle(\n () => {\n const query = dbStatementSerializer(commandObj);\n if (this._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = query;\n }\n if (this._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = query;\n }\n },\n err => {\n if (err) {\n this._diag.error('Error running dbStatementSerializer hook', err);\n }\n },\n true\n );\n }\n\n return attributes;\n }\n\n private _spanNameFromAttrs(attributes: Attributes): string {\n let spanName;\n if (this._dbSemconvStability & SemconvStability.STABLE) {\n // https://opentelemetry.io/docs/specs/semconv/database/database-spans/#name\n spanName =\n [\n attributes[ATTR_DB_OPERATION_NAME],\n attributes[ATTR_DB_COLLECTION_NAME],\n ]\n .filter(attr => attr)\n .join(' ') || DB_SYSTEM_NAME_VALUE_MONGODB;\n } else {\n spanName = `mongodb.${attributes[ATTR_DB_OPERATION] || 'command'}`;\n }\n return spanName;\n }\n\n private _getDefaultDbStatementReplacer(): Replacer {\n const seen = new WeakSet();\n return (_key, value) => {\n // undefined, boolean, number, bigint, string, symbol, function || null\n if (typeof value !== 'object' || !value) return '?';\n\n // objects (including arrays)\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return value;\n };\n }\n\n private _defaultDbStatementSerializer(commandObj: Record<string, unknown>) {\n const { enhancedDatabaseReporting } = this.getConfig();\n\n if (enhancedDatabaseReporting) {\n return JSON.stringify(commandObj);\n }\n\n return JSON.stringify(commandObj, this._getDefaultDbStatementReplacer());\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 { responseHook } = this.getConfig();\n if (typeof responseHook === 'function') {\n safeExecuteInTheMiddle(\n () => {\n 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 let spanEnded = false;\n\n return function patchedEnd(this: {}, ...args: unknown[]) {\n if (!spanEnded) {\n spanEnded = true;\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 if (commandType === 'endSessions') {\n instrumentation._connCountAdd(-1, instrumentation._poolName, 'idle');\n }\n }\n\n return context.with(activeContext, () => {\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 private _checkSkipInstrumentation(currentSpan: Span | undefined) {\n const requireParentSpan = this.getConfig().requireParentSpan;\n const hasNoParentSpan = currentSpan === undefined;\n return requireParentSpan === true && hasNoParentSpan;\n }\n}\n"]}
@@ -80,6 +80,14 @@ export declare const ATTR_NET_PEER_NAME: "net.peer.name";
80
80
  * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
81
81
  */
82
82
  export declare const ATTR_NET_PEER_PORT: "net.peer.port";
83
+ /**
84
+ * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM_NAME}.
85
+ *
86
+ * [MongoDB](https://www.mongodb.com/)
87
+ *
88
+ * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
89
+ */
90
+ export declare const DB_SYSTEM_NAME_VALUE_MONGODB: "mongodb";
83
91
  /**
84
92
  * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM}.
85
93
  *
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.METRIC_DB_CLIENT_CONNECTIONS_USAGE = exports.DB_SYSTEM_VALUE_MONGODB = exports.ATTR_NET_PEER_PORT = exports.ATTR_NET_PEER_NAME = exports.ATTR_DB_SYSTEM = exports.ATTR_DB_STATEMENT = exports.ATTR_DB_OPERATION = exports.ATTR_DB_NAME = exports.ATTR_DB_MONGODB_COLLECTION = exports.ATTR_DB_CONNECTION_STRING = void 0;
18
+ exports.METRIC_DB_CLIENT_CONNECTIONS_USAGE = exports.DB_SYSTEM_VALUE_MONGODB = exports.DB_SYSTEM_NAME_VALUE_MONGODB = exports.ATTR_NET_PEER_PORT = exports.ATTR_NET_PEER_NAME = exports.ATTR_DB_SYSTEM = exports.ATTR_DB_STATEMENT = exports.ATTR_DB_OPERATION = exports.ATTR_DB_NAME = exports.ATTR_DB_MONGODB_COLLECTION = exports.ATTR_DB_CONNECTION_STRING = void 0;
19
19
  /*
20
20
  * This file contains a copy of unstable semantic convention definitions
21
21
  * used by this package.
@@ -103,6 +103,14 @@ exports.ATTR_NET_PEER_NAME = 'net.peer.name';
103
103
  * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
104
104
  */
105
105
  exports.ATTR_NET_PEER_PORT = 'net.peer.port';
106
+ /**
107
+ * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM_NAME}.
108
+ *
109
+ * [MongoDB](https://www.mongodb.com/)
110
+ *
111
+ * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
112
+ */
113
+ exports.DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb';
106
114
  /**
107
115
  * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM}.
108
116
  *
@@ -1 +1 @@
1
- {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;;;GAQG;AACU,QAAA,0BAA0B,GAAG,uBAAgC,CAAC;AAE3E;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,SAAkB,CAAC;AAE/C;;;;;;;;;;GAUG;AACU,QAAA,iBAAiB,GAAG,cAAuB,CAAC;AAEzD;;;;;;;;;GASG;AACU,QAAA,iBAAiB,GAAG,cAAuB,CAAC;AAEzD;;;;;;GAMG;AACU,QAAA,cAAc,GAAG,WAAoB,CAAC;AAEnD;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG,SAAkB,CAAC;AAE1D;;;;;;GAMG;AACU,QAAA,kCAAkC,GAC7C,6BAAsC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use `server.address`, `server.port` attributes instead.\n *\n * @example \"Server=(localdb)\\\\v11.0;Integrated Security=true;\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.address` and `server.port`.\n */\nexport const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;\n\n/**\n * Deprecated, use `db.collection.name` instead.\n *\n * @example \"mytable\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.collection.name`.\n */\nexport const ATTR_DB_MONGODB_COLLECTION = 'db.mongodb.collection' as const;\n\n/**\n * Deprecated, use `db.namespace` instead.\n *\n * @example customers\n * @example main\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.namespace`.\n */\nexport const ATTR_DB_NAME = 'db.name' as const;\n\n/**\n * Deprecated, use `db.operation.name` instead.\n *\n * @example findAndModify\n * @example HMSET\n * @example SELECT\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.operation.name`.\n */\nexport const ATTR_DB_OPERATION = 'db.operation' as const;\n\n/**\n * The database statement being executed.\n *\n * @example SELECT * FROM wuser_table\n * @example SET mykey \"WuValue\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.query.text`.\n */\nexport const ATTR_DB_STATEMENT = 'db.statement' as const;\n\n/**\n * Deprecated, use `db.system.name` instead.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.system.name`.\n */\nexport const ATTR_DB_SYSTEM = 'db.system' as const;\n\n/**\n * Deprecated, use `server.address` on client spans and `client.address` on server spans.\n *\n * @example example.com\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.\n */\nexport const ATTR_NET_PEER_NAME = 'net.peer.name' as const;\n\n/**\n * Deprecated, use `server.port` on client spans and `client.port` on server spans.\n *\n * @example 8080\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.\n */\nexport const ATTR_NET_PEER_PORT = 'net.peer.port' as const;\n\n/**\n * Enum value \"mongodb\" for attribute {@link ATTR_DB_SYSTEM}.\n *\n * MongoDB\n *\n * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const DB_SYSTEM_VALUE_MONGODB = 'mongodb' as const;\n\n/**\n * Deprecated, use `db.client.connection.count` instead.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.client.connection.count`.\n */\nexport const METRIC_DB_CLIENT_CONNECTIONS_USAGE =\n 'db.client.connections.usage' as const;\n"]}
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;;;GAQG;AACU,QAAA,0BAA0B,GAAG,uBAAgC,CAAC;AAE3E;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,SAAkB,CAAC;AAE/C;;;;;;;;;;GAUG;AACU,QAAA,iBAAiB,GAAG,cAAuB,CAAC;AAEzD;;;;;;;;;GASG;AACU,QAAA,iBAAiB,GAAG,cAAuB,CAAC;AAEzD;;;;;;GAMG;AACU,QAAA,cAAc,GAAG,WAAoB,CAAC;AAEnD;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;GAMG;AACU,QAAA,4BAA4B,GAAG,SAAkB,CAAC;AAE/D;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG,SAAkB,CAAC;AAE1D;;;;;;GAMG;AACU,QAAA,kCAAkC,GAC7C,6BAAsC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use `server.address`, `server.port` attributes instead.\n *\n * @example \"Server=(localdb)\\\\v11.0;Integrated Security=true;\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.address` and `server.port`.\n */\nexport const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;\n\n/**\n * Deprecated, use `db.collection.name` instead.\n *\n * @example \"mytable\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.collection.name`.\n */\nexport const ATTR_DB_MONGODB_COLLECTION = 'db.mongodb.collection' as const;\n\n/**\n * Deprecated, use `db.namespace` instead.\n *\n * @example customers\n * @example main\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.namespace`.\n */\nexport const ATTR_DB_NAME = 'db.name' as const;\n\n/**\n * Deprecated, use `db.operation.name` instead.\n *\n * @example findAndModify\n * @example HMSET\n * @example SELECT\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.operation.name`.\n */\nexport const ATTR_DB_OPERATION = 'db.operation' as const;\n\n/**\n * The database statement being executed.\n *\n * @example SELECT * FROM wuser_table\n * @example SET mykey \"WuValue\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.query.text`.\n */\nexport const ATTR_DB_STATEMENT = 'db.statement' as const;\n\n/**\n * Deprecated, use `db.system.name` instead.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.system.name`.\n */\nexport const ATTR_DB_SYSTEM = 'db.system' as const;\n\n/**\n * Deprecated, use `server.address` on client spans and `client.address` on server spans.\n *\n * @example example.com\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.\n */\nexport const ATTR_NET_PEER_NAME = 'net.peer.name' as const;\n\n/**\n * Deprecated, use `server.port` on client spans and `client.port` on server spans.\n *\n * @example 8080\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.\n */\nexport const ATTR_NET_PEER_PORT = 'net.peer.port' as const;\n\n/**\n * Enum value \"mongodb\" for attribute {@link ATTR_DB_SYSTEM_NAME}.\n *\n * [MongoDB](https://www.mongodb.com/)\n *\n * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb' as const;\n\n/**\n * Enum value \"mongodb\" for attribute {@link ATTR_DB_SYSTEM}.\n *\n * MongoDB\n *\n * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const DB_SYSTEM_VALUE_MONGODB = 'mongodb' as const;\n\n/**\n * Deprecated, use `db.client.connection.count` instead.\n *\n * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `db.client.connection.count`.\n */\nexport const METRIC_DB_CLIENT_CONNECTIONS_USAGE =\n 'db.client.connections.usage' as const;\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.61.0";
1
+ export declare const PACKAGE_VERSION = "0.63.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-mongodb";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.61.0';
20
+ exports.PACKAGE_VERSION = '0.63.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mongodb';
22
22
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.61.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mongodb';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.63.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mongodb';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-mongodb",
3
- "version": "0.61.0",
3
+ "version": "0.63.0",
4
4
  "description": "OpenTelemetry instrumentation for `mongodb` database client for MongoDB",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -16,12 +16,13 @@
16
16
  "compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-mongodb",
17
17
  "compile": "tsc -p .",
18
18
  "prepublishOnly": "npm run compile",
19
- "tdd": "npm run test-v5-v6-run -- --watch-extensions ts --watch",
20
- "test": "npm run test-v5-v6 && npm run test-unit",
21
- "test-unit": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/unit/*.test.ts'",
22
- "test-v3": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
23
- "test-v4": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
24
- "test-v5-v6": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
19
+ "test": "npm run test-v6 && npm run test-unit",
20
+ "test-unit": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/unit/*.test.ts",
21
+ "test-v3": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/mongodb-v3.test.ts",
22
+ "test-v4": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/mongodb-metrics-v4plus.test.ts test/mongodb-v4.test.ts",
23
+ "test-v5": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/mongodb-metrics-v4plus.test.ts test/mongodb-v5plus.test.ts",
24
+ "test-v6": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/mongodb-metrics-v4plus.test.ts test/mongodb-v5plus.test.ts",
25
+ "test-v7": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' test/mongodb-metrics-v4plus.test.ts test/mongodb-v5plus.test.ts",
25
26
  "test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
26
27
  "test-all-versions": "tav",
27
28
  "test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions",
@@ -56,23 +57,17 @@
56
57
  "devDependencies": {
57
58
  "@opentelemetry/api": "^1.3.0",
58
59
  "@opentelemetry/context-async-hooks": "^2.0.0",
59
- "@opentelemetry/contrib-test-utils": "^0.55.0",
60
+ "@opentelemetry/contrib-test-utils": "^0.57.0",
60
61
  "@opentelemetry/sdk-metrics": "^2.0.0",
61
62
  "@opentelemetry/sdk-trace-base": "^2.0.0",
62
63
  "@opentelemetry/sdk-trace-node": "^2.0.0",
63
64
  "@types/bson": "4.0.5",
64
- "@types/mocha": "10.0.10",
65
- "@types/node": "18.18.14",
66
- "cross-env": "7.0.3",
67
- "mongodb": "6.19.0",
68
- "nyc": "17.1.0",
69
- "rimraf": "5.0.10",
70
- "test-all-versions": "6.1.0",
71
- "typescript": "5.0.4"
65
+ "mongodb": "6.19.0"
72
66
  },
73
67
  "dependencies": {
74
- "@opentelemetry/instrumentation": "^0.208.0"
68
+ "@opentelemetry/instrumentation": "^0.210.0",
69
+ "@opentelemetry/semantic-conventions": "^1.33.0"
75
70
  },
76
71
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mongodb#readme",
77
- "gitHead": "94e5b7da4500459e38e8d4dfda93542f22159600"
72
+ "gitHead": "c84212cca7f010b80747cccb9942474e0459df6e"
78
73
  }