@opentelemetry/instrumentation-mongoose 0.52.0 → 0.52.3
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/build/src/mongoose.js +7 -7
- package/build/src/mongoose.js.map +1 -1
- package/build/src/semconv.d.ts +84 -0
- package/build/src/semconv.js +107 -0
- package/build/src/semconv.js.map +1 -0
- package/build/src/utils.js +6 -6
- package/build/src/utils.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +4 -6
package/build/src/mongoose.js
CHANGED
|
@@ -22,7 +22,7 @@ const utils_1 = require("./utils");
|
|
|
22
22
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
23
23
|
/** @knipignore */
|
|
24
24
|
const version_1 = require("./version");
|
|
25
|
-
const
|
|
25
|
+
const semconv_1 = require("./semconv");
|
|
26
26
|
const contextCaptureFunctionsCommon = [
|
|
27
27
|
'deleteOne',
|
|
28
28
|
'deleteMany',
|
|
@@ -137,7 +137,7 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
137
137
|
const attributes = {};
|
|
138
138
|
const { dbStatementSerializer } = self.getConfig();
|
|
139
139
|
if (dbStatementSerializer) {
|
|
140
|
-
attributes[
|
|
140
|
+
attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer('aggregate', {
|
|
141
141
|
options: this.options,
|
|
142
142
|
aggregatePipeline: this._pipeline,
|
|
143
143
|
});
|
|
@@ -159,7 +159,7 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
159
159
|
const attributes = {};
|
|
160
160
|
const { dbStatementSerializer } = self.getConfig();
|
|
161
161
|
if (dbStatementSerializer) {
|
|
162
|
-
attributes[
|
|
162
|
+
attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(this.op, {
|
|
163
163
|
condition: this._conditions,
|
|
164
164
|
updates: this._update,
|
|
165
165
|
options: this.options,
|
|
@@ -186,7 +186,7 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
186
186
|
const attributes = {};
|
|
187
187
|
const { dbStatementSerializer } = self.getConfig();
|
|
188
188
|
if (dbStatementSerializer) {
|
|
189
|
-
attributes[
|
|
189
|
+
attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(op, serializePayload);
|
|
190
190
|
}
|
|
191
191
|
const span = self._startSpan(this.constructor.collection, this.constructor.modelName, op, attributes);
|
|
192
192
|
if (options instanceof Function) {
|
|
@@ -227,7 +227,7 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
227
227
|
const attributes = {};
|
|
228
228
|
const { dbStatementSerializer } = self.getConfig();
|
|
229
229
|
if (dbStatementSerializer) {
|
|
230
|
-
attributes[
|
|
230
|
+
attributes[semconv_1.ATTR_DB_STATEMENT] = dbStatementSerializer(op, serializePayload);
|
|
231
231
|
}
|
|
232
232
|
const span = self._startSpan(this.collection, this.modelName, op, attributes);
|
|
233
233
|
return self._handleResponse(span, original, this, arguments, callback, moduleVersion);
|
|
@@ -265,8 +265,8 @@ class MongooseInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
265
265
|
attributes: {
|
|
266
266
|
...attributes,
|
|
267
267
|
...(0, utils_1.getAttributesFromCollection)(collection),
|
|
268
|
-
[
|
|
269
|
-
[
|
|
268
|
+
[semconv_1.ATTR_DB_OPERATION]: operation,
|
|
269
|
+
[semconv_1.ATTR_DB_SYSTEM]: 'mongoose',
|
|
270
270
|
},
|
|
271
271
|
}, parentSpan ? api_1.trace.setSpan(api_1.context.active(), parentSpan) : undefined);
|
|
272
272
|
}
|
|
@@ -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;A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,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;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"]}
|
|
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,kBA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,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"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deprecated, use `db.collection.name` instead.
|
|
3
|
+
*
|
|
4
|
+
* @example "mytable"
|
|
5
|
+
*
|
|
6
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Replaced by `db.collection.name`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ATTR_DB_MONGODB_COLLECTION: "db.mongodb.collection";
|
|
11
|
+
/**
|
|
12
|
+
* Deprecated, use `db.namespace` instead.
|
|
13
|
+
*
|
|
14
|
+
* @example customers
|
|
15
|
+
* @example main
|
|
16
|
+
*
|
|
17
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Replaced by `db.namespace`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ATTR_DB_NAME: "db.name";
|
|
22
|
+
/**
|
|
23
|
+
* Deprecated, use `db.operation.name` instead.
|
|
24
|
+
*
|
|
25
|
+
* @example findAndModify
|
|
26
|
+
* @example HMSET
|
|
27
|
+
* @example SELECT
|
|
28
|
+
*
|
|
29
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Replaced by `db.operation.name`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const ATTR_DB_OPERATION: "db.operation";
|
|
34
|
+
/**
|
|
35
|
+
* The database statement being executed.
|
|
36
|
+
*
|
|
37
|
+
* @example SELECT * FROM wuser_table
|
|
38
|
+
* @example SET mykey "WuValue"
|
|
39
|
+
*
|
|
40
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Replaced by `db.query.text`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ATTR_DB_STATEMENT: "db.statement";
|
|
45
|
+
/**
|
|
46
|
+
* Deprecated, use `db.system.name` instead.
|
|
47
|
+
*
|
|
48
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Replaced by `db.system.name`.
|
|
51
|
+
*/
|
|
52
|
+
export declare const ATTR_DB_SYSTEM: "db.system";
|
|
53
|
+
/**
|
|
54
|
+
* Deprecated, no replacement at this time.
|
|
55
|
+
*
|
|
56
|
+
* @example readonly_user
|
|
57
|
+
* @example reporting_user
|
|
58
|
+
*
|
|
59
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Removed, no replacement at this time.
|
|
62
|
+
*/
|
|
63
|
+
export declare const ATTR_DB_USER: "db.user";
|
|
64
|
+
/**
|
|
65
|
+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
|
|
66
|
+
*
|
|
67
|
+
* @example example.com
|
|
68
|
+
*
|
|
69
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
70
|
+
*
|
|
71
|
+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
|
|
72
|
+
*/
|
|
73
|
+
export declare const ATTR_NET_PEER_NAME: "net.peer.name";
|
|
74
|
+
/**
|
|
75
|
+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
|
|
76
|
+
*
|
|
77
|
+
* @example 8080
|
|
78
|
+
*
|
|
79
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
80
|
+
*
|
|
81
|
+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
|
|
82
|
+
*/
|
|
83
|
+
export declare const ATTR_NET_PEER_PORT: "net.peer.port";
|
|
84
|
+
//# sourceMappingURL=semconv.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
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;
|
|
19
|
+
/*
|
|
20
|
+
* This file contains a copy of unstable semantic convention definitions
|
|
21
|
+
* used by this package.
|
|
22
|
+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Deprecated, use `db.collection.name` instead.
|
|
26
|
+
*
|
|
27
|
+
* @example "mytable"
|
|
28
|
+
*
|
|
29
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Replaced by `db.collection.name`.
|
|
32
|
+
*/
|
|
33
|
+
exports.ATTR_DB_MONGODB_COLLECTION = 'db.mongodb.collection';
|
|
34
|
+
/**
|
|
35
|
+
* Deprecated, use `db.namespace` instead.
|
|
36
|
+
*
|
|
37
|
+
* @example customers
|
|
38
|
+
* @example main
|
|
39
|
+
*
|
|
40
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Replaced by `db.namespace`.
|
|
43
|
+
*/
|
|
44
|
+
exports.ATTR_DB_NAME = 'db.name';
|
|
45
|
+
/**
|
|
46
|
+
* Deprecated, use `db.operation.name` instead.
|
|
47
|
+
*
|
|
48
|
+
* @example findAndModify
|
|
49
|
+
* @example HMSET
|
|
50
|
+
* @example SELECT
|
|
51
|
+
*
|
|
52
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Replaced by `db.operation.name`.
|
|
55
|
+
*/
|
|
56
|
+
exports.ATTR_DB_OPERATION = 'db.operation';
|
|
57
|
+
/**
|
|
58
|
+
* The database statement being executed.
|
|
59
|
+
*
|
|
60
|
+
* @example SELECT * FROM wuser_table
|
|
61
|
+
* @example SET mykey "WuValue"
|
|
62
|
+
*
|
|
63
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
64
|
+
*
|
|
65
|
+
* @deprecated Replaced by `db.query.text`.
|
|
66
|
+
*/
|
|
67
|
+
exports.ATTR_DB_STATEMENT = 'db.statement';
|
|
68
|
+
/**
|
|
69
|
+
* Deprecated, use `db.system.name` instead.
|
|
70
|
+
*
|
|
71
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
72
|
+
*
|
|
73
|
+
* @deprecated Replaced by `db.system.name`.
|
|
74
|
+
*/
|
|
75
|
+
exports.ATTR_DB_SYSTEM = 'db.system';
|
|
76
|
+
/**
|
|
77
|
+
* Deprecated, no replacement at this time.
|
|
78
|
+
*
|
|
79
|
+
* @example readonly_user
|
|
80
|
+
* @example reporting_user
|
|
81
|
+
*
|
|
82
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
83
|
+
*
|
|
84
|
+
* @deprecated Removed, no replacement at this time.
|
|
85
|
+
*/
|
|
86
|
+
exports.ATTR_DB_USER = 'db.user';
|
|
87
|
+
/**
|
|
88
|
+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
|
|
89
|
+
*
|
|
90
|
+
* @example example.com
|
|
91
|
+
*
|
|
92
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
93
|
+
*
|
|
94
|
+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
|
|
95
|
+
*/
|
|
96
|
+
exports.ATTR_NET_PEER_NAME = 'net.peer.name';
|
|
97
|
+
/**
|
|
98
|
+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
|
|
99
|
+
*
|
|
100
|
+
* @example 8080
|
|
101
|
+
*
|
|
102
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
103
|
+
*
|
|
104
|
+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
|
|
105
|
+
*/
|
|
106
|
+
exports.ATTR_NET_PEER_PORT = 'net.peer.port';
|
|
107
|
+
//# sourceMappingURL=semconv.js.map
|
|
@@ -0,0 +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"]}
|
package/build/src/utils.js
CHANGED
|
@@ -18,14 +18,14 @@ exports.handleCallbackResponse = exports.handlePromiseResponse = exports.getAttr
|
|
|
18
18
|
*/
|
|
19
19
|
const api_1 = require("@opentelemetry/api");
|
|
20
20
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
21
|
-
const
|
|
21
|
+
const semconv_1 = require("./semconv");
|
|
22
22
|
function getAttributesFromCollection(collection) {
|
|
23
23
|
return {
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
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
29
|
};
|
|
30
30
|
}
|
|
31
31
|
exports.getAttributesFromCollection = getAttributesFromCollection;
|
package/build/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4E;AAG5E,oEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;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,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 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 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"]}
|
package/build/src/version.d.ts
CHANGED
package/build/src/version.js
CHANGED
|
@@ -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.52.
|
|
20
|
+
exports.PACKAGE_VERSION = '0.52.3';
|
|
21
21
|
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mongoose';
|
|
22
22
|
//# sourceMappingURL=version.js.map
|
package/build/src/version.js.map
CHANGED
|
@@ -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.52.
|
|
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.52.3';\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.52.
|
|
3
|
+
"version": "0.52.3",
|
|
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",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
|
|
25
25
|
"test-all-versions": "tav",
|
|
26
26
|
"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",
|
|
27
|
-
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
|
|
28
27
|
"test-services:start": "cd ../.. && npm run test-services:start mongodb",
|
|
29
28
|
"test-services:stop": "cd ../.. && npm run test-services:stop mongodb",
|
|
30
29
|
"version:update": "node ../../scripts/version-update.js"
|
|
@@ -56,7 +55,7 @@
|
|
|
56
55
|
},
|
|
57
56
|
"devDependencies": {
|
|
58
57
|
"@opentelemetry/api": "^1.3.0",
|
|
59
|
-
"@opentelemetry/contrib-test-utils": "^0.
|
|
58
|
+
"@opentelemetry/contrib-test-utils": "^0.52.2",
|
|
60
59
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
61
60
|
"@types/mocha": "10.0.10",
|
|
62
61
|
"@types/node": "18.18.14",
|
|
@@ -70,9 +69,8 @@
|
|
|
70
69
|
},
|
|
71
70
|
"dependencies": {
|
|
72
71
|
"@opentelemetry/core": "^2.0.0",
|
|
73
|
-
"@opentelemetry/instrumentation": "^0.205.0"
|
|
74
|
-
"@opentelemetry/semantic-conventions": "^1.27.0"
|
|
72
|
+
"@opentelemetry/instrumentation": "^0.205.0"
|
|
75
73
|
},
|
|
76
74
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-mongoose#readme",
|
|
77
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "5a5918fd4f9f16b14c9ef4d3de08ab98c20e5b46"
|
|
78
76
|
}
|