Skip to content

Commit

Permalink
refactor(instrumentation-mysql2): use substring() instead of split() …
Browse files Browse the repository at this point in the history
…to get span name
  • Loading branch information
geotry committed Oct 10, 2024
1 parent 645ac2e commit aed3839
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ export function getDbStatement(
export function getSpanName(query: string | Query | QueryOptions): string {
const rawQuery = typeof query === 'object' ? query.sql : query;
// Extract the SQL verb
return rawQuery?.split(' ')?.[0];
const firstSpace = rawQuery?.indexOf(' ');
if (typeof firstSpace === "number" && firstSpace !== -1) {
return rawQuery?.substring(0, firstSpace);
}
return rawQuery;
}

export const once = (fn: Function) => {
Expand Down

0 comments on commit aed3839

Please sign in to comment.