diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts index 8230052d0e..6483b8cce5 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts @@ -115,7 +115,11 @@ export function getSpanName(query: string | Query | QueryOptions): string { if (typeof query === 'object') { return query.sql; } - return query.split(' ')[0]; + const firstSpace = query?.indexOf(' '); + if (typeof firstSpace === 'number' && firstSpace !== -1) { + return query?.substring(0, firstSpace); + } + return query; } export function arrayStringifyHelper(arr: Array | undefined): string { diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index b59d1b7387..0a045ff45a 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -132,7 +132,7 @@ export function getSpanName(query: string | Query | QueryOptions): string { const rawQuery = typeof query === 'object' ? query.sql : query; // Extract the SQL verb const firstSpace = rawQuery?.indexOf(' '); - if (typeof firstSpace === "number" && firstSpace !== -1) { + if (typeof firstSpace === 'number' && firstSpace !== -1) { return rawQuery?.substring(0, firstSpace); } return rawQuery;