@opentelemetry/instrumentation-mongoose 0.48.0 → 0.50.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.
@@ -1,3 +1,3 @@
1
- export * from './mongoose';
2
- export * from './types';
1
+ export { MongooseInstrumentation } from './mongoose';
2
+ export type { DbStatementSerializer, MongooseInstrumentationConfig, MongooseResponseCustomAttributesFunction, ResponseInfo, SerializerPayload, } from './types';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,19 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseInstrumentation = void 0;
17
4
  /*
18
5
  * Copyright The OpenTelemetry Authors
19
6
  *
@@ -29,6 +16,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
16
  * See the License for the specific language governing permissions and
30
17
  * limitations under the License.
31
18
  */
32
- __exportStar(require("./mongoose"), exports);
33
- __exportStar(require("./types"), exports);
19
+ var mongoose_1 = require("./mongoose");
20
+ Object.defineProperty(exports, "MongooseInstrumentation", { enumerable: true, get: function () { return mongoose_1.MongooseInstrumentation; } });
34
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAA2B;AAC3B,0CAAwB","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 */\nexport * from './mongoose';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA","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 */\nexport { MongooseInstrumentation } from './mongoose';\nexport type {\n DbStatementSerializer,\n MongooseInstrumentationConfig,\n MongooseResponseCustomAttributesFunction,\n ResponseInfo,\n SerializerPayload,\n} from './types';\n"]}
@@ -9,6 +9,7 @@ export declare class MongooseInstrumentation extends InstrumentationBase<Mongoos
9
9
  private patchAggregateExec;
10
10
  private patchQueryExec;
11
11
  private patchOnModelMethods;
12
+ private patchModelStatic;
12
13
  private patchModelAggregate;
13
14
  private patchAndCaptureSpanContext;
14
15
  private _startSpan;
@@ -101,6 +101,8 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
101
101
  this._wrap(moduleExports.Query.prototype, funcName, this.patchAndCaptureSpanContext(funcName));
102
102
  });
103
103
  this._wrap(moduleExports.Model, 'aggregate', this.patchModelAggregate());
104
+ this._wrap(moduleExports.Model, 'insertMany', this.patchModelStatic('insertMany', moduleVersion));
105
+ this._wrap(moduleExports.Model, 'bulkWrite', this.patchModelStatic('bulkWrite', moduleVersion));
104
106
  return moduleExports;
105
107
  }
106
108
  unpatch(module, moduleVersion) {
@@ -120,6 +122,8 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
120
122
  this._unwrap(moduleExports.Query.prototype, funcName);
121
123
  });
122
124
  this._unwrap(moduleExports.Model, 'aggregate');
125
+ this._unwrap(moduleExports.Model, 'insertMany');
126
+ this._unwrap(moduleExports.Model, 'bulkWrite');
123
127
  }
124
128
  patchAggregateExec(moduleVersion) {
125
129
  const self = this;
@@ -193,6 +197,43 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
193
197
  };
194
198
  };
195
199
  }
200
+ patchModelStatic(op, moduleVersion) {
201
+ const self = this;
202
+ return (original) => {
203
+ return function patchedStatic(docsOrOps, options, callback) {
204
+ if (self.getConfig().requireParentSpan &&
205
+ api_1.trace.getSpan(api_1.context.active()) === undefined) {
206
+ return original.apply(this, arguments);
207
+ }
208
+ if (typeof options === 'function') {
209
+ callback = options;
210
+ options = undefined;
211
+ }
212
+ const serializePayload = {};
213
+ switch (op) {
214
+ case 'insertMany':
215
+ serializePayload.documents = docsOrOps;
216
+ break;
217
+ case 'bulkWrite':
218
+ serializePayload.operations = docsOrOps;
219
+ break;
220
+ default:
221
+ serializePayload.document = docsOrOps;
222
+ break;
223
+ }
224
+ if (options !== undefined) {
225
+ serializePayload.options = options;
226
+ }
227
+ const attributes = {};
228
+ const { dbStatementSerializer } = self.getConfig();
229
+ if (dbStatementSerializer) {
230
+ attributes[semantic_conventions_1.SEMATTRS_DB_STATEMENT] = dbStatementSerializer(op, serializePayload);
231
+ }
232
+ const span = self._startSpan(this.collection, this.modelName, op, attributes);
233
+ return self._handleResponse(span, original, this, arguments, callback, moduleVersion);
234
+ };
235
+ };
236
+ }
196
237
  // we want to capture the otel span on the object which is calling exec.
197
238
  // in the special case of aggregate, we need have no function to path
198
239
  // on the Aggregate object to capture the context on, so we patch
@@ -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,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;QAC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CAAC,CAAC;SAC1E;aAAM;YACL,OAAO,gBAAgB,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AA5TD,0DA4TC","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 SEMATTRS_DB_OPERATION,\n SEMATTRS_DB_STATEMENT,\n SEMATTRS_DB_SYSTEM,\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// 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 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\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[SEMATTRS_DB_STATEMENT] = dbStatementSerializer(\n 'aggregate',\n {\n options: this.options,\n aggregatePipeline: this._pipeline,\n }\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[SEMATTRS_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[SEMATTRS_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 // 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 [SEMATTRS_DB_OPERATION]: operation,\n [SEMATTRS_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,oEAIwC;AACxC,kBAAkB;AAClB,uCAA0D;AAC1D,8EAI6C;AAE7C,MA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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;AA1YD,0DA0YC","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 SEMATTRS_DB_OPERATION,\n SEMATTRS_DB_STATEMENT,\n SEMATTRS_DB_SYSTEM,\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// 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[SEMATTRS_DB_STATEMENT] = dbStatementSerializer(\n 'aggregate',\n {\n options: this.options,\n aggregatePipeline: this._pipeline,\n }\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[SEMATTRS_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[SEMATTRS_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[SEMATTRS_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 [SEMATTRS_DB_OPERATION]: operation,\n [SEMATTRS_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"]}
@@ -7,6 +7,8 @@ export interface SerializerPayload {
7
7
  document?: any;
8
8
  aggregatePipeline?: any;
9
9
  fields?: any;
10
+ documents?: any;
11
+ operations?: any;
10
12
  }
11
13
  export type DbStatementSerializer = (operation: string, payload: SerializerPayload) => string;
12
14
  export interface ResponseInfo {
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport interface SerializerPayload {\n condition?: any;\n options?: any;\n updates?: any;\n document?: any;\n aggregatePipeline?: any;\n fields?: any;\n}\n\nexport type DbStatementSerializer = (\n operation: string,\n payload: SerializerPayload\n) => string;\n\nexport interface ResponseInfo {\n moduleVersion: string | undefined;\n response: any;\n}\n\nexport type MongooseResponseCustomAttributesFunction = (\n span: Span,\n responseInfo: ResponseInfo\n) => void;\n\nexport interface MongooseInstrumentationConfig extends InstrumentationConfig {\n /**\n * Mongoose operation use mongodb under the hood.\n * If mongodb instrumentation is enabled, a mongoose operation will also create\n * a mongodb operation describing the communication with mongoDB servers.\n * Setting the `suppressInternalInstrumentation` config value to `true` will\n * cause the instrumentation to suppress instrumentation of underlying operations,\n * effectively causing mongodb spans to be non-recordable.\n */\n suppressInternalInstrumentation?: boolean;\n\n /** Custom serializer function for the db.statement tag */\n dbStatementSerializer?: DbStatementSerializer;\n\n /** hook for adding custom attributes using the response payload */\n responseHook?: MongooseResponseCustomAttributesFunction;\n\n /** Set to true if you do not want to collect traces that start with mongoose */\n requireParentSpan?: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport interface SerializerPayload {\n condition?: any;\n options?: any;\n updates?: any;\n document?: any;\n aggregatePipeline?: any;\n fields?: any;\n documents?: any;\n operations?: any;\n}\n\nexport type DbStatementSerializer = (\n operation: string,\n payload: SerializerPayload\n) => string;\n\nexport interface ResponseInfo {\n moduleVersion: string | undefined;\n response: any;\n}\n\nexport type MongooseResponseCustomAttributesFunction = (\n span: Span,\n responseInfo: ResponseInfo\n) => void;\n\nexport interface MongooseInstrumentationConfig extends InstrumentationConfig {\n /**\n * Mongoose operation use mongodb under the hood.\n * If mongodb instrumentation is enabled, a mongoose operation will also create\n * a mongodb operation describing the communication with mongoDB servers.\n * Setting the `suppressInternalInstrumentation` config value to `true` will\n * cause the instrumentation to suppress instrumentation of underlying operations,\n * effectively causing mongodb spans to be non-recordable.\n */\n suppressInternalInstrumentation?: boolean;\n\n /** Custom serializer function for the db.statement tag */\n dbStatementSerializer?: DbStatementSerializer;\n\n /** hook for adding custom attributes using the response payload */\n responseHook?: MongooseResponseCustomAttributesFunction;\n\n /** Set to true if you do not want to collect traces that start with mongoose */\n requireParentSpan?: boolean;\n}\n"]}
@@ -69,6 +69,9 @@ function handleCallbackResponse(callback, exec, originalThis, span, args, respon
69
69
  if (args.length === 2) {
70
70
  callbackArgumentIndex = 1;
71
71
  }
72
+ else if (args.length === 3) {
73
+ callbackArgumentIndex = 2;
74
+ }
72
75
  args[callbackArgumentIndex] = (err, response) => {
73
76
  err
74
77
  ? setErrorStatus(span, err)
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4E;AAG5E,oEAAwE;AACxE,8EAM6C;AAE7C,SAAgB,2BAA2B,CACzC,UAAsB;IAEtB,OAAO;QACL,CAAC,qDAA8B,CAAC,EAAE,UAAU,CAAC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ACnE,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,YAAY;SAChB,IAAI,CAAC,QAAQ,CAAC,EAAE;QACf,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QAC/D,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,CAAC,EAAE;QACX,cAAc,CAAC,IAAI,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;IAED,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAU,EAAE,QAAa,EAAO,EAAE;QAC/D,GAAG;YACD,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC;YAC3B,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QAEnE,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;AAxBD,wDAwBC","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 SEMATTRS_DB_MONGODB_COLLECTION,\n SEMATTRS_DB_NAME,\n SEMATTRS_DB_USER,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n} from '@opentelemetry/semantic-conventions';\n\nexport function getAttributesFromCollection(\n collection: Collection\n): Attributes {\n return {\n [SEMATTRS_DB_MONGODB_COLLECTION]: collection.name,\n [SEMATTRS_DB_NAME]: collection.conn.name,\n [SEMATTRS_DB_USER]: collection.conn.user,\n [SEMATTRS_NET_PEER_NAME]: collection.conn.host,\n [SEMATTRS_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 }\n\n args[callbackArgumentIndex] = (err: Error, response: any): any => {\n err\n ? setErrorStatus(span, err)\n : applyResponseHook(span, response, responseHook, moduleVersion);\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,oEAAwE;AACxE,8EAM6C;AAE7C,SAAgB,2BAA2B,CACzC,UAAsB;IAEtB,OAAO;QACL,CAAC,qDAA8B,CAAC,EAAE,UAAU,CAAC,IAAI;QACjD,CAAC,uCAAgB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QACxC,CAAC,uCAAgB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QACxC,CAAC,6CAAsB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;QAC9C,CAAC,6CAAsB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI;KAC/C,CAAC;AACJ,CAAC;AAVD,kEAUC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,QAAa,EAAE;IACjD,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAE5B,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,oBAAc,CAAC,KAAK;QAC1B,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,IACvB,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ACd,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,GAAG;YACD,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC;YAC3B,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QAEnE,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;AA1BD,wDA0BC","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 SEMATTRS_DB_MONGODB_COLLECTION,\n SEMATTRS_DB_NAME,\n SEMATTRS_DB_USER,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_PORT,\n} from '@opentelemetry/semantic-conventions';\n\nexport function getAttributesFromCollection(\n collection: Collection\n): Attributes {\n return {\n [SEMATTRS_DB_MONGODB_COLLECTION]: collection.name,\n [SEMATTRS_DB_NAME]: collection.conn.name,\n [SEMATTRS_DB_USER]: collection.conn.user,\n [SEMATTRS_NET_PEER_NAME]: collection.conn.host,\n [SEMATTRS_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 err\n ? setErrorStatus(span, err)\n : applyResponseHook(span, response, responseHook, moduleVersion);\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.48.0";
1
+ export declare const PACKAGE_VERSION = "0.50.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.48.0';
20
+ exports.PACKAGE_VERSION = '0.50.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.48.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.50.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-mongoose';\n"]}
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-mongoose",
3
- "version": "0.48.0",
3
+ "version": "0.50.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",
7
- "repository": "open-telemetry/opentelemetry-js-contrib",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib.git",
10
+ "directory": "packages/instrumentation-mongoose"
11
+ },
8
12
  "scripts": {
9
13
  "docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
10
14
  "test": "npm run test-v5-v6",
@@ -15,10 +19,10 @@
15
19
  "clean": "rimraf build/*",
16
20
  "lint": "eslint . --ext .ts",
17
21
  "lint:fix": "eslint . --ext .ts --fix",
18
- "lint:readme": "node ../../../scripts/lint-readme.js",
19
- "prewatch": "npm run precompile",
22
+ "lint:readme": "node ../../scripts/lint-readme.js",
20
23
  "prepublishOnly": "npm run compile",
21
- "version:update": "node ../../../scripts/version-update.js",
24
+ "version:update": "node ../../scripts/version-update.js",
25
+ "setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-mongoose",
22
26
  "compile": "tsc -p ."
23
27
  },
24
28
  "keywords": [
@@ -48,7 +52,7 @@
48
52
  },
49
53
  "devDependencies": {
50
54
  "@opentelemetry/api": "^1.3.0",
51
- "@opentelemetry/contrib-test-utils": "^0.47.0",
55
+ "@opentelemetry/contrib-test-utils": "^0.49.0",
52
56
  "@opentelemetry/sdk-trace-base": "^2.0.0",
53
57
  "@types/mocha": "10.0.10",
54
58
  "@types/node": "18.18.14",
@@ -61,9 +65,9 @@
61
65
  },
62
66
  "dependencies": {
63
67
  "@opentelemetry/core": "^2.0.0",
64
- "@opentelemetry/instrumentation": "^0.201.0",
68
+ "@opentelemetry/instrumentation": "^0.203.0",
65
69
  "@opentelemetry/semantic-conventions": "^1.27.0"
66
70
  },
67
- "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose#readme",
68
- "gitHead": "393b51596dc869983a03ce8857658029ca122a15"
71
+ "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mongoose#readme",
72
+ "gitHead": "e7960a2061c0a039ffa57ed8dbb73d605d65f4f6"
69
73
  }