diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts index ad1780d996..2cb1720846 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts @@ -410,11 +410,11 @@ export class MongoDBInstrumentation extends InstrumentationBase< // capture parameters within the query as well if enhancedDatabaseReporting is enabled. const commandObj = command.query ?? command.q ?? command; - const dbStatementSerializer: DbStatementSerializer = - this._config.dbStatementSerializer || + const dbStatementSerializer = + typeof this._config.dbStatementSerializer === 'function' ? + this._config.dbStatementSerializer : this._defaultDbStatementSerializer.bind(this); - if (typeof dbStatementSerializer === 'function') { safeExecuteInTheMiddle( () => { const query = dbStatementSerializer(commandObj); @@ -427,7 +427,6 @@ export class MongoDBInstrumentation extends InstrumentationBase< }, true ); - } } private _defaultDbStatementSerializer(commandObj: Record) {