lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.21.0 vs lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.21.1
- old
+ new
@@ -7,11 +7,11 @@
module OpenTelemetry
module Instrumentation
module Mysql2
module Patches
# Module to prepend to Mysql2::Client for instrumentation
- module Client
+ module Client # rubocop:disable Metrics/ModuleLength
QUERY_NAMES = [
'set names',
'select',
'insert',
'update',
@@ -71,14 +71,17 @@
def obfuscate_sql(sql)
if sql.size > 2000
'SQL query too large to remove sensitive data ...'
else
- obfuscated = sql.gsub(generated_mysql_regex, '?')
+ obfuscated = OpenTelemetry::Common::Utilities.utf8_encode(sql, binary: true)
+ obfuscated = obfuscated.gsub(generated_mysql_regex, '?')
obfuscated = 'Failed to obfuscate SQL query - quote characters remained after obfuscation' if detect_unmatched_pairs(obfuscated)
obfuscated
end
+ rescue StandardError
+ 'OpenTelemetry error: failed to obfuscate sql'
end
def generated_mysql_regex
@generated_mysql_regex ||= Regexp.union(MYSQL_COMPONENTS.map { |component| COMPONENTS_REGEX_MAP[component] })
end
@@ -140,9 +143,10 @@
def extract_statement_type(sql)
QUERY_NAME_RE.match(sql) { |match| match[1].downcase } unless sql.nil?
rescue StandardError => e
OpenTelemetry.logger.debug("Error extracting sql statement type: #{e.message}")
+ nil
end
end
end
end
end