@opentelemetry/instrumentation-mongoose 0.55.0 → 0.56.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
@@ -40,20 +40,34 @@ registerInstrumentations({
40
40
 
41
41
  ## Semantic Conventions
42
42
 
43
- 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)
43
+ 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-mongoose@0.44.0` support has been added for migrating to the stable semantic conventions using the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable as follows:
44
+
45
+ 1. Upgrade to the latest version of this instrumentation package.
46
+ 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 the `db.*` attributes.)
47
+ 3. Modify alerts, dashboards, metrics, and other processes in your Observability system to use the stable semantic conventions.
48
+ 4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=http,database` to emit only the stable semantic conventions.
49
+
50
+ By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used.
51
+ 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.
52
+ 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.
44
53
 
45
54
  Attributes collected:
46
55
 
47
- | Attribute | Short Description |
48
- | ----------------------- | --------------------------------------------------------------------------- |
49
- | `db.mongodb.collection` | The collection being accessed within the database stated in `db.name`. |
50
- | `db.name` | This attribute is used to report the name of the database being accessed. |
51
- | `db.operation` | The name of the operation being executed, or the SQL keyword. |
52
- | `db.statement` | The database statement being executed. |
53
- | `db.system` | An identifier for the database management system (DBMS) product being used. |
54
- | `db.user` | Username for accessing the database. |
55
- | `net.peer.name` | Remote hostname or similar. |
56
- | `net.peer.port` | Remote port number. |
56
+ | Old semconv | Stable semconv | Description |
57
+ | ----------------------- | -------------------- | -------------------------------------------------------------------------------------------- |
58
+ | `db.system` | `db.system.name` | An identifier for the database management system (DBMS) product being used. Value: 'mongodb' |
59
+ | `db.mongodb.collection` | `db.collection.name` | The collection being accessed within the database stated in `db.name`. |
60
+ | `db.name` | `db.namespace` | This attribute is used to report the name of the database being accessed. |
61
+ | `db.operation` | `db.operation.name` | The name of the operation being executed. |
62
+ | `db.statement` | `db.query.text` | The database statement being executed. |
63
+ | `db.user` | Removed | Username for accessing the database. |
64
+ | `net.peer.name` | `server.address` | Remote hostname or similar. |
65
+ | `net.peer.port` | `server.port` | Remote port number. |
66
+
67
+ Span name format:
68
+
69
+ - Old: `mongoose.{modelName}.{operation}` (e.g., `mongoose.User.save`)
70
+ - Stable: `{operation} {collection}` (e.g., `save users`)
57
71
 
58
72
  ## Useful links
59
73
 
@@ -1,14 +1,19 @@
1
1
  import { MongooseInstrumentationConfig } from './types';
2
2
  import { InstrumentationBase, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
3
3
  export declare const _STORED_PARENT_SPAN: unique symbol;
4
+ export declare const _ALREADY_INSTRUMENTED: unique symbol;
4
5
  export declare class MongooseInstrumentation extends InstrumentationBase<MongooseInstrumentationConfig> {
6
+ private _netSemconvStability;
7
+ private _dbSemconvStability;
5
8
  constructor(config?: MongooseInstrumentationConfig);
9
+ private _setSemconvStabilityFromEnv;
6
10
  protected init(): InstrumentationModuleDefinition;
7
11
  private patch;
8
12
  private unpatch;
9
13
  private patchAggregateExec;
10
14
  private patchQueryExec;
11
15
  private patchOnModelMethods;
16
+ private _patchDocumentUpdateMethods;
12
17
  private patchModelStatic;
13
18
  private patchModelAggregate;
14
19
  private patchAndCaptureSpanContext;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongooseInstrumentation = exports._STORED_PARENT_SPAN = void 0;
3
+ exports.MongooseInstrumentation = exports._ALREADY_INSTRUMENTED = exports._STORED_PARENT_SPAN = void 0;
4
4
  /*
5
5
  * Copyright The OpenTelemetry Authors
6
6
  *
@@ -23,6 +23,7 @@ const instrumentation_1 = require("@opentelemetry/instrumentation");
23
23
  /** @knipignore */
24
24
  const version_1 = require("./version");
25
25
  const semconv_1 = require("./semconv");
26
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
26
27
  const contextCaptureFunctionsCommon = [
27
28
  'deleteOne',
28
29
  'deleteMany',
@@ -69,13 +70,35 @@ function instrumentRemove(moduleVersion) {
69
70
  (moduleVersion.startsWith('5.') || moduleVersion.startsWith('6.'))) ||
70
71
  false);
71
72
  }
73
+ /**
74
+ * 8.21.0 changed Document.updateOne/deleteOne so that the Query is not fully built when Query.exec() is called.
75
+ * @param moduleVersion
76
+ */
77
+ function needsDocumentMethodPatch(moduleVersion) {
78
+ if (!moduleVersion || !moduleVersion.startsWith('8.')) {
79
+ return false;
80
+ }
81
+ const minor = parseInt(moduleVersion.split('.')[1], 10);
82
+ return minor >= 21;
83
+ }
72
84
  // when mongoose functions are called, we store the original call context
73
85
  // and then set it as the parent for the spans created by Query/Aggregate exec()
74
86
  // calls. this bypass the unlinked spans issue on thenables await operations.
75
87
  exports._STORED_PARENT_SPAN = Symbol('stored-parent-span');
88
+ // Prevents double-instrumentation when doc.updateOne/deleteOne (Mongoose 8.21.0+)
89
+ // creates a span and returns a Query that also calls exec()
90
+ exports._ALREADY_INSTRUMENTED = Symbol('already-instrumented');
76
91
  class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
92
+ _netSemconvStability;
93
+ _dbSemconvStability;
77
94
  constructor(config = {}) {
78
95
  super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
96
+ this._setSemconvStabilityFromEnv();
97
+ }
98
+ // Used for testing.
99
+ _setSemconvStabilityFromEnv() {
100
+ this._netSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
101
+ this._dbSemconvStability = (0, instrumentation_1.semconvStabilityFromStr)('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);
79
102
  }
80
103
  init() {
81
104
  const module = new instrumentation_1.InstrumentationNodeModuleDefinition('mongoose', ['>=5.9.7 <9'], this.patch.bind(this), this.unpatch.bind(this));
@@ -94,6 +117,22 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
94
117
  if (instrumentRemove(moduleVersion)) {
95
118
  this._wrap(moduleExports.Model.prototype, 'remove', this.patchOnModelMethods('remove', moduleVersion));
96
119
  }
120
+ // Mongoose 8.21.0+ changed Document.updateOne()/deleteOne() so that the Query is not fully built when Query.exec() is called.
121
+ //
122
+ // See https://github.com/Automattic/mongoose/blob/7dbda12dca1bd7adb9e270d7de8ac5229606ce72/lib/document.js#L861.
123
+ // - `this` is a Query object
124
+ // - the update happens in a pre-hook that gets called when Query.exec() is already running.
125
+ // - when we instrument Query.exec(), we don't have access to the options yet as they get set during Query.exec() only.
126
+ //
127
+ // Unfortunately, after Query.exec() is finished, the options are left modified by the library, so just delaying
128
+ // attaching the attributes after the span is done is not an option. Therefore, we patch Model methods
129
+ // and grab the data directly where the user provides it.
130
+ //
131
+ // ref: https://github.com/Automattic/mongoose/pull/15908 (introduced this behavior)
132
+ if (needsDocumentMethodPatch(moduleVersion)) {
133
+ this._wrap(moduleExports.Model.prototype, 'updateOne', this._patchDocumentUpdateMethods('updateOne', moduleVersion));
134
+ this._wrap(moduleExports.Model.prototype, 'deleteOne', this._patchDocumentUpdateMethods('deleteOne', moduleVersion));
135
+ }
97
136
  this._wrap(moduleExports.Query.prototype, 'exec', this.patchQueryExec(moduleVersion));
98
137
  this._wrap(moduleExports.Aggregate.prototype, 'exec', this.patchAggregateExec(moduleVersion));
99
138
  const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);
@@ -116,6 +155,10 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
116
155
  if (instrumentRemove(moduleVersion)) {
117
156
  this._unwrap(moduleExports.Model.prototype, 'remove');
118
157
  }
158
+ if (needsDocumentMethodPatch(moduleVersion)) {
159
+ this._unwrap(moduleExports.Model.prototype, 'updateOne');
160
+ this._unwrap(moduleExports.Model.prototype, 'deleteOne');
161
+ }
119
162
  this._unwrap(moduleExports.Query.prototype, 'exec');
120
163
  this._unwrap(moduleExports.Aggregate.prototype, 'exec');
121
164
  contextCaptureFunctions.forEach((funcName) => {
@@ -137,10 +180,16 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
137
180
  const attributes = {};
138
181
  const { dbStatementSerializer } = self.getConfig();
139
182
  if (dbStatementSerializer) {
140
- attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer('aggregate', {
183
+ const statement = dbStatementSerializer('aggregate', {
141
184
  options: this.options,
142
185
  aggregatePipeline: this._pipeline,
143
186
  });
187
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
188
+ attributes[semconv_1.ATTR_DB_STATEMENT] = statement;
189
+ }
190
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
191
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = statement;
192
+ }
144
193
  }
145
194
  const span = self._startSpan(this._model.collection, this._model?.modelName, 'aggregate', attributes, parentSpan);
146
195
  return self._handleResponse(span, originalAggregate, this, arguments, callback, moduleVersion);
@@ -151,6 +200,10 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
151
200
  const self = this;
152
201
  return (originalExec) => {
153
202
  return function exec(callback) {
203
+ // Skip if already instrumented by document instance method patch
204
+ if (this[exports._ALREADY_INSTRUMENTED]) {
205
+ return originalExec.apply(this, arguments);
206
+ }
154
207
  if (self.getConfig().requireParentSpan &&
155
208
  api_1.trace.getSpan(api_1.context.active()) === undefined) {
156
209
  return originalExec.apply(this, arguments);
@@ -159,12 +212,19 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
159
212
  const attributes = {};
160
213
  const { dbStatementSerializer } = self.getConfig();
161
214
  if (dbStatementSerializer) {
162
- attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(this.op, {
163
- condition: this._conditions,
215
+ const statement = dbStatementSerializer(this.op, {
216
+ // Use public API methods (getFilter/getOptions) for better compatibility
217
+ condition: this.getFilter?.() ?? this._conditions,
164
218
  updates: this._update,
165
- options: this.options,
219
+ options: this.getOptions?.() ?? this.options,
166
220
  fields: this._fields,
167
221
  });
222
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
223
+ attributes[semconv_1.ATTR_DB_STATEMENT] = statement;
224
+ }
225
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
226
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = statement;
227
+ }
168
228
  }
169
229
  const span = self._startSpan(this.mongooseCollection, this.model.modelName, this.op, attributes, parentSpan);
170
230
  return self._handleResponse(span, originalExec, this, arguments, callback, moduleVersion);
@@ -186,7 +246,13 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
186
246
  const attributes = {};
187
247
  const { dbStatementSerializer } = self.getConfig();
188
248
  if (dbStatementSerializer) {
189
- attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(op, serializePayload);
249
+ const statement = dbStatementSerializer(op, serializePayload);
250
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
251
+ attributes[semconv_1.ATTR_DB_STATEMENT] = statement;
252
+ }
253
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
254
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = statement;
255
+ }
190
256
  }
191
257
  const span = self._startSpan(this.constructor.collection, this.constructor.modelName, op, attributes);
192
258
  if (options instanceof Function) {
@@ -197,6 +263,54 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
197
263
  };
198
264
  };
199
265
  }
266
+ // Patch document instance methods (doc.updateOne/deleteOne) for Mongoose 8.21.0+.
267
+ _patchDocumentUpdateMethods(op, moduleVersion) {
268
+ const self = this;
269
+ return (originalMethod) => {
270
+ return function method(update, options, callback) {
271
+ if (self.getConfig().requireParentSpan &&
272
+ api_1.trace.getSpan(api_1.context.active()) === undefined) {
273
+ return originalMethod.apply(this, arguments);
274
+ }
275
+ // determine actual callback since different argument patterns are allowed
276
+ let actualCallback = callback;
277
+ let actualUpdate = update;
278
+ let actualOptions = options;
279
+ if (typeof update === 'function') {
280
+ actualCallback = update;
281
+ actualUpdate = undefined;
282
+ actualOptions = undefined;
283
+ }
284
+ else if (typeof options === 'function') {
285
+ actualCallback = options;
286
+ actualOptions = undefined;
287
+ }
288
+ const attributes = {};
289
+ const dbStatementSerializer = self.getConfig().dbStatementSerializer;
290
+ if (dbStatementSerializer) {
291
+ const statement = dbStatementSerializer(op, {
292
+ // Document instance methods automatically use the document's _id as filter
293
+ condition: { _id: this._id },
294
+ updates: actualUpdate,
295
+ options: actualOptions,
296
+ });
297
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
298
+ attributes[semconv_1.ATTR_DB_STATEMENT] = statement;
299
+ }
300
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
301
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = statement;
302
+ }
303
+ }
304
+ const span = self._startSpan(this.constructor.collection, this.constructor.modelName, op, attributes);
305
+ const result = self._handleResponse(span, originalMethod, this, arguments, actualCallback, moduleVersion);
306
+ // Mark returned Query to prevent double-instrumentation when exec() is eventually called
307
+ if (result && typeof result === 'object') {
308
+ result[exports._ALREADY_INSTRUMENTED] = true;
309
+ }
310
+ return result;
311
+ };
312
+ };
313
+ }
200
314
  patchModelStatic(op, moduleVersion) {
201
315
  const self = this;
202
316
  return (original) => {
@@ -227,7 +341,13 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
227
341
  const attributes = {};
228
342
  const { dbStatementSerializer } = self.getConfig();
229
343
  if (dbStatementSerializer) {
230
- attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(op, serializePayload);
344
+ const statement = dbStatementSerializer(op, serializePayload);
345
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
346
+ attributes[semconv_1.ATTR_DB_STATEMENT] = statement;
347
+ }
348
+ if (self._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
349
+ attributes[semantic_conventions_1.ATTR_DB_QUERY_TEXT] = statement;
350
+ }
231
351
  }
232
352
  const span = self._startSpan(this.collection, this.modelName, op, attributes);
233
353
  return self._handleResponse(span, original, this, arguments, callback, moduleVersion);
@@ -260,14 +380,24 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
260
380
  };
261
381
  }
262
382
  _startSpan(collection, modelName, operation, attributes, parentSpan) {
263
- return this.tracer.startSpan(`mongoose.${modelName}.${operation}`, {
383
+ const finalAttributes = {
384
+ ...attributes,
385
+ ...(0, utils_1.getAttributesFromCollection)(collection, this._dbSemconvStability, this._netSemconvStability),
386
+ };
387
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
388
+ finalAttributes[semconv_1.ATTR_DB_OPERATION] = operation;
389
+ finalAttributes[semconv_1.ATTR_DB_SYSTEM] = 'mongoose'; // keep for backwards compatibility
390
+ }
391
+ if (this._dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
392
+ finalAttributes[semantic_conventions_1.ATTR_DB_OPERATION_NAME] = operation;
393
+ finalAttributes[semantic_conventions_1.ATTR_DB_SYSTEM_NAME] = semconv_1.DB_SYSTEM_NAME_VALUE_MONGODB; // actual db system name
394
+ }
395
+ const spanName = this._dbSemconvStability & instrumentation_1.SemconvStability.STABLE
396
+ ? `${operation} ${collection.name}`
397
+ : `mongoose.${modelName}.${operation}`;
398
+ return this.tracer.startSpan(spanName, {
264
399
  kind: api_1.SpanKind.CLIENT,
265
- attributes: {
266
- ...attributes,
267
- ...(0, utils_1.getAttributesFromCollection)(collection),
268
- [semconv_1.ATTR_DB_OPERATION]: operation,
269
- [semconv_1.ATTR_DB_SYSTEM]: 'mongoose',
270
- },
400
+ attributes: finalAttributes,
271
401
  }, parentSpan ? api_1.trace.setSpan(api_1.context.active(), parentSpan) : undefined);
272
402
  }
273
403
  _handleResponse(span, exec, originalThis, args, callback, moduleVersion = undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"mongoose.js","sourceRoot":"","sources":["../../src/mongoose.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAAgF;AAChF,8CAAsD;AAGtD,mCAIiB;AACjB,oEAIwC;AACxC,kBAAkB;AAClB,uCAA0D;AAC1D,uCAImB;AAEnB,MAAM,6BAA6B,GAAG;IACpC,WAAW;IACX,YAAY;IACZ,MAAM;IACN,SAAS;IACT,wBAAwB;IACxB,gBAAgB;IAChB,UAAU;IACV,OAAO;IACP,QAAQ;IACR,kBAAkB;IAClB,kBAAkB;IAClB,mBAAmB;CACpB,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,QAAQ;IACR,OAAO;IACP,kBAAkB;IAClB,GAAG,6BAA6B;CACjC,CAAC;AACF,MAAM,wBAAwB,GAAG;IAC/B,OAAO;IACP,kBAAkB;IAClB,GAAG,6BAA6B;CACjC,CAAC;AACF,MAAM,wBAAwB,GAAG,CAAC,GAAG,6BAA6B,CAAC,CAAC;AAEpE,SAAS,0BAA0B,CACjC,aAAiC;IAEjC,0BAA0B;IAC1B,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,6BAA6B,CAAC;KACtC;SAAM,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC3E,OAAO,wBAAwB,CAAC;KACjC;SAAM,IA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C,SAAS;QAE7C,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,QAAQ,YAAY,QAAQ,EAAE;YAChC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CACrC,IAAA,8BAAsB,EACpB,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,CAAC,SAAS,EAAE,CAAC,YAAY,EAC7B,aAAa,CACd,CACF,CAAC;SACH;aAAM;YACL,MAAM,QAAQ,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CAC/C,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,CAC/B,CAAC;YACF,OAAO,IAAA,6BAAqB,EAC1B,QAAQ,EACR,IAAI,EACJ,IAAI,CAAC,SAAS,EAAE,CAAC,YAAY,EAC7B,aAAa,CACd,CAAC;SACH;IACH,CAAC;IAEO,qBAAqB,CAAI,gBAAuC;QACtE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,+BAA+B,EAAE;YACpD,OAAO,aAAO,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;SAC1E;aAAM;YACL,OAAO,gBAAgB,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AAvYD,0DAuYC","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 { context, Span, trace, Attributes, SpanKind } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport type * as mongoose from 'mongoose';\nimport { MongooseInstrumentationConfig, SerializerPayload } from './types';\nimport {\n handleCallbackResponse,\n handlePromiseResponse,\n getAttributesFromCollection,\n} from './utils';\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport {\n ATTR_DB_OPERATION,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n} from './semconv';\n\nconst contextCaptureFunctionsCommon = [\n 'deleteOne',\n 'deleteMany',\n 'find',\n 'findOne',\n 'estimatedDocumentCount',\n 'countDocuments',\n 'distinct',\n 'where',\n '$where',\n 'findOneAndUpdate',\n 'findOneAndDelete',\n 'findOneAndReplace',\n];\n\nconst contextCaptureFunctions6 = [\n 'remove',\n 'count',\n 'findOneAndRemove',\n ...contextCaptureFunctionsCommon,\n];\nconst contextCaptureFunctions7 = [\n 'count',\n 'findOneAndRemove',\n ...contextCaptureFunctionsCommon,\n];\nconst contextCaptureFunctions8 = [...contextCaptureFunctionsCommon];\n\nfunction getContextCaptureFunctions(\n moduleVersion: string | undefined\n): string[] {\n /* istanbul ignore next */\n if (!moduleVersion) {\n return contextCaptureFunctionsCommon;\n } else if (moduleVersion.startsWith('6.') || moduleVersion.startsWith('5.')) {\n return contextCaptureFunctions6;\n } else if (moduleVersion.startsWith('7.')) {\n return contextCaptureFunctions7;\n } else {\n return contextCaptureFunctions8;\n }\n}\n\nfunction instrumentRemove(moduleVersion: string | undefined): boolean {\n return (\n (moduleVersion &&\n (moduleVersion.startsWith('5.') || moduleVersion.startsWith('6.'))) ||\n false\n );\n}\n\n// when mongoose functions are called, we store the original call context\n// and then set it as the parent for the spans created by Query/Aggregate exec()\n// calls. this bypass the unlinked spans issue on thenables await operations.\nexport const _STORED_PARENT_SPAN: unique symbol = Symbol('stored-parent-span');\n\nexport class MongooseInstrumentation extends InstrumentationBase<MongooseInstrumentationConfig> {\n constructor(config: MongooseInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'mongoose',\n ['>=5.9.7 <9'],\n this.patch.bind(this),\n this.unpatch.bind(this)\n );\n return module;\n }\n\n private patch(module: any, moduleVersion: string | undefined) {\n const moduleExports: typeof mongoose =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n\n this._wrap(\n moduleExports.Model.prototype,\n 'save',\n this.patchOnModelMethods('save', moduleVersion)\n );\n // mongoose applies this code on module require:\n // Model.prototype.$save = Model.prototype.save;\n // which captures the save function before it is patched.\n // so we need to apply the same logic after instrumenting the save function.\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._wrap(\n moduleExports.Model.prototype,\n 'remove',\n this.patchOnModelMethods('remove', moduleVersion)\n );\n }\n\n this._wrap(\n moduleExports.Query.prototype,\n 'exec',\n this.patchQueryExec(moduleVersion)\n );\n this._wrap(\n moduleExports.Aggregate.prototype,\n 'exec',\n this.patchAggregateExec(moduleVersion)\n );\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._wrap(\n moduleExports.Query.prototype,\n funcName as any,\n this.patchAndCaptureSpanContext(funcName)\n );\n });\n this._wrap(moduleExports.Model, 'aggregate', this.patchModelAggregate());\n\n this._wrap(\n moduleExports.Model,\n 'insertMany',\n this.patchModelStatic('insertMany', moduleVersion)\n );\n this._wrap(\n moduleExports.Model,\n 'bulkWrite',\n this.patchModelStatic('bulkWrite', moduleVersion)\n );\n\n return moduleExports;\n }\n\n private unpatch(module: any, moduleVersion: string | undefined): void {\n const moduleExports: typeof mongoose =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n this._unwrap(moduleExports.Model.prototype, 'save');\n // revert the patch for $save which we applied by aliasing it to patched `save`\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'remove');\n }\n\n this._unwrap(moduleExports.Query.prototype, 'exec');\n this._unwrap(moduleExports.Aggregate.prototype, 'exec');\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._unwrap(moduleExports.Query.prototype, funcName as any);\n });\n this._unwrap(moduleExports.Model, 'aggregate');\n\n this._unwrap(moduleExports.Model, 'insertMany');\n this._unwrap(moduleExports.Model, 'bulkWrite');\n }\n\n private patchAggregateExec(moduleVersion: string | undefined) {\n const self = this;\n return (originalAggregate: Function) => {\n return function exec(this: any, callback?: Function) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalAggregate.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n attributes[ATTR_DB_STATEMENT] = dbStatementSerializer('aggregate', {\n options: this.options,\n aggregatePipeline: this._pipeline,\n });\n }\n\n const span = self._startSpan(\n this._model.collection,\n this._model?.modelName,\n 'aggregate',\n attributes,\n parentSpan\n );\n\n return self._handleResponse(\n span,\n originalAggregate,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n private patchQueryExec(moduleVersion: string | undefined) {\n const self = this;\n return (originalExec: Function) => {\n return function exec(this: any, callback?: Function) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalExec.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n attributes[ATTR_DB_STATEMENT] = dbStatementSerializer(this.op, {\n condition: this._conditions,\n updates: this._update,\n options: this.options,\n fields: this._fields,\n });\n }\n const span = self._startSpan(\n this.mongooseCollection,\n this.model.modelName,\n this.op,\n attributes,\n parentSpan\n );\n\n return self._handleResponse(\n span,\n originalExec,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n private patchOnModelMethods(op: string, moduleVersion: string | undefined) {\n const self = this;\n return (originalOnModelFunction: Function) => {\n return function method(this: any, options?: any, callback?: Function) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalOnModelFunction.apply(this, arguments);\n }\n\n const serializePayload: SerializerPayload = { document: this };\n if (options && !(options instanceof Function)) {\n serializePayload.options = options;\n }\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n attributes[ATTR_DB_STATEMENT] = dbStatementSerializer(\n op,\n serializePayload\n );\n }\n const span = self._startSpan(\n this.constructor.collection,\n this.constructor.modelName,\n op,\n attributes\n );\n\n if (options instanceof Function) {\n callback = options;\n options = undefined;\n }\n\n return self._handleResponse(\n span,\n originalOnModelFunction,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n private patchModelStatic(op: string, moduleVersion: string | undefined) {\n const self = this;\n return (original: Function) => {\n return function patchedStatic(\n this: any,\n docsOrOps: any,\n options?: any,\n callback?: Function\n ) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return original.apply(this, arguments);\n }\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n\n const serializePayload: SerializerPayload = {};\n switch (op) {\n case 'insertMany':\n serializePayload.documents = docsOrOps;\n break;\n case 'bulkWrite':\n serializePayload.operations = docsOrOps;\n break;\n default:\n serializePayload.document = docsOrOps;\n break;\n }\n if (options !== undefined) {\n serializePayload.options = options;\n }\n\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n attributes[ATTR_DB_STATEMENT] = dbStatementSerializer(\n op,\n serializePayload\n );\n }\n\n const span = self._startSpan(\n this.collection,\n this.modelName,\n op,\n attributes\n );\n\n return self._handleResponse(\n span,\n original,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n // we want to capture the otel span on the object which is calling exec.\n // in the special case of aggregate, we need have no function to path\n // on the Aggregate object to capture the context on, so we patch\n // the aggregate of Model, and set the context on the Aggregate object\n private patchModelAggregate() {\n const self = this;\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n const currentSpan = trace.getSpan(context.active());\n const aggregate = self._callOriginalFunction(() =>\n original.apply(this, arguments)\n );\n if (aggregate) aggregate[_STORED_PARENT_SPAN] = currentSpan;\n return aggregate;\n };\n };\n }\n\n private patchAndCaptureSpanContext(funcName: string) {\n const self = this;\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n this[_STORED_PARENT_SPAN] = trace.getSpan(context.active());\n return self._callOriginalFunction(() =>\n original.apply(this, arguments)\n );\n };\n };\n }\n\n private _startSpan(\n collection: mongoose.Collection,\n modelName: string,\n operation: string,\n attributes: Attributes,\n parentSpan?: Span\n ): Span {\n return this.tracer.startSpan(\n `mongoose.${modelName}.${operation}`,\n {\n kind: SpanKind.CLIENT,\n attributes: {\n ...attributes,\n ...getAttributesFromCollection(collection),\n [ATTR_DB_OPERATION]: operation,\n [ATTR_DB_SYSTEM]: 'mongoose',\n },\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined\n );\n }\n\n private _handleResponse(\n span: Span,\n exec: Function,\n originalThis: any,\n args: IArguments,\n callback?: Function,\n moduleVersion: string | undefined = undefined\n ) {\n const self = this;\n if (callback instanceof Function) {\n return self._callOriginalFunction(() =>\n handleCallbackResponse(\n callback,\n exec,\n originalThis,\n span,\n args,\n self.getConfig().responseHook,\n moduleVersion\n )\n );\n } else {\n const response = self._callOriginalFunction(() =>\n exec.apply(originalThis, args)\n );\n return handlePromiseResponse(\n response,\n span,\n self.getConfig().responseHook,\n moduleVersion\n );\n }\n }\n\n private _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this.getConfig().suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"mongoose.js","sourceRoot":"","sources":["../../src/mongoose.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAAgF;AAChF,8CAAsD;AAGtD,mCAIiB;AACjB,oEAMwC;AACxC,kBAAkB;AAClB,uCAA0D;AAC1D,uCAKmB;AACnB,8EAI6C;AAE7C,MAAM,6BAA6B,GAAG;IACpC,WAAW;IACX,YAAY;IACZ,MAAM;IACN,SAAS;IACT,wBAAwB;IACxB,gBAAgB;IAChB,UAAU;IACV,OAAO;IACP,QAAQ;IACR,kBAAkB;IAClB,kBAAkB;IAClB,mBAAmB;CACpB,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,QAAQ;IACR,OAAO;IACP,kBAAkB;IAClB,GAAG,6BAA6B;CACjC,CAAC;AACF,MAAM,wBAAwB,GAAG;IAC/B,OAAO;IACP,kBAAkB;IAClB,GAAG,6BAA6B;CACjC,CAAC;AACF,MAAM,wBAAwB,GAAG,CAAC,GAAG,6BAA6B,CAAC,CAAC;AAEpE,SAAS,0BAA0B,CACjC,aAAiC;IAEjC,0BAA0B;IAC1B,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,6BAA6B,CAAC;KACtC;SAAM,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC3E,OAAO,wBAAwB,CAAC;KACjC;SAAM,IAAI,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzC,OAAO,wBAAwB,CAAC;KACjC;SAAM;QACL,OAAO,wBAAwB,CAAC;KACjC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,aAAiC;IACzD,OAAO,CACL,CAAC,aAAa;QACZ,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,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AAC,GAAG,EAAE,CACrC,IAAA,8BAAsB,EACpB,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,CAAC,SAAS,EAAE,CAAC,YAAY,EAC7B,aAAa,CACd,CACF,CAAC;SACH;aAAM;YACL,MAAM,QAAQ,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CAC/C,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,CAC/B,CAAC;YACF,OAAO,IAAA,6BAAqB,EAC1B,QAAQ,EACR,IAAI,EACJ,IAAI,CAAC,SAAS,EAAE,CAAC,YAAY,EAC7B,aAAa,CACd,CAAC;SACH;IACH,CAAC;IAEO,qBAAqB,CAAI,gBAAuC;QACtE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,+BAA+B,EAAE;YACpD,OAAO,aAAO,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;SAC1E;aAAM;YACL,OAAO,gBAAgB,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AA5iBD,0DA4iBC","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 { context, Span, trace, Attributes, SpanKind } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport type * as mongoose from 'mongoose';\nimport { MongooseInstrumentationConfig, SerializerPayload } from './types';\nimport {\n handleCallbackResponse,\n handlePromiseResponse,\n getAttributesFromCollection,\n} from './utils';\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport {\n ATTR_DB_OPERATION,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n DB_SYSTEM_NAME_VALUE_MONGODB,\n} from './semconv';\nimport {\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n} from '@opentelemetry/semantic-conventions';\n\nconst contextCaptureFunctionsCommon = [\n 'deleteOne',\n 'deleteMany',\n 'find',\n 'findOne',\n 'estimatedDocumentCount',\n 'countDocuments',\n 'distinct',\n 'where',\n '$where',\n 'findOneAndUpdate',\n 'findOneAndDelete',\n 'findOneAndReplace',\n];\n\nconst contextCaptureFunctions6 = [\n 'remove',\n 'count',\n 'findOneAndRemove',\n ...contextCaptureFunctionsCommon,\n];\nconst contextCaptureFunctions7 = [\n 'count',\n 'findOneAndRemove',\n ...contextCaptureFunctionsCommon,\n];\nconst contextCaptureFunctions8 = [...contextCaptureFunctionsCommon];\n\nfunction getContextCaptureFunctions(\n moduleVersion: string | undefined\n): string[] {\n /* istanbul ignore next */\n if (!moduleVersion) {\n return contextCaptureFunctionsCommon;\n } else if (moduleVersion.startsWith('6.') || moduleVersion.startsWith('5.')) {\n return contextCaptureFunctions6;\n } else if (moduleVersion.startsWith('7.')) {\n return contextCaptureFunctions7;\n } else {\n return contextCaptureFunctions8;\n }\n}\n\nfunction instrumentRemove(moduleVersion: string | undefined): boolean {\n return (\n (moduleVersion &&\n (moduleVersion.startsWith('5.') || moduleVersion.startsWith('6.'))) ||\n false\n );\n}\n\n/**\n * 8.21.0 changed Document.updateOne/deleteOne so that the Query is not fully built when Query.exec() is called.\n * @param moduleVersion\n */\nfunction needsDocumentMethodPatch(moduleVersion: string | undefined): boolean {\n if (!moduleVersion || !moduleVersion.startsWith('8.')) {\n return false;\n }\n\n const minor = parseInt(moduleVersion.split('.')[1], 10);\n return minor >= 21;\n}\n\n// when mongoose functions are called, we store the original call context\n// and then set it as the parent for the spans created by Query/Aggregate exec()\n// calls. this bypass the unlinked spans issue on thenables await operations.\nexport const _STORED_PARENT_SPAN: unique symbol = Symbol('stored-parent-span');\n\n// Prevents double-instrumentation when doc.updateOne/deleteOne (Mongoose 8.21.0+)\n// creates a span and returns a Query that also calls exec()\nexport const _ALREADY_INSTRUMENTED: unique symbol = Symbol(\n 'already-instrumented'\n);\n\nexport class MongooseInstrumentation extends InstrumentationBase<MongooseInstrumentationConfig> {\n private _netSemconvStability!: SemconvStability;\n private _dbSemconvStability!: SemconvStability;\n\n constructor(config: MongooseInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, 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 protected init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(\n 'mongoose',\n ['>=5.9.7 <9'],\n this.patch.bind(this),\n this.unpatch.bind(this)\n );\n return module;\n }\n\n private patch(module: any, moduleVersion: string | undefined) {\n const moduleExports: typeof mongoose =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n\n this._wrap(\n moduleExports.Model.prototype,\n 'save',\n this.patchOnModelMethods('save', moduleVersion)\n );\n // mongoose applies this code on module require:\n // Model.prototype.$save = Model.prototype.save;\n // which captures the save function before it is patched.\n // so we need to apply the same logic after instrumenting the save function.\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._wrap(\n moduleExports.Model.prototype,\n 'remove',\n this.patchOnModelMethods('remove', moduleVersion)\n );\n }\n\n // Mongoose 8.21.0+ changed Document.updateOne()/deleteOne() so that the Query is not fully built when Query.exec() is called.\n //\n // See https://github.com/Automattic/mongoose/blob/7dbda12dca1bd7adb9e270d7de8ac5229606ce72/lib/document.js#L861.\n // - `this` is a Query object\n // - the update happens in a pre-hook that gets called when Query.exec() is already running.\n // - when we instrument Query.exec(), we don't have access to the options yet as they get set during Query.exec() only.\n //\n // Unfortunately, after Query.exec() is finished, the options are left modified by the library, so just delaying\n // attaching the attributes after the span is done is not an option. Therefore, we patch Model methods\n // and grab the data directly where the user provides it.\n //\n // ref: https://github.com/Automattic/mongoose/pull/15908 (introduced this behavior)\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._wrap(\n moduleExports.Model.prototype,\n 'updateOne',\n this._patchDocumentUpdateMethods('updateOne', moduleVersion)\n );\n this._wrap(\n moduleExports.Model.prototype,\n 'deleteOne',\n this._patchDocumentUpdateMethods('deleteOne', moduleVersion)\n );\n }\n\n this._wrap(\n moduleExports.Query.prototype,\n 'exec',\n this.patchQueryExec(moduleVersion)\n );\n this._wrap(\n moduleExports.Aggregate.prototype,\n 'exec',\n this.patchAggregateExec(moduleVersion)\n );\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._wrap(\n moduleExports.Query.prototype,\n funcName as any,\n this.patchAndCaptureSpanContext(funcName)\n );\n });\n this._wrap(moduleExports.Model, 'aggregate', this.patchModelAggregate());\n\n this._wrap(\n moduleExports.Model,\n 'insertMany',\n this.patchModelStatic('insertMany', moduleVersion)\n );\n this._wrap(\n moduleExports.Model,\n 'bulkWrite',\n this.patchModelStatic('bulkWrite', moduleVersion)\n );\n\n return moduleExports;\n }\n\n private unpatch(module: any, moduleVersion: string | undefined): void {\n const moduleExports: typeof mongoose =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n\n const contextCaptureFunctions = getContextCaptureFunctions(moduleVersion);\n\n this._unwrap(moduleExports.Model.prototype, 'save');\n // revert the patch for $save which we applied by aliasing it to patched `save`\n moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;\n\n if (instrumentRemove(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'remove');\n }\n\n if (needsDocumentMethodPatch(moduleVersion)) {\n this._unwrap(moduleExports.Model.prototype, 'updateOne');\n this._unwrap(moduleExports.Model.prototype, 'deleteOne');\n }\n\n this._unwrap(moduleExports.Query.prototype, 'exec');\n this._unwrap(moduleExports.Aggregate.prototype, 'exec');\n\n contextCaptureFunctions.forEach((funcName: string) => {\n this._unwrap(moduleExports.Query.prototype, funcName as any);\n });\n this._unwrap(moduleExports.Model, 'aggregate');\n\n this._unwrap(moduleExports.Model, 'insertMany');\n this._unwrap(moduleExports.Model, 'bulkWrite');\n }\n\n private patchAggregateExec(moduleVersion: string | undefined) {\n const self = this;\n return (originalAggregate: Function) => {\n return function exec(this: any, callback?: Function) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalAggregate.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n const statement = dbStatementSerializer('aggregate', {\n options: this.options,\n aggregatePipeline: this._pipeline,\n });\n if (self._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = statement;\n }\n if (self._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = statement;\n }\n }\n\n const span = self._startSpan(\n this._model.collection,\n this._model?.modelName,\n 'aggregate',\n attributes,\n parentSpan\n );\n\n return self._handleResponse(\n span,\n originalAggregate,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n private patchQueryExec(moduleVersion: string | undefined) {\n const self = this;\n return (originalExec: Function) => {\n return function exec(this: any, callback?: Function) {\n // Skip if already instrumented by document instance method patch\n if (this[_ALREADY_INSTRUMENTED]) {\n return originalExec.apply(this, arguments);\n }\n\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalExec.apply(this, arguments);\n }\n\n const parentSpan = this[_STORED_PARENT_SPAN];\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n const statement = dbStatementSerializer(this.op, {\n // Use public API methods (getFilter/getOptions) for better compatibility\n condition: this.getFilter?.() ?? this._conditions,\n updates: this._update,\n options: this.getOptions?.() ?? this.options,\n fields: this._fields,\n });\n if (self._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = statement;\n }\n if (self._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = statement;\n }\n }\n const span = self._startSpan(\n this.mongooseCollection,\n this.model.modelName,\n this.op,\n attributes,\n parentSpan\n );\n\n return self._handleResponse(\n span,\n originalExec,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n private patchOnModelMethods(op: string, moduleVersion: string | undefined) {\n const self = this;\n return (originalOnModelFunction: Function) => {\n return function method(this: any, options?: any, callback?: Function) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalOnModelFunction.apply(this, arguments);\n }\n\n const serializePayload: SerializerPayload = { document: this };\n if (options && !(options instanceof Function)) {\n serializePayload.options = options;\n }\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n const statement = dbStatementSerializer(op, serializePayload);\n if (self._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = statement;\n }\n if (self._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = statement;\n }\n }\n const span = self._startSpan(\n this.constructor.collection,\n this.constructor.modelName,\n op,\n attributes\n );\n\n if (options instanceof Function) {\n callback = options;\n options = undefined;\n }\n\n return self._handleResponse(\n span,\n originalOnModelFunction,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n // Patch document instance methods (doc.updateOne/deleteOne) for Mongoose 8.21.0+.\n private _patchDocumentUpdateMethods(\n op: string,\n moduleVersion: string | undefined\n ) {\n const self = this;\n return (originalMethod: Function) => {\n return function method(\n this: any,\n update?: any,\n options?: any,\n callback?: Function\n ) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return originalMethod.apply(this, arguments);\n }\n\n // determine actual callback since different argument patterns are allowed\n let actualCallback: Function | undefined = callback;\n let actualUpdate = update;\n let actualOptions = options;\n\n if (typeof update === 'function') {\n actualCallback = update;\n actualUpdate = undefined;\n actualOptions = undefined;\n } else if (typeof options === 'function') {\n actualCallback = options;\n actualOptions = undefined;\n }\n\n const attributes: Attributes = {};\n const dbStatementSerializer = self.getConfig().dbStatementSerializer;\n if (dbStatementSerializer) {\n const statement = dbStatementSerializer(op, {\n // Document instance methods automatically use the document's _id as filter\n condition: { _id: this._id },\n updates: actualUpdate,\n options: actualOptions,\n });\n if (self._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = statement;\n }\n if (self._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = statement;\n }\n }\n\n const span = self._startSpan(\n this.constructor.collection,\n this.constructor.modelName,\n op,\n attributes\n );\n\n const result = self._handleResponse(\n span,\n originalMethod,\n this,\n arguments,\n actualCallback,\n moduleVersion\n );\n\n // Mark returned Query to prevent double-instrumentation when exec() is eventually called\n if (result && typeof result === 'object') {\n result[_ALREADY_INSTRUMENTED] = true;\n }\n\n return result;\n };\n };\n }\n\n private patchModelStatic(op: string, moduleVersion: string | undefined) {\n const self = this;\n return (original: Function) => {\n return function patchedStatic(\n this: any,\n docsOrOps: any,\n options?: any,\n callback?: Function\n ) {\n if (\n self.getConfig().requireParentSpan &&\n trace.getSpan(context.active()) === undefined\n ) {\n return original.apply(this, arguments);\n }\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n\n const serializePayload: SerializerPayload = {};\n switch (op) {\n case 'insertMany':\n serializePayload.documents = docsOrOps;\n break;\n case 'bulkWrite':\n serializePayload.operations = docsOrOps;\n break;\n default:\n serializePayload.document = docsOrOps;\n break;\n }\n if (options !== undefined) {\n serializePayload.options = options;\n }\n\n const attributes: Attributes = {};\n const { dbStatementSerializer } = self.getConfig();\n if (dbStatementSerializer) {\n const statement = dbStatementSerializer(op, serializePayload);\n if (self._dbSemconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = statement;\n }\n if (self._dbSemconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = statement;\n }\n }\n\n const span = self._startSpan(\n this.collection,\n this.modelName,\n op,\n attributes\n );\n\n return self._handleResponse(\n span,\n original,\n this,\n arguments,\n callback,\n moduleVersion\n );\n };\n };\n }\n\n // we want to capture the otel span on the object which is calling exec.\n // in the special case of aggregate, we need have no function to path\n // on the Aggregate object to capture the context on, so we patch\n // the aggregate of Model, and set the context on the Aggregate object\n private patchModelAggregate() {\n const self = this;\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n const currentSpan = trace.getSpan(context.active());\n const aggregate = self._callOriginalFunction(() =>\n original.apply(this, arguments)\n );\n if (aggregate) aggregate[_STORED_PARENT_SPAN] = currentSpan;\n return aggregate;\n };\n };\n }\n\n private patchAndCaptureSpanContext(funcName: string) {\n const self = this;\n return (original: Function) => {\n return function captureSpanContext(this: any) {\n this[_STORED_PARENT_SPAN] = trace.getSpan(context.active());\n return self._callOriginalFunction(() =>\n original.apply(this, arguments)\n );\n };\n };\n }\n\n private _startSpan(\n collection: mongoose.Collection,\n modelName: string,\n operation: string,\n attributes: Attributes,\n parentSpan?: Span\n ): Span {\n const finalAttributes: Attributes = {\n ...attributes,\n ...getAttributesFromCollection(\n collection,\n this._dbSemconvStability,\n this._netSemconvStability\n ),\n };\n\n if (this._dbSemconvStability & SemconvStability.OLD) {\n finalAttributes[ATTR_DB_OPERATION] = operation;\n finalAttributes[ATTR_DB_SYSTEM] = 'mongoose'; // keep for backwards compatibility\n }\n if (this._dbSemconvStability & SemconvStability.STABLE) {\n finalAttributes[ATTR_DB_OPERATION_NAME] = operation;\n finalAttributes[ATTR_DB_SYSTEM_NAME] = DB_SYSTEM_NAME_VALUE_MONGODB; // actual db system name\n }\n\n const spanName =\n this._dbSemconvStability & SemconvStability.STABLE\n ? `${operation} ${collection.name}`\n : `mongoose.${modelName}.${operation}`;\n\n return this.tracer.startSpan(\n spanName,\n {\n kind: SpanKind.CLIENT,\n attributes: finalAttributes,\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined\n );\n }\n\n private _handleResponse(\n span: Span,\n exec: Function,\n originalThis: any,\n args: IArguments,\n callback?: Function,\n moduleVersion: string | undefined = undefined\n ) {\n const self = this;\n if (callback instanceof Function) {\n return self._callOriginalFunction(() =>\n handleCallbackResponse(\n callback,\n exec,\n originalThis,\n span,\n args,\n self.getConfig().responseHook,\n moduleVersion\n )\n );\n } else {\n const response = self._callOriginalFunction(() =>\n exec.apply(originalThis, args)\n );\n return handlePromiseResponse(\n response,\n span,\n self.getConfig().responseHook,\n moduleVersion\n );\n }\n }\n\n private _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this.getConfig().suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n}\n"]}
@@ -81,4 +81,12 @@ export declare const ATTR_NET_PEER_NAME: "net.peer.name";
81
81
  * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
82
82
  */
83
83
  export declare const ATTR_NET_PEER_PORT: "net.peer.port";
84
+ /**
85
+ * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM_NAME}.
86
+ *
87
+ * [MongoDB](https://www.mongodb.com/)
88
+ *
89
+ * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
90
+ */
91
+ export declare const DB_SYSTEM_NAME_VALUE_MONGODB: "mongodb";
84
92
  //# sourceMappingURL=semconv.d.ts.map
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ATTR_NET_PEER_PORT = exports.ATTR_NET_PEER_NAME = exports.ATTR_DB_USER = exports.ATTR_DB_SYSTEM = exports.ATTR_DB_STATEMENT = exports.ATTR_DB_OPERATION = exports.ATTR_DB_NAME = exports.ATTR_DB_MONGODB_COLLECTION = void 0;
18
+ exports.DB_SYSTEM_NAME_VALUE_MONGODB = exports.ATTR_NET_PEER_PORT = exports.ATTR_NET_PEER_NAME = exports.ATTR_DB_USER = exports.ATTR_DB_SYSTEM = exports.ATTR_DB_STATEMENT = exports.ATTR_DB_OPERATION = exports.ATTR_DB_NAME = exports.ATTR_DB_MONGODB_COLLECTION = void 0;
19
19
  /*
20
20
  * This file contains a copy of unstable semantic convention definitions
21
21
  * used by this package.
@@ -104,4 +104,12 @@ exports.ATTR_NET_PEER_NAME = 'net.peer.name';
104
104
  * @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
105
105
  */
106
106
  exports.ATTR_NET_PEER_PORT = 'net.peer.port';
107
+ /**
108
+ * Enum value "mongodb" for attribute {@link ATTR_DB_SYSTEM_NAME}.
109
+ *
110
+ * [MongoDB](https://www.mongodb.com/)
111
+ *
112
+ * @experimental This enum value is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
113
+ */
114
+ exports.DB_SYSTEM_NAME_VALUE_MONGODB = 'mongodb';
107
115
  //# sourceMappingURL=semconv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;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;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,SAAkB,CAAC;AAE/C;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,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 `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, no replacement at this time.\n *\n * @example readonly_user\n * @example reporting_user\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Removed, no replacement at this time.\n */\nexport const ATTR_DB_USER = 'db.user' 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"]}
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;;;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;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,SAAkB,CAAC;AAE/C;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;;;GAQG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;GAMG;AACU,QAAA,4BAA4B,GAAG,SAAkB,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 `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, no replacement at this time.\n *\n * @example readonly_user\n * @example reporting_user\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Removed, no replacement at this time.\n */\nexport const ATTR_DB_USER = 'db.user' 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"]}
@@ -1,7 +1,8 @@
1
1
  import { Attributes, Span } from '@opentelemetry/api';
2
2
  import type { Collection } from 'mongoose';
3
3
  import { MongooseResponseCustomAttributesFunction } from './types';
4
- export declare function getAttributesFromCollection(collection: Collection): Attributes;
4
+ import { SemconvStability } from '@opentelemetry/instrumentation';
5
+ export declare function getAttributesFromCollection(collection: Collection, dbSemconvStability: SemconvStability, netSemconvStability: SemconvStability): Attributes;
5
6
  export declare function handlePromiseResponse(execResponse: any, span: Span, responseHook?: MongooseResponseCustomAttributesFunction, moduleVersion?: string | undefined): any;
6
7
  export declare function handleCallbackResponse(callback: Function, exec: Function, originalThis: any, span: Span, args: IArguments, responseHook?: MongooseResponseCustomAttributesFunction, moduleVersion?: string | undefined): any;
7
8
  //# sourceMappingURL=utils.d.ts.map
@@ -19,14 +19,28 @@ exports.handleCallbackResponse = exports.handlePromiseResponse = exports.getAttr
19
19
  const api_1 = require("@opentelemetry/api");
20
20
  const instrumentation_1 = require("@opentelemetry/instrumentation");
21
21
  const semconv_1 = require("./semconv");
22
- function getAttributesFromCollection(collection) {
23
- return {
24
- [semconv_1.ATTR_DB_MONGODB_COLLECTION]: collection.name,
25
- [semconv_1.ATTR_DB_NAME]: collection.conn.name,
26
- [semconv_1.ATTR_DB_USER]: collection.conn.user,
27
- [semconv_1.ATTR_NET_PEER_NAME]: collection.conn.host,
28
- [semconv_1.ATTR_NET_PEER_PORT]: collection.conn.port,
29
- };
22
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
23
+ function getAttributesFromCollection(collection, dbSemconvStability, netSemconvStability) {
24
+ const attrs = {};
25
+ if (dbSemconvStability & instrumentation_1.SemconvStability.OLD) {
26
+ attrs[semconv_1.ATTR_DB_MONGODB_COLLECTION] = collection.name;
27
+ attrs[semconv_1.ATTR_DB_NAME] = collection.conn.name;
28
+ attrs[semconv_1.ATTR_DB_USER] = collection.conn.user;
29
+ }
30
+ if (dbSemconvStability & instrumentation_1.SemconvStability.STABLE) {
31
+ attrs[semantic_conventions_1.ATTR_DB_COLLECTION_NAME] = collection.name;
32
+ attrs[semantic_conventions_1.ATTR_DB_NAMESPACE] = collection.conn.name;
33
+ // db.user has no stable replacement
34
+ }
35
+ if (netSemconvStability & instrumentation_1.SemconvStability.OLD) {
36
+ attrs[semconv_1.ATTR_NET_PEER_NAME] = collection.conn.host;
37
+ attrs[semconv_1.ATTR_NET_PEER_PORT] = collection.conn.port;
38
+ }
39
+ if (netSemconvStability & instrumentation_1.SemconvStability.STABLE) {
40
+ attrs[semantic_conventions_1.ATTR_SERVER_ADDRESS] = collection.conn.host;
41
+ attrs[semantic_conventions_1.ATTR_SERVER_PORT] = collection.conn.port;
42
+ }
43
+ return attrs;
30
44
  }
31
45
  exports.getAttributesFromCollection = getAttributesFromCollection;
32
46
  function setErrorStatus(span, error = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4E;AAG5E,oEAAwE;AACxE,uCAMmB;AAEnB,SAAgB,2BAA2B,CACzC,UAAsB;IAEtB,OAAO;QACL,CAAC,oCAA0B,CAAC,EAAE,UAAU,CAAC,IAAI;QAC7C,CAAC,sBAAY,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QACpC,CAAC,sBAAY,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QACpC,CAAC,4BAAkB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QAC1C,CAAC,4BAAkB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;KAC3C,CAAC;AACJ,CAAC;AAVD,kE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I,EAAE,GAAG,CAAC,CAAC;QAC1B,MAAM,GAAG,CAAC;IACZ,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AAC/B,CAAC;AAtBD,sDAsBC;AAED,SAAgB,sBAAsB,CACpC,QAAkB,EAClB,IAAc,EACd,YAAiB,EACjB,IAAU,EACV,IAAgB,EAChB,YAAuD,EACvD,gBAAoC,SAAS;IAE7C,IAAI,qBAAqB,GAAG,CAAC,CAAC;IAC9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,qBAAqB,GAAG,CAAC,CAAC;KAC3B;SAAM,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,qBAAqB,GAAG,CAAC,CAAC;KAC3B;IAED,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAU,EAAE,QAAa,EAAO,EAAE;QAC/D,IAAI,GAAG,EAAE;YACP,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC3B;aAAM;YACL,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;SAChE;QAED,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,QAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AA5BD,wDA4BC","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 { Attributes, SpanStatusCode, diag, Span } from '@opentelemetry/api';\nimport type { Collection } from 'mongoose';\nimport { MongooseResponseCustomAttributesFunction } from './types';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_MONGODB_COLLECTION,\n ATTR_DB_NAME,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n} from './semconv';\n\nexport function getAttributesFromCollection(\n collection: Collection\n): Attributes {\n return {\n [ATTR_DB_MONGODB_COLLECTION]: collection.name,\n [ATTR_DB_NAME]: collection.conn.name,\n [ATTR_DB_USER]: collection.conn.user,\n [ATTR_NET_PEER_NAME]: collection.conn.host,\n [ATTR_NET_PEER_PORT]: collection.conn.port,\n };\n}\n\nfunction setErrorStatus(span: Span, error: any = {}) {\n span.recordException(error);\n\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: `${error.message} ${\n error.code ? `\\nMongoose Error Code: ${error.code}` : ''\n }`,\n });\n}\n\nfunction applyResponseHook(\n span: Span,\n response: any,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n) {\n if (!responseHook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => responseHook(span, { moduleVersion, response }),\n e => {\n if (e) {\n diag.error('mongoose instrumentation: responseHook error', e);\n }\n },\n true\n );\n}\n\nexport function handlePromiseResponse(\n execResponse: any,\n span: Span,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n): any {\n if (!(execResponse instanceof Promise)) {\n applyResponseHook(span, execResponse, responseHook, moduleVersion);\n span.end();\n return execResponse;\n }\n\n return execResponse\n .then(response => {\n applyResponseHook(span, response, responseHook, moduleVersion);\n return response;\n })\n .catch(err => {\n setErrorStatus(span, err);\n throw err;\n })\n .finally(() => span.end());\n}\n\nexport function handleCallbackResponse(\n callback: Function,\n exec: Function,\n originalThis: any,\n span: Span,\n args: IArguments,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n) {\n let callbackArgumentIndex = 0;\n if (args.length === 2) {\n callbackArgumentIndex = 1;\n } else if (args.length === 3) {\n callbackArgumentIndex = 2;\n }\n\n args[callbackArgumentIndex] = (err: Error, response: any): any => {\n if (err) {\n setErrorStatus(span, err);\n } else {\n applyResponseHook(span, response, responseHook, moduleVersion);\n }\n\n span.end();\n return callback!(err, response);\n };\n\n return exec.apply(originalThis, args);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4E;AAG5E,oEAGwC;AACxC,uCAMmB;AACnB,8EAK6C;AAE7C,SAAgB,2BAA2B,CACzC,UAAsB,EACtB,kBAAoC,EACpC,mBAAqC;IAErC,MAAM,KAAK,GAAe,EAAE,CAAC;IAE7B,IAAI,kBAAkB,GAAG,kCAAgB,CAAC,GAAG,EAAE;QAC7C,KAAK,CAAC,oCAA0B,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;QACpD,KAAK,CAAC,sBAAY,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QAC3C,KAAK,CAAC,sBAAY,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;KAC5C;IACD,IAAI,kBAAkB,GAAG,kCAAgB,CAAC,MAAM,EAAE;QAChD,KAAK,CAAC,8CAAuB,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;QACjD,KAAK,CAAC,wCAAiB,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QAChD,oCAAoC;KACrC;IAED,IAAI,mBAAmB,GAAG,kCAAgB,CAAC,GAAG,EAAE;QAC9C,KAAK,CAAC,4BAAkB,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACjD,KAAK,CAAC,4BAAkB,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC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ry 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 { Attributes, SpanStatusCode, diag, Span } from '@opentelemetry/api';\nimport type { Collection } from 'mongoose';\nimport { MongooseResponseCustomAttributesFunction } from './types';\nimport {\n safeExecuteInTheMiddle,\n SemconvStability,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_MONGODB_COLLECTION,\n ATTR_DB_NAME,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n} from './semconv';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\n\nexport function getAttributesFromCollection(\n collection: Collection,\n dbSemconvStability: SemconvStability,\n netSemconvStability: SemconvStability\n): Attributes {\n const attrs: Attributes = {};\n\n if (dbSemconvStability & SemconvStability.OLD) {\n attrs[ATTR_DB_MONGODB_COLLECTION] = collection.name;\n attrs[ATTR_DB_NAME] = collection.conn.name;\n attrs[ATTR_DB_USER] = collection.conn.user;\n }\n if (dbSemconvStability & SemconvStability.STABLE) {\n attrs[ATTR_DB_COLLECTION_NAME] = collection.name;\n attrs[ATTR_DB_NAMESPACE] = collection.conn.name;\n // db.user has no stable replacement\n }\n\n if (netSemconvStability & SemconvStability.OLD) {\n attrs[ATTR_NET_PEER_NAME] = collection.conn.host;\n attrs[ATTR_NET_PEER_PORT] = collection.conn.port;\n }\n if (netSemconvStability & SemconvStability.STABLE) {\n attrs[ATTR_SERVER_ADDRESS] = collection.conn.host;\n attrs[ATTR_SERVER_PORT] = collection.conn.port;\n }\n\n return attrs;\n}\n\nfunction setErrorStatus(span: Span, error: any = {}) {\n span.recordException(error);\n\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: `${error.message} ${\n error.code ? `\\nMongoose Error Code: ${error.code}` : ''\n }`,\n });\n}\n\nfunction applyResponseHook(\n span: Span,\n response: any,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n) {\n if (!responseHook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => responseHook(span, { moduleVersion, response }),\n e => {\n if (e) {\n diag.error('mongoose instrumentation: responseHook error', e);\n }\n },\n true\n );\n}\n\nexport function handlePromiseResponse(\n execResponse: any,\n span: Span,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n): any {\n if (!(execResponse instanceof Promise)) {\n applyResponseHook(span, execResponse, responseHook, moduleVersion);\n span.end();\n return execResponse;\n }\n\n return execResponse\n .then(response => {\n applyResponseHook(span, response, responseHook, moduleVersion);\n return response;\n })\n .catch(err => {\n setErrorStatus(span, err);\n throw err;\n })\n .finally(() => span.end());\n}\n\nexport function handleCallbackResponse(\n callback: Function,\n exec: Function,\n originalThis: any,\n span: Span,\n args: IArguments,\n responseHook?: MongooseResponseCustomAttributesFunction,\n moduleVersion: string | undefined = undefined\n) {\n let callbackArgumentIndex = 0;\n if (args.length === 2) {\n callbackArgumentIndex = 1;\n } else if (args.length === 3) {\n callbackArgumentIndex = 2;\n }\n\n args[callbackArgumentIndex] = (err: Error, response: any): any => {\n if (err) {\n setErrorStatus(span, err);\n } else {\n applyResponseHook(span, response, responseHook, moduleVersion);\n }\n\n span.end();\n return callback!(err, response);\n };\n\n return exec.apply(originalThis, args);\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.55.0";
1
+ export declare const PACKAGE_VERSION = "0.56.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-mongoose";
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.55.0';
20
+ exports.PACKAGE_VERSION = '0.56.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mongoose';
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,yCAAyC,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.55.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mongoose';\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,yCAAyC,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.56.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mongoose';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-mongoose",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "description": "OpenTelemetry instrumentation for `mongoose` database object data modeling (ODM) library for MongoDB",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -17,8 +17,8 @@
17
17
  "prepublishOnly": "npm run compile",
18
18
  "tdd": "npm run test -- --watch-extensions ts --watch",
19
19
  "test": "npm run test-v5-v6",
20
- "test-v5-v6": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongoose-common.test.ts' 'test/**/mongoose-v5-v6.test.ts'",
21
- "test-v7-v8": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongoose-common.test.ts' 'test/**/mongoose-v7-v8.test.ts'",
20
+ "test-v5-v6": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongoose-common.test.ts' 'test/**/mongoose-v5-v6.test.ts'",
21
+ "test-v7-v8": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongoose-common.test.ts' 'test/**/mongoose-v7-v8.test.ts'",
22
22
  "test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
23
23
  "test-all-versions": "tav",
24
24
  "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",
@@ -53,22 +53,15 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@opentelemetry/api": "^1.3.0",
56
- "@opentelemetry/contrib-test-utils": "^0.55.0",
56
+ "@opentelemetry/contrib-test-utils": "^0.57.0",
57
57
  "@opentelemetry/sdk-trace-base": "^2.0.0",
58
- "@types/mocha": "10.0.10",
59
- "@types/node": "18.18.14",
60
- "cross-env": "7.0.3",
61
- "expect": "29.2.0",
62
- "mongoose": "6.13.8",
63
- "nyc": "17.1.0",
64
- "rimraf": "5.0.10",
65
- "test-all-versions": "6.1.0",
66
- "typescript": "5.0.4"
58
+ "mongoose": "6.13.8"
67
59
  },
68
60
  "dependencies": {
69
61
  "@opentelemetry/core": "^2.0.0",
70
- "@opentelemetry/instrumentation": "^0.208.0"
62
+ "@opentelemetry/instrumentation": "^0.210.0",
63
+ "@opentelemetry/semantic-conventions": "^1.33.0"
71
64
  },
72
65
  "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mongoose#readme",
73
- "gitHead": "94e5b7da4500459e38e8d4dfda93542f22159600"
66
+ "gitHead": "c84212cca7f010b80747cccb9942474e0459df6e"
74
67
  }