Class: NewRelic::Agent::Database::Obfuscator
- Inherits:
-
Object
- Object
- NewRelic::Agent::Database::Obfuscator
- Includes:
- ObfuscationHelpers, Singleton
- Defined in:
- lib/new_relic/agent/database/obfuscator.rb
Constant Summary collapse
- QUERY_TOO_LARGE_MESSAGE =
'Query too large (over 16k characters) to safely obfuscate'.freeze
- ELLIPSIS =
'...'.freeze
Constants included from ObfuscationHelpers
NewRelic::Agent::Database::ObfuscationHelpers::CASSANDRA_COMPONENTS_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::CLEANUP_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::COMPONENTS_REGEX_MAP, NewRelic::Agent::Database::ObfuscationHelpers::DIALECT_COMPONENTS, NewRelic::Agent::Database::ObfuscationHelpers::FAILED_TO_OBFUSCATE_MESSAGE, NewRelic::Agent::Database::ObfuscationHelpers::FALLBACK_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::MYSQL_COMPONENTS_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::ORACLE_COMPONENTS_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::PLACEHOLDER, NewRelic::Agent::Database::ObfuscationHelpers::POSTGRES_COMPONENTS_REGEX, NewRelic::Agent::Database::ObfuscationHelpers::SQLITE_COMPONENTS_REGEX
Instance Attribute Summary collapse
- #obfuscator ⇒ Object readonly
Instance Method Summary collapse
- #default_sql_obfuscator(sql) ⇒ Object
-
#initialize ⇒ Obfuscator
constructor
A new instance of Obfuscator.
- #reset ⇒ Object
-
#set_sql_obfuscator(type, &block) ⇒ Object
Sets the sql obfuscator used to clean up sql when sending it to the server.
Methods included from ObfuscationHelpers
#detect_unmatched_pairs, generate_regex, #obfuscate, #obfuscate_single_quote_literals
Constructor Details
#initialize ⇒ Obfuscator
Returns a new instance of Obfuscator.
20 21 22 |
# File 'lib/new_relic/agent/database/obfuscator.rb', line 20 def initialize reset end |
Instance Attribute Details
#obfuscator ⇒ Object (readonly)
15 16 17 |
# File 'lib/new_relic/agent/database/obfuscator.rb', line 15 def obfuscator @obfuscator end |
Instance Method Details
#default_sql_obfuscator(sql) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/new_relic/agent/database/obfuscator.rb', line 51 def default_sql_obfuscator(sql) stmt = sql.kind_of?(Statement) ? sql : Statement.new(sql) if stmt.sql.end_with?(ELLIPSIS) return QUERY_TOO_LARGE_MESSAGE end obfuscate(stmt.sql, stmt.adapter).to_s end |
#reset ⇒ Object
24 25 26 |
# File 'lib/new_relic/agent/database/obfuscator.rb', line 24 def reset @obfuscator = method(:default_sql_obfuscator) end |
#set_sql_obfuscator(type, &block) ⇒ Object
Sets the sql obfuscator used to clean up sql when sending it to the server. Possible types are:
:before => sets the block to run before the existing obfuscators
:after => sets the block to run after the existing obfuscator(s)
:replace => removes the current obfuscator and replaces it with the provided block
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/new_relic/agent/database/obfuscator.rb', line 39 def set_sql_obfuscator(type, &block) if type == :before @obfuscator = NewRelic::ChainedCall.new(block, @obfuscator) elsif type == :after @obfuscator = NewRelic::ChainedCall.new(@obfuscator, block) elsif type == :replace @obfuscator = block else fail "unknown sql_obfuscator type #{type}" end end |