Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(instrumentation-mysql2): improve performance of getSpanName using substring #2470

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor(instrumentation-mysql2): use substring() instead of split() …
…to get span name
geotry committed Oct 10, 2024
commit aed383986f1695a6f566073514e2876a4534f3a7
Original file line number Diff line number Diff line change
@@ -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) => {