From 46616da8690cfce4bf9da424c1d437ae60ff3f0b Mon Sep 17 00:00:00 2001 From: Hannah Ramadan Date: Mon, 14 Oct 2024 13:23:25 -0700 Subject: [PATCH] Capture table names in double quotes --- .../opentelemetry/instrumentation/mysql2/patches/client.rb | 2 +- instrumentation/mysql2/test/fixtures/sql_table_name.json | 4 ++++ .../opentelemetry/instrumentation/trilogy/patches/client.rb | 2 +- instrumentation/trilogy/test/fixtures/sql_table_name.json | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/patches/client.rb b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/patches/client.rb index c3f360750..d1094f4cd 100644 --- a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/patches/client.rb +++ b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/patches/client.rb @@ -14,7 +14,7 @@ module Patches # Module to prepend to Mysql2::Client for instrumentation module Client # Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands - TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["']?([\w.]+)["']?/i + TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["]?([\w.]+)["]?/i def query(sql, options = {}) tracer.in_span( diff --git a/instrumentation/mysql2/test/fixtures/sql_table_name.json b/instrumentation/mysql2/test/fixtures/sql_table_name.json index eacd9571f..665ff93ed 100644 --- a/instrumentation/mysql2/test/fixtures/sql_table_name.json +++ b/instrumentation/mysql2/test/fixtures/sql_table_name.json @@ -50,5 +50,9 @@ { "name": "from_with_join", "sql": "SELECT columns FROM test_table JOIN table2 ON test_table.column = table2.column" + }, + { + "name": "table_name_with_double_quotes", + "sql": "SELECT columns FROM \"test_table\"" } ] \ No newline at end of file diff --git a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb index 13b328804..e39659bfd 100644 --- a/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb +++ b/instrumentation/trilogy/lib/opentelemetry/instrumentation/trilogy/patches/client.rb @@ -14,7 +14,7 @@ module Patches # Module to prepend to Trilogy for instrumentation module Client # Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands - TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["']?([\w.]+)["']?/i + TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["]?([\w.]+)["]?/i def initialize(options = {}) @connection_options = options # This is normally done by Trilogy#initialize diff --git a/instrumentation/trilogy/test/fixtures/sql_table_name.json b/instrumentation/trilogy/test/fixtures/sql_table_name.json index eacd9571f..665ff93ed 100644 --- a/instrumentation/trilogy/test/fixtures/sql_table_name.json +++ b/instrumentation/trilogy/test/fixtures/sql_table_name.json @@ -50,5 +50,9 @@ { "name": "from_with_join", "sql": "SELECT columns FROM test_table JOIN table2 ON test_table.column = table2.column" + }, + { + "name": "table_name_with_double_quotes", + "sql": "SELECT columns FROM \"test_table\"" } ] \ No newline at end of file