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 }