From 816611e47e71ce1478f4749fe7b6ba923b8d473a Mon Sep 17 00:00:00 2001 From: Ievgen Makukh Date: Wed, 22 May 2024 23:32:59 +0300 Subject: [PATCH] perf(instrumentation-pg): do not split query to determine operation name (#2029) Co-authored-by: Amir Blum --- plugins/node/opentelemetry-instrumentation-pg/src/utils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index f0325bbd77..a16ccc9cd0 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -86,7 +86,12 @@ export function getQuerySpanName( } function parseNormalizedOperationName(queryText: string) { - const sqlCommand = queryText.split(' ')[0].toUpperCase(); + const indexOfFirstSpace = queryText.indexOf(' '); + let sqlCommand = + indexOfFirstSpace === -1 + ? queryText + : queryText.slice(0, indexOfFirstSpace); + sqlCommand = sqlCommand.toUpperCase(); // Handle query text being "COMMIT;", which has an extra semicolon before the space. return sqlCommand.endsWith(';') ? sqlCommand.slice(0, -1) : sqlCommand;