lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.23.0 vs lib/opentelemetry/instrumentation/mysql2/patches/client.rb in opentelemetry-instrumentation-mysql2-0.24.0
- old
+ new
@@ -28,10 +28,11 @@
'create table'
].freeze
QUERY_NAME_RE = Regexp.new("^(#{QUERY_NAMES.join('|')})", Regexp::IGNORECASE)
+ # From: https://github.com/newrelic/newrelic-ruby-agent/blob/0235b288d85b8bc795bdc1a24621dd9f84cfef45/lib/new_relic/agent/database/obfuscation_helpers.rb#L9-L34
COMPONENTS_REGEX_MAP = {
single_quotes: /'(?:[^']|'')*?(?:\\'.*|'(?!'))/,
double_quotes: /"(?:[^"]|"")*?(?:\\".*|"(?!"))/,
numeric_literals: /-?\b(?:[0-9]+\.)?[0-9]+([eE][+-]?[0-9]+)?\b/,
boolean_literals: /\b(?:true|false|null)\b/i,
@@ -68,11 +69,12 @@
end
private
def obfuscate_sql(sql)
- if sql.size > 2000
- 'SQL query too large to remove sensitive data ...'
+ if sql.size > config[:obfuscation_limit]
+ truncated_sql = sql[..sql.index(generated_mysql_regex) - 1]
+ truncated_sql + "...\nSQL truncated (> #{config[:obfuscation_limit]} characters)"
else
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