Skip to content

Commit

Permalink
fix mysql2 span name
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik committed Feb 28, 2022
1 parent e7ab4d0 commit ebe8be2
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('[email protected]', () => {
query.on('end', () => {
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans[0].name, 'SELECT');
assert.strictEqual(
spans[0].attributes[SemanticAttributes.DB_STATEMENT],
query
);
done();
});
});
Expand All @@ -161,7 +165,11 @@ describe('[email protected]', () => {

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
);
done();
});
});
Expand Down

0 comments on commit ebe8be2

Please sign in to comment.