@opentelemetry/instrumentation-mongodb
Advanced tools
Comparing version 0.15.0 to 0.16.0
@@ -0,4 +1,4 @@ | ||
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
import type * as mongodb from 'mongodb'; | ||
import { MongoDBInstrumentationConfig } from './types'; | ||
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
/** mongodb instrumentation plugin for OpenTelemetry */ | ||
@@ -5,0 +5,0 @@ export declare class MongoDBInstrumentation extends InstrumentationBase<typeof mongodb> { |
@@ -20,6 +20,6 @@ "use strict"; | ||
const api_1 = require("@opentelemetry/api"); | ||
const instrumentation_1 = require("@opentelemetry/instrumentation"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const types_1 = require("./types"); | ||
const version_1 = require("./version"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const instrumentation_1 = require("@opentelemetry/instrumentation"); | ||
const supportedVersions = ['>=3.3 <4']; | ||
@@ -99,3 +99,8 @@ /** mongodb instrumentation plugin for OpenTelemetry */ | ||
typeof ops !== 'object') { | ||
return original.call(this, server, ns, ops, typeof options === 'function' ? callback : options, callback); | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, ops, options); | ||
} | ||
else { | ||
return original.call(this, server, ns, ops, options, callback); | ||
} | ||
} | ||
@@ -109,3 +114,9 @@ const span = instrumentation.tracer.startSpan(`mongodb.${operationName}`, { | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler); | ||
return original.call(this, server, ns, ops, typeof options === 'function' ? patchedCallback : options, patchedCallback); | ||
// handle when options is the callback to send the correct number of args | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, ops, patchedCallback); | ||
} | ||
else { | ||
return original.call(this, server, ns, ops, options, patchedCallback); | ||
} | ||
}; | ||
@@ -124,3 +135,8 @@ }; | ||
typeof cmd !== 'object') { | ||
return original.call(this, server, ns, cmd, typeof options === 'function' ? callback : options, callback); | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cmd, options); | ||
} | ||
else { | ||
return original.call(this, server, ns, cmd, options, callback); | ||
} | ||
} | ||
@@ -134,3 +150,9 @@ const commandType = instrumentation._getCommandType(cmd); | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler); | ||
return original.call(this, server, ns, cmd, typeof options === 'function' ? patchedCallback : options, patchedCallback); | ||
// handle when options is the callback to send the correct number of args | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cmd, patchedCallback); | ||
} | ||
else { | ||
return original.call(this, server, ns, cmd, options, patchedCallback); | ||
} | ||
}; | ||
@@ -149,3 +171,8 @@ }; | ||
typeof cmd !== 'object') { | ||
return original.call(this, server, ns, cmd, cursorState, typeof options === 'function' ? callback : options, callback); | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cmd, cursorState, options); | ||
} | ||
else { | ||
return original.call(this, server, ns, cmd, cursorState, options, callback); | ||
} | ||
} | ||
@@ -157,3 +184,9 @@ const span = instrumentation.tracer.startSpan('mongodb.find', { | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler); | ||
return original.call(this, server, ns, cmd, cursorState, typeof options === 'function' ? patchedCallback : options, patchedCallback); | ||
// handle when options is the callback to send the correct number of args | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cmd, cursorState, patchedCallback); | ||
} | ||
else { | ||
return original.call(this, server, ns, cmd, cursorState, options, patchedCallback); | ||
} | ||
}; | ||
@@ -170,3 +203,8 @@ }; | ||
if (!currentSpan || typeof resultHandler !== 'function') { | ||
return original.call(this, server, ns, cursorState, batchSize, typeof options === 'function' ? callback : options, callback); | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cursorState, batchSize, options); | ||
} | ||
else { | ||
return original.call(this, server, ns, cursorState, batchSize, options, callback); | ||
} | ||
} | ||
@@ -178,3 +216,9 @@ const span = instrumentation.tracer.startSpan('mongodb.getMore', { | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler); | ||
return original.call(this, server, ns, cursorState, batchSize, typeof options === 'function' ? patchedCallback : options, patchedCallback); | ||
// handle when options is the callback to send the correct number of args | ||
if (typeof options === 'function') { | ||
return original.call(this, server, ns, cursorState, batchSize, patchedCallback); | ||
} | ||
else { | ||
return original.call(this, server, ns, cursorState, batchSize, options, patchedCallback); | ||
} | ||
}; | ||
@@ -216,4 +260,4 @@ }; | ||
span.setAttributes({ | ||
[semantic_conventions_1.GeneralAttribute.NET_HOST_NAME]: `${(_b = (_a = topology.s.options) === null || _a === void 0 ? void 0 : _a.host) !== null && _b !== void 0 ? _b : topology.s.host}`, | ||
[semantic_conventions_1.GeneralAttribute.NET_HOST_PORT]: `${(_d = (_c = topology.s.options) === null || _c === void 0 ? void 0 : _c.port) !== null && _d !== void 0 ? _d : topology.s.port}`, | ||
[semantic_conventions_1.SemanticAttributes.NET_HOST_NAME]: `${(_b = (_a = topology.s.options) === null || _a === void 0 ? void 0 : _a.host) !== null && _b !== void 0 ? _b : topology.s.host}`, | ||
[semantic_conventions_1.SemanticAttributes.NET_HOST_PORT]: `${(_d = (_c = topology.s.options) === null || _c === void 0 ? void 0 : _c.port) !== null && _d !== void 0 ? _d : topology.s.port}`, | ||
}); | ||
@@ -228,5 +272,5 @@ } | ||
span.setAttributes({ | ||
[semantic_conventions_1.DatabaseAttribute.DB_SYSTEM]: 'mongodb', | ||
[semantic_conventions_1.DatabaseAttribute.DB_NAME]: dbName, | ||
[semantic_conventions_1.DatabaseAttribute.DB_MONGODB_COLLECTION]: dbCollection, | ||
[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: 'mongodb', | ||
[semantic_conventions_1.SemanticAttributes.DB_NAME]: dbName, | ||
[semantic_conventions_1.SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection, | ||
}); | ||
@@ -243,3 +287,3 @@ if (command === undefined) | ||
}, {}); | ||
span.setAttribute(semantic_conventions_1.DatabaseAttribute.DB_STATEMENT, JSON.stringify(query)); | ||
span.setAttribute(semantic_conventions_1.SemanticAttributes.DB_STATEMENT, JSON.stringify(query)); | ||
} | ||
@@ -252,2 +296,5 @@ /** | ||
_patchEnd(span, resultHandler) { | ||
// mongodb is using "tick" when calling a callback, this way the context | ||
// in final callback (resultHandler) is lost | ||
const activeContext = api_1.context.active(); | ||
return function patchedEnd(...args) { | ||
@@ -262,3 +309,5 @@ const error = args[0]; | ||
span.end(); | ||
return resultHandler.apply(this, args); | ||
return api_1.context.with(activeContext, () => { | ||
return resultHandler.apply(this, args); | ||
}); | ||
}; | ||
@@ -265,0 +314,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.15.0"; | ||
export declare const VERSION = "0.16.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.15.0'; | ||
exports.VERSION = '0.16.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-mongodb", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "OpenTelemetry mongodb automatic instrumentation package.", | ||
@@ -9,2 +9,3 @@ "main": "build/src/index.js", | ||
"scripts": { | ||
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=localhost -p 27017:27017 --rm mongo", | ||
"test": "nyc ts-mocha --parallel -p tsconfig.json 'test/**/*.test.ts'", | ||
@@ -19,3 +20,4 @@ "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", | ||
"compile": "npm run version:update && tsc -p .", | ||
"prepare": "npm run compile" | ||
"prepare": "npm run compile", | ||
"watch": "tsc -w" | ||
}, | ||
@@ -46,5 +48,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"@opentelemetry/context-async-hooks": "0.18.2", | ||
"@opentelemetry/node": "0.18.2", | ||
"@opentelemetry/tracing": "0.18.2", | ||
"@opentelemetry/context-async-hooks": "0.19.0", | ||
"@opentelemetry/node": "0.19.0", | ||
"@opentelemetry/tracing": "0.19.0", | ||
"@types/mocha": "7.0.2", | ||
@@ -60,3 +62,2 @@ "@types/mongodb": "3.5.25", | ||
"ts-mocha": "8.0.0", | ||
"ts-node": "9.0.0", | ||
"tslint-consistent-codestyle": "1.16.0", | ||
@@ -67,7 +68,7 @@ "tslint-microsoft-contrib": "6.2.0", | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.18.0", | ||
"@opentelemetry/instrumentation": "^0.18.0", | ||
"@opentelemetry/semantic-conventions": "^0.18.0" | ||
"@opentelemetry/api": "^1.0.0-rc.0", | ||
"@opentelemetry/instrumentation": "^0.19.0", | ||
"@opentelemetry/semantic-conventions": "^0.19.0" | ||
}, | ||
"gitHead": "a2de7757da17a026433f0735035f65f7f88f1666" | ||
"gitHead": "5ecccc916e8f4eecaf6629a0350fc672edcba1be" | ||
} |
@@ -28,12 +28,18 @@ # OpenTelemetry mongodb Instrumentation for Node.js | ||
```javascript | ||
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb'); | ||
const { NodeTracerProvider } = require('@opentelemetry/node'); | ||
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb'); | ||
const { registerInstrumentations } = require('@opentelemetry/instrumentation'); | ||
const provider = new NodeTracerProvider(); | ||
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); | ||
provider.register(); | ||
const mongodbInstrumentation = new MongoDBInstrumentation({ | ||
// see under for available configuration | ||
registerInstrumentations({ | ||
instrumentations: [ | ||
new MongoDBInstrumentation({ | ||
// see under for available configuration | ||
}), | ||
], | ||
tracerProvider: provider, | ||
}); | ||
``` | ||
@@ -40,0 +46,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39114
16
467
73
0
+ Added@opentelemetry/api@1.9.0(transitive)
+ Added@opentelemetry/api-metrics@0.19.0(transitive)
+ Added@opentelemetry/instrumentation@0.19.0(transitive)
+ Added@opentelemetry/semantic-conventions@0.19.0(transitive)
- Removed@opentelemetry/api@0.18.1(transitive)
- Removed@opentelemetry/api-metrics@0.18.2(transitive)
- Removed@opentelemetry/instrumentation@0.18.2(transitive)
- Removed@opentelemetry/semantic-conventions@0.18.2(transitive)