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;