diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index a71560014e..0d42e7dc67 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -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) => { diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts index f456ba368c..28f1ba8bd0 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts @@ -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], + query + ); done(); }); }); @@ -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 + ); done(); }); });