From c694e556d67b5ad02d7a9604d11bc9d2c5284472 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 19 Sep 2023 11:14:19 -0700 Subject: [PATCH] Update QUERY_NAME_REGEX Users of marginalia or other tools that can prepend content onto a SQL statement consistently received 'mysql' as the span name because statement type extraction required the statement to be at the beginning of the string. Now, the requirement for a query name to appear at the beginning of a statement has been removed. --- helpers/mysql/lib/opentelemetry/helpers/mysql.rb | 2 +- helpers/mysql/test/helpers/mysql_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/helpers/mysql/lib/opentelemetry/helpers/mysql.rb b/helpers/mysql/lib/opentelemetry/helpers/mysql.rb index 857516857..1260f8d14 100644 --- a/helpers/mysql/lib/opentelemetry/helpers/mysql.rb +++ b/helpers/mysql/lib/opentelemetry/helpers/mysql.rb @@ -36,7 +36,7 @@ class MySQL 'create table' ].freeze - QUERY_NAME_REGEX = Regexp.new("^(#{QUERY_NAMES.join('|')})", Regexp::IGNORECASE) + QUERY_NAME_REGEX = Regexp.new("(#{QUERY_NAMES.join('|')})", Regexp::IGNORECASE) # This is a span naming utility intended for use in MySQL database # adapter instrumentation. diff --git a/helpers/mysql/test/helpers/mysql_test.rb b/helpers/mysql/test/helpers/mysql_test.rb index 2ba1fdb2f..7cba870b4 100644 --- a/helpers/mysql/test/helpers/mysql_test.rb +++ b/helpers/mysql/test/helpers/mysql_test.rb @@ -93,6 +93,18 @@ end end + describe 'when sql has marginalia-style prepended comments' do + let(:sql) do + '/*application:web,controller:blob,action:show,correlation_id:01EZVMR923313VV44ZJDJ7PMEZ,' \ + 'endpoint_id:Projects::BlobController#show*/ SELECT "routes".* FROM "routes" WHERE "routes"' \ + '."source_id" = 75 AND "routes"."source_type" = \'Namespace\' LIMIT 1' + end + + it 'finds the query name' do + assert_equal('select', extract_statement_type) + end + end + describe 'when sql is nil' do let(:sql) { nil }