Skip to content

Commit

Permalink
Update QUERY_NAME_REGEX
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaylareopelle committed Sep 19, 2023
1 parent f69eb9c commit c694e55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helpers/mysql/lib/opentelemetry/helpers/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions helpers/mysql/test/helpers/mysql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit c694e55

Please sign in to comment.