@opentelemetry/instrumentation-mongodb
Advanced tools
Comparing version 0.41.0 to 0.42.0
@@ -25,3 +25,4 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
/** Creates spans for command operation */ | ||
private _getV4PatchCommand; | ||
private _getV4PatchCommandCallback; | ||
private _getV4PatchCommandPromise; | ||
/** Creates spans for find operation */ | ||
@@ -28,0 +29,0 @@ private _getV3PatchFind; |
@@ -39,3 +39,3 @@ "use strict"; | ||
const { v4PatchConnect, v4UnpatchConnect } = this._getV4ConnectPatches(); | ||
const { v4PatchConnection, v4UnpatchConnection } = this._getV4ConnectionPatches(); | ||
const { v4PatchConnectionCallback, v4PatchConnectionPromise, v4UnpatchConnection, } = this._getV4ConnectionPatches(); | ||
const { v4PatchConnectionPool, v4UnpatchConnectionPool } = this._getV4ConnectionPoolPatches(); | ||
@@ -47,7 +47,8 @@ const { v4PatchSessions, v4UnpatchSessions } = this._getV4SessionsPatches(); | ||
]), | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['4.*', '5.*', '>=6 <6.4'], undefined, undefined, [ | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnection, v4UnpatchConnection), | ||
new instrumentation_1.InstrumentationNodeModuleDefinition('mongodb', ['4.*', '5.*', '6.*'], undefined, undefined, [ | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnectionCallback, v4UnpatchConnection), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection.js', ['>=6.4'], v4PatchConnectionPromise, v4UnpatchConnection), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connection_pool.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnectionPool, v4UnpatchConnectionPool), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchConnect, v4UnpatchConnect), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['4.*', '5.*', '>=6 <6.4'], v4PatchSessions, v4UnpatchSessions), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/cmap/connect.js', ['4.*', '5.*', '6.*'], v4PatchConnect, v4UnpatchConnect), | ||
new instrumentation_1.InstrumentationNodeModuleFile('mongodb/lib/sessions.js', ['4.*', '5.*', '6.*'], v4PatchSessions, v4UnpatchSessions), | ||
]), | ||
@@ -229,2 +230,14 @@ ]; | ||
return function patchedConnect(options, callback) { | ||
// from v6.4 `connect` method only accepts an options param and returns a promise | ||
// with the connection | ||
if (original.length === 1) { | ||
const result = original.call(this, options); | ||
if (result && typeof result.then === 'function') { | ||
result.then(() => instrumentation.setPoolName(options), | ||
// this handler is set to pass the lint rules | ||
() => undefined); | ||
} | ||
return result; | ||
} | ||
// Earlier versions expects a callback param and return void | ||
const patchedCallback = function (err, conn) { | ||
@@ -245,3 +258,3 @@ if (err || !conn) { | ||
return { | ||
v4PatchConnection: (moduleExports, moduleVersion) => { | ||
v4PatchConnectionCallback: (moduleExports, moduleVersion) => { | ||
api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`); | ||
@@ -252,5 +265,14 @@ // patch insert operation | ||
} | ||
this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommand()); | ||
this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommandCallback()); | ||
return moduleExports; | ||
}, | ||
v4PatchConnectionPromise: (moduleExports, moduleVersion) => { | ||
api_1.diag.debug(`Applying patch for mongodb@${moduleVersion}`); | ||
// patch insert operation | ||
if ((0, instrumentation_1.isWrapped)(moduleExports.Connection.prototype.command)) { | ||
this._unwrap(moduleExports.Connection.prototype, 'command'); | ||
} | ||
this._wrap(moduleExports.Connection.prototype, 'command', this._getV4PatchCommandPromise()); | ||
return moduleExports; | ||
}, | ||
v4UnpatchConnection: (moduleExports, moduleVersion) => { | ||
@@ -334,3 +356,3 @@ if (moduleExports === undefined) | ||
/** Creates spans for command operation */ | ||
_getV4PatchCommand() { | ||
_getV4PatchCommandCallback() { | ||
const instrumentation = this; | ||
@@ -348,14 +370,35 @@ return (original) => { | ||
} | ||
if (!currentSpan) { | ||
const patchedCallback = instrumentation._patchEnd(undefined, resultHandler, this.id, commandType); | ||
return original.call(this, ns, cmd, options, patchedCallback); | ||
let span = undefined; | ||
if (currentSpan) { | ||
span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, { | ||
kind: api_1.SpanKind.CLIENT, | ||
}); | ||
instrumentation._populateV4Attributes(span, this, ns, cmd, commandType); | ||
} | ||
else { | ||
const span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, { | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType); | ||
return original.call(this, ns, cmd, options, patchedCallback); | ||
}; | ||
}; | ||
} | ||
_getV4PatchCommandPromise() { | ||
const instrumentation = this; | ||
return (original) => { | ||
return function patchedV4ServerCommand(ns, cmd, options) { | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const commandType = Object.keys(cmd)[0]; | ||
const resultHandler = () => undefined; | ||
if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) { | ||
return original.call(this, ns, cmd, options); | ||
} | ||
let span = undefined; | ||
if (currentSpan) { | ||
span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, { | ||
kind: api_1.SpanKind.CLIENT, | ||
}); | ||
instrumentation._populateV4Attributes(span, this, ns, cmd, commandType); | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType); | ||
return original.call(this, ns, cmd, options, patchedCallback); | ||
} | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler, this.id, commandType); | ||
const result = original.call(this, ns, cmd, options); | ||
result.then((res) => patchedCallback(null, res), (err) => patchedCallback(err)); | ||
return result; | ||
}; | ||
@@ -362,0 +405,0 @@ }; |
@@ -95,3 +95,5 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
export declare type V4Connection = { | ||
command(ns: any, cmd: Document, options: undefined | unknown, callback: any): void; | ||
command: Function; | ||
commandPromise(ns: any, cmd: Document, options: undefined | unknown): Promise<any>; | ||
commandCallback(ns: any, cmd: Document, options: undefined | unknown, callback: any): void; | ||
}; | ||
@@ -102,3 +104,5 @@ export declare type V4ConnectionPool = { | ||
export declare type V4Connect = { | ||
connect: (options: any, callback: any) => void; | ||
connect: Function; | ||
connectPromise: (options: any) => Promise<any>; | ||
connectCallback: (options: any, callback: any) => void; | ||
}; | ||
@@ -105,0 +109,0 @@ export declare type V4Session = { |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.41.0"; | ||
export declare const VERSION = "0.42.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.41.0'; | ||
exports.VERSION = '0.42.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-mongodb", | ||
"version": "0.41.0", | ||
"version": "0.42.0", | ||
"description": "OpenTelemetry mongodb automatic instrumentation package.", | ||
@@ -10,3 +10,3 @@ "main": "build/src/index.js", | ||
"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", | ||
"test": "npm run test-v3", | ||
"test": "npm run test-v5-v6", | ||
"test-v3": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'", | ||
@@ -54,3 +54,3 @@ "test-v4": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'", | ||
"@opentelemetry/context-async-hooks": "^1.8.0", | ||
"@opentelemetry/contrib-test-utils": "^0.37.0", | ||
"@opentelemetry/contrib-test-utils": "^0.38.0", | ||
"@opentelemetry/sdk-trace-base": "^1.8.0", | ||
@@ -63,3 +63,3 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", | ||
"mocha": "7.2.0", | ||
"mongodb": "3.6.11", | ||
"mongodb": "6.5.0", | ||
"nyc": "15.1.0", | ||
@@ -72,3 +72,3 @@ "rimraf": "5.0.5", | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.49.1", | ||
"@opentelemetry/instrumentation": "^0.50.0", | ||
"@opentelemetry/sdk-metrics": "^1.9.1", | ||
@@ -78,3 +78,3 @@ "@opentelemetry/semantic-conventions": "^1.0.0" | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme", | ||
"gitHead": "9d19ca4103bc72bd42e28979fee19bd08d85b721" | ||
"gitHead": "17a0bc1da3baa472ba9b867eee3c60730cc130fb" | ||
} |
@@ -1,2 +0,2 @@ | ||
# OpenTelemetry mongodb Instrumentation for Node.js | ||
# OpenTelemetry MongoDB Instrumentation for Node.js | ||
@@ -24,3 +24,3 @@ [![NPM Published Version][npm-img]][npm-url] | ||
OpenTelemetry Mongodb Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. | ||
OpenTelemetry MongoDB Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems. | ||
@@ -27,0 +27,0 @@ To load a specific instrumentation (**mongodb** in this case), specify it in the Node Tracer's configuration. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129776
979
+ Added@opentelemetry/api-logs@0.50.0(transitive)
+ Added@opentelemetry/instrumentation@0.50.0(transitive)
- Removed@opentelemetry/api-logs@0.49.1(transitive)
- Removed@opentelemetry/instrumentation@0.49.1(transitive)