Skip to content

Commit

Permalink
cr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik committed Aug 30, 2021
1 parent c93e767 commit aa00598
Showing 1 changed file with 15 additions and 17 deletions.
Expand Up @@ -41,7 +41,6 @@ import {
CommandResult,
} from './types';
import { VERSION } from './version';
import { DbStatementSerializer } from './types';

const supportedVersions = ['>=3.3 <4'];

Expand Down Expand Up @@ -410,24 +409,23 @@ 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);
span.setAttribute(SemanticAttributes.DB_STATEMENT, query);
},
err => {
if (err) {
this._diag.error('Error running dbStatementSerializer hook', err);
}
},
true
);
}
safeExecuteInTheMiddle(
() => {
const query = dbStatementSerializer(commandObj);
span.setAttribute(SemanticAttributes.DB_STATEMENT, query);
},
err => {
if (err) {
this._diag.error('Error running dbStatementSerializer hook', err);
}
},
true
);
}

private _defaultDbStatementSerializer(commandObj: Record<string, unknown>) {
Expand Down

0 comments on commit aa00598

Please sign in to comment.