@opentelemetry/instrumentation-mongodb
Advanced tools
Comparing version 0.51.0 to 0.52.0
@@ -8,2 +8,3 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
constructor(config?: MongoDBInstrumentationConfig); | ||
setConfig(config?: MongoDBInstrumentationConfig): void; | ||
_updateMetricInstruments(): void; | ||
@@ -69,3 +70,4 @@ init(): InstrumentationNodeModuleDefinition[]; | ||
private setPoolName; | ||
private _checkSkipInstrumentation; | ||
} | ||
//# sourceMappingURL=instrumentation.d.ts.map |
@@ -25,7 +25,13 @@ "use strict"; | ||
const version_1 = require("./version"); | ||
const DEFAULT_CONFIG = { | ||
requireParentSpan: true, | ||
}; | ||
/** mongodb instrumentation plugin for OpenTelemetry */ | ||
class MongoDBInstrumentation extends instrumentation_1.InstrumentationBase { | ||
constructor(config = {}) { | ||
super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config); | ||
super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, Object.assign(Object.assign({}, DEFAULT_CONFIG), config)); | ||
} | ||
setConfig(config = {}) { | ||
super.setConfig(Object.assign(Object.assign({}, DEFAULT_CONFIG), config)); | ||
} | ||
_updateMetricInstruments() { | ||
@@ -277,4 +283,5 @@ this._connectionsUsage = this.meter.createUpDownCounter('db.client.connections.usage', { | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const resultHandler = typeof options === 'function' ? options : callback; | ||
if (!currentSpan || | ||
if (skipInstrumentation || | ||
typeof resultHandler !== 'function' || | ||
@@ -312,4 +319,5 @@ typeof ops !== 'object') { | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const resultHandler = typeof options === 'function' ? options : callback; | ||
if (!currentSpan || | ||
if (skipInstrumentation || | ||
typeof resultHandler !== 'function' || | ||
@@ -348,12 +356,10 @@ typeof cmd !== 'object') { | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const resultHandler = callback; | ||
const commandType = Object.keys(cmd)[0]; | ||
if (typeof resultHandler !== 'function' || | ||
typeof cmd !== 'object' || | ||
cmd.ismaster || | ||
cmd.hello) { | ||
if (typeof cmd !== 'object' || cmd.ismaster || cmd.hello) { | ||
return original.call(this, ns, cmd, options, callback); | ||
} | ||
let span = undefined; | ||
if (currentSpan) { | ||
if (!skipInstrumentation) { | ||
span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, { | ||
@@ -375,2 +381,3 @@ kind: api_1.SpanKind.CLIENT, | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const commandType = Object.keys(cmd)[0]; | ||
@@ -382,3 +389,3 @@ const resultHandler = () => undefined; | ||
let span = undefined; | ||
if (currentSpan) { | ||
if (!skipInstrumentation) { | ||
span = instrumentation.tracer.startSpan(`mongodb.${commandType}`, { | ||
@@ -402,4 +409,5 @@ kind: api_1.SpanKind.CLIENT, | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const resultHandler = typeof options === 'function' ? options : callback; | ||
if (!currentSpan || | ||
if (skipInstrumentation || | ||
typeof resultHandler !== 'function' || | ||
@@ -435,4 +443,5 @@ typeof cmd !== 'object') { | ||
const currentSpan = api_1.trace.getSpan(api_1.context.active()); | ||
const skipInstrumentation = instrumentation._checkSkipInstrumentation(currentSpan); | ||
const resultHandler = typeof options === 'function' ? options : callback; | ||
if (!currentSpan || typeof resultHandler !== 'function') { | ||
if (skipInstrumentation || typeof resultHandler !== 'function') { | ||
if (typeof options === 'function') { | ||
@@ -661,4 +670,9 @@ return original.call(this, server, ns, cursorState, batchSize, options); | ||
} | ||
_checkSkipInstrumentation(currentSpan) { | ||
const requireParentSpan = this.getConfig().requireParentSpan; | ||
const hasNoParentSpan = currentSpan === undefined; | ||
return requireParentSpan === true && hasNoParentSpan; | ||
} | ||
} | ||
exports.MongoDBInstrumentation = MongoDBInstrumentation; | ||
//# sourceMappingURL=instrumentation.js.map |
@@ -31,2 +31,6 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
dbStatementSerializer?: DbStatementSerializer; | ||
/** | ||
* Require parent to create mongodb span, default when unset is true | ||
*/ | ||
requireParentSpan?: boolean; | ||
} | ||
@@ -33,0 +37,0 @@ export interface MongoResponseHookInformation { |
@@ -1,3 +0,3 @@ | ||
export declare const PACKAGE_VERSION = "0.51.0"; | ||
export declare const PACKAGE_VERSION = "0.52.0"; | ||
export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-mongodb"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.PACKAGE_VERSION = '0.51.0'; | ||
exports.PACKAGE_VERSION = '0.52.0'; | ||
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-mongodb'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-mongodb", | ||
"version": "0.51.0", | ||
"version": "0.52.0", | ||
"description": "OpenTelemetry instrumentation for `mongodb` database client for MongoDB", | ||
@@ -10,8 +10,11 @@ "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-v5-v6", | ||
"test-v3": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'", | ||
"test-v4": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'", | ||
"test-v5-v6": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'", | ||
"test": "npm run test-v3 && npm run test-v4 && npm run test-v5-v6 && nyc merge .nyc_output ./coverage/coverage-final.json", | ||
"test-v3": "tav mongodb 3.7.4 npm run test-v3-run", | ||
"test-v4": "tav mongodb 4.17.0 npm run test-v4-run", | ||
"test-v5-v6": "npm run test-v5-v6-run", | ||
"test-v3-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'", | ||
"test-v4-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'", | ||
"test-v5-v6-run": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'", | ||
"test-all-versions": "tav", | ||
"tdd": "npm run test -- --watch-extensions ts --watch", | ||
"tdd": "npm run test-v5-v6-run -- --watch-extensions ts --watch", | ||
"clean": "rimraf build/*", | ||
@@ -54,3 +57,3 @@ "lint": "eslint . --ext .ts", | ||
"@opentelemetry/context-async-hooks": "^1.8.0", | ||
"@opentelemetry/contrib-test-utils": "^0.45.0", | ||
"@opentelemetry/contrib-test-utils": "^0.45.1", | ||
"@opentelemetry/sdk-metrics": "^1.9.1", | ||
@@ -69,7 +72,7 @@ "@opentelemetry/sdk-trace-base": "^1.8.0", | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.57.0", | ||
"@opentelemetry/instrumentation": "^0.57.1", | ||
"@opentelemetry/semantic-conventions": "^1.27.0" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme", | ||
"gitHead": "3ef5205e5353010184c69ff7b9f0f4830f0932de" | ||
"gitHead": "1eb77007669bae87fe5664d68ba6533b95275d52" | ||
} |
@@ -57,2 +57,3 @@ # OpenTelemetry MongoDB Instrumentation for Node.js | ||
| `dbStatementSerializer` | `DbStatementSerializer` (function) | Custom serializer function for the db.statement tag | | ||
| `requireParentSpan` | `boolean` | Require a parent span in order to create mongodb spans, default when unset is `true` | | ||
@@ -59,0 +60,0 @@ ## Semantic Conventions |
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
133685
1011
90
+ Addedacorn@8.14.0(transitive)
- Removedacorn@8.14.1(transitive)