From 24e1ceb6d5598b668175616550d16dd33869bd24 Mon Sep 17 00:00:00 2001 From: Samuron Date: Thu, 21 Mar 2024 09:18:34 +0200 Subject: [PATCH] perf(instrumentation-pg): do not split query to determine span name --- 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 bcf8e4efb7..5cc55162de 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -81,7 +81,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;