Skip to content

Commit

Permalink
don't parse operation from raw queries
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Jun 4, 2024
1 parent ac619c1 commit cdaea83
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
16 changes: 1 addition & 15 deletions plugins/node/instrumentation-typeorm/src/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,6 @@ export class TypeormInstrumentation extends InstrumentationBase {
};
}

private getOperationName(statement: string) {
let operation = 'raw query';
if (typeof statement === 'string') {
statement = statement.trim();
try {
operation = statement.split(' ')[0].toUpperCase();
} catch (e) {
/* */
}
}

return operation;
}

private _patchRawQuery() {
const self = this;
return (original: Function) => {
Expand All @@ -358,7 +344,7 @@ export class TypeormInstrumentation extends InstrumentationBase {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sql = args[0] as any;
const operation = self.getOperationName(sql);
const operation = 'raw query';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const connectionOptions: any = this.options;
const attributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Connection', () => {
const attributes = typeOrmSpans[0].attributes;
assert.strictEqual(attributes[SEMATTRS_DB_SYSTEM], options.type);
assert.strictEqual(attributes[SEMATTRS_DB_NAME], options.database);
assert.strictEqual(attributes[SEMATTRS_DB_OPERATION], 'SELECT');
assert.strictEqual(attributes[SEMATTRS_DB_OPERATION], 'raw query');
assert.strictEqual(attributes[SEMATTRS_DB_STATEMENT], query);
await connection.close();
});
Expand Down

0 comments on commit cdaea83

Please sign in to comment.