Skip to content

Commit

Permalink
fix: use SQL verb for mysql2 span name when query object is used (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik authored Mar 2, 2022
1 parent 1b3bb5f commit 3d1388b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ export function getDbStatement(
* @returns SQL statement without variable arguments or SQL verb
*/
export function getSpanName(query: string | Query | QueryOptions): string {
if (typeof query === 'object') {
return query.sql;
}
return query.split(' ')[0];
const rawQuery = typeof query === 'object' ? query.sql : query;
// Extract the SQL verb
return rawQuery?.split(' ')?.[0];
}

export const once = (fn: Function) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ describe('mysql@2.x', () => {
query.on('end', () => {
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans[0].name, 'SELECT');
assert.strictEqual(
spans[0].attributes[SemanticAttributes.DB_STATEMENT],
sql
);
done();
});
});
Expand All @@ -161,7 +165,11 @@ describe('mysql@2.x', () => {

query.on('end', () => {
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans[0].name, sql);
assert.strictEqual(spans[0].name, 'SELECT');
assert.strictEqual(
spans[0].attributes[SemanticAttributes.DB_STATEMENT],
query.sql
);
done();
});
});
Expand Down

0 comments on commit 3d1388b

Please sign in to comment.