@opentelemetry/instrumentation-mongodb
Advanced tools
Comparing version 0.24.0 to 0.25.0
@@ -31,2 +31,3 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
private _populateAttributes; | ||
private _defaultDbStatementSerializer; | ||
/** | ||
@@ -33,0 +34,0 @@ * Triggers the response hook in case it is defined. |
@@ -110,3 +110,3 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
operationName !== 'insert' ? ops[0] : undefined); | ||
ops[0]); | ||
const patchedCallback = instrumentation._patchEnd(span, resultHandler); | ||
@@ -248,3 +248,3 @@ // handle when options is the callback to send the correct number of args | ||
_populateAttributes(span, ns, topology, command) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f; | ||
// add network attributes to determine the remote server | ||
@@ -272,3 +272,18 @@ if (topology && topology.s) { | ||
const commandObj = (_f = (_e = command.query) !== null && _e !== void 0 ? _e : command.q) !== null && _f !== void 0 ? _f : command; | ||
const query = ((_g = this._config) === null || _g === void 0 ? void 0 : _g.enhancedDatabaseReporting) === true | ||
const dbStatementSerializer = typeof this._config.dbStatementSerializer === 'function' | ||
? this._config.dbStatementSerializer | ||
: this._defaultDbStatementSerializer.bind(this); | ||
instrumentation_1.safeExecuteInTheMiddle(() => { | ||
const query = dbStatementSerializer(commandObj); | ||
span.setAttribute(semantic_conventions_1.SemanticAttributes.DB_STATEMENT, query); | ||
}, err => { | ||
if (err) { | ||
this._diag.error('Error running dbStatementSerializer hook', err); | ||
} | ||
}, true); | ||
} | ||
_defaultDbStatementSerializer(commandObj) { | ||
var _a; | ||
const enhancedDbReporting = !!((_a = this._config) === null || _a === void 0 ? void 0 : _a.enhancedDatabaseReporting); | ||
const resultObj = enhancedDbReporting | ||
? commandObj | ||
@@ -279,3 +294,3 @@ : Object.keys(commandObj).reduce((obj, key) => { | ||
}, {}); | ||
span.setAttribute(semantic_conventions_1.SemanticAttributes.DB_STATEMENT, JSON.stringify(query)); | ||
return JSON.stringify(resultObj); | ||
} | ||
@@ -282,0 +297,0 @@ /** |
@@ -6,2 +6,9 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
} | ||
/** | ||
* Function that can be used to serialize db.statement tag | ||
* @param cmd - MongoDB command object | ||
* | ||
* @returns serialized string that will be used as the db.statement attribute. | ||
*/ | ||
export declare type DbStatementSerializer = (cmd: Record<string, unknown>) => string; | ||
export interface MongoDBInstrumentationConfig extends InstrumentationConfig { | ||
@@ -21,2 +28,6 @@ /** | ||
responseHook?: MongoDBInstrumentationExecutionResponseHook; | ||
/** | ||
* Custom serializer function for the db.statement tag | ||
*/ | ||
dbStatementSerializer?: DbStatementSerializer; | ||
} | ||
@@ -23,0 +34,0 @@ export declare type Func<T> = (...args: unknown[]) => T; |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.24.0"; | ||
export declare const VERSION = "0.25.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.24.0'; | ||
exports.VERSION = '0.25.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-mongodb", | ||
"version": "0.24.0", | ||
"version": "0.25.0", | ||
"description": "OpenTelemetry mongodb automatic instrumentation package.", | ||
@@ -11,2 +11,3 @@ "main": "build/src/index.js", | ||
"test": "nyc ts-mocha --parallel -p tsconfig.json 'test/**/*.test.ts'", | ||
"test-all-versions": "tav", | ||
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", | ||
@@ -48,17 +49,18 @@ "tdd": "npm run test -- --watch-extensions ts --watch", | ||
"peerDependencies": { | ||
"@opentelemetry/api": "^1.0.1" | ||
"@opentelemetry/api": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"@opentelemetry/api": "1.0.1", | ||
"@opentelemetry/context-async-hooks": "0.24.0", | ||
"@opentelemetry/node": "0.24.0", | ||
"@opentelemetry/tracing": "0.24.0", | ||
"@opentelemetry/api": "1.0.2", | ||
"@opentelemetry/context-async-hooks": "0.25.0", | ||
"@opentelemetry/sdk-trace-base": "0.25.0", | ||
"@opentelemetry/sdk-trace-node": "0.25.0", | ||
"@types/mocha": "7.0.2", | ||
"@types/node": "14.17.5", | ||
"@types/node": "14.17.9", | ||
"codecov": "3.8.3", | ||
"gts": "3.1.0", | ||
"mocha": "7.2.0", | ||
"mongodb": "3.6.10", | ||
"mongodb": "3.6.11", | ||
"nyc": "15.1.0", | ||
"rimraf": "3.0.2", | ||
"test-all-versions": "5.0.1", | ||
"ts-mocha": "8.0.0", | ||
@@ -68,7 +70,7 @@ "typescript": "4.3.5" | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.24.0", | ||
"@opentelemetry/semantic-conventions": "^0.24.0", | ||
"@opentelemetry/instrumentation": "^0.25.0", | ||
"@opentelemetry/semantic-conventions": "^0.25.0", | ||
"@types/mongodb": "3.6.20" | ||
}, | ||
"gitHead": "e4757035a7b4012703a98b5609b8ac0f859e9726" | ||
"gitHead": "fcfaeb965804d2a081f1dc8d2b82803cd51681af" | ||
} |
@@ -11,3 +11,3 @@ # OpenTelemetry mongodb Instrumentation for Node.js | ||
For automatic instrumentation see the | ||
[@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. | ||
[@opentelemetry/sdk-trace-node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package. | ||
@@ -31,3 +31,3 @@ ## Installation | ||
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb'); | ||
const { NodeTracerProvider } = require('@opentelemetry/node'); | ||
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); | ||
const { registerInstrumentations } = require('@opentelemetry/instrumentation'); | ||
@@ -56,2 +56,3 @@ | ||
| `responseHook` | `MongoDBInstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response | | ||
| `dbStatementSerializer` | `DbStatementSerializer` (function) | Custom serializer function for the db.statement tag | | ||
@@ -58,0 +59,0 @@ ## Useful links |
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
53811
543
75
15
+ Added@opentelemetry/api-metrics@0.25.0(transitive)
+ Added@opentelemetry/instrumentation@0.25.0(transitive)
+ Added@opentelemetry/semantic-conventions@0.25.0(transitive)
- Removed@opentelemetry/api-metrics@0.24.0(transitive)
- Removed@opentelemetry/instrumentation@0.24.0(transitive)
- Removed@opentelemetry/semantic-conventions@0.24.0(transitive)