module NewRelic::Agent::Database::ObfuscationHelpers
Constants
- CASSANDRA_COMPONENTS_REGEX
- CLEANUP_REGEX
We use these to check whether the query contains any quote characters after obfuscation. If so, that's a good indication that the original query was malformed, and so our obfuscation can't reliably find literals. In such a case, we'll replace the entire query with a placeholder.
- COMPONENTS_REGEX_MAP
- DIALECT_COMPONENTS
- FAILED_TO_OBFUSCATE_MESSAGE
- FALLBACK_REGEX
- MYSQL_COMPONENTS_REGEX
- ORACLE_COMPONENTS_REGEX
- PLACEHOLDER
- POSTGRES_COMPONENTS_REGEX
- SQLITE_COMPONENTS_REGEX
Public Class Methods
generate_regex(dialect)
click to toggle source
# File lib/new_relic/agent/database/obfuscation_helpers.rb, line 55 def self.generate_regex(dialect) components = DIALECT_COMPONENTS[dialect] Regexp.union(components.map{|component| COMPONENTS_REGEX_MAP[component]}) end
Public Instance Methods
detect_unmatched_pairs(obfuscated, adapter)
click to toggle source
# File lib/new_relic/agent/database/obfuscation_helpers.rb, line 87 def detect_unmatched_pairs(obfuscated, adapter) if CLEANUP_REGEX[adapter] CLEANUP_REGEX[adapter].match(obfuscated) else CLEANUP_REGEX[:mysql].match(obfuscated) end end
obfuscate(sql, adapter)
click to toggle source
# File lib/new_relic/agent/database/obfuscation_helpers.rb, line 67 def obfuscate(sql, adapter) case adapter when :mysql regex = MYSQL_COMPONENTS_REGEX when :postgres regex = POSTGRES_COMPONENTS_REGEX when :sqlite regex = SQLITE_COMPONENTS_REGEX when :oracle regex = ORACLE_COMPONENTS_REGEX when :cassandra regex = CASSANDRA_COMPONENTS_REGEX else regex = FALLBACK_REGEX end obfuscated = sql.gsub(regex, PLACEHOLDER) obfuscated = FAILED_TO_OBFUSCATE_MESSAGE if detect_unmatched_pairs(obfuscated, adapter) obfuscated end
obfuscate_single_quote_literals(sql)
click to toggle source
# File lib/new_relic/agent/database/obfuscation_helpers.rb, line 51 def obfuscate_single_quote_literals(sql) sql.gsub!(COMPONENTS_REGEX_MAP[:single_quotes], PLACEHOLDER) || sql end