Class: NewRelic::Agent::Database::Obfuscator
- Inherits:
-
Object
- Object
- NewRelic::Agent::Database::Obfuscator
- Includes:
- Singleton
- Defined in:
- lib/new_relic/agent/database.rb
Instance Attribute Summary collapse
-
#obfuscator ⇒ Object
readonly
Returns the value of attribute obfuscator.
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.
Constructor Details
#initialize ⇒ Obfuscator
Returns a new instance of Obfuscator.
158 159 160 |
# File 'lib/new_relic/agent/database.rb', line 158 def initialize reset end |
Instance Attribute Details
#obfuscator ⇒ Object (readonly)
Returns the value of attribute obfuscator.
156 157 158 |
# File 'lib/new_relic/agent/database.rb', line 156 def obfuscator @obfuscator end |
Instance Method Details
#default_sql_obfuscator(sql) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/new_relic/agent/database.rb', line 189 def default_sql_obfuscator(sql) sql = sql.dup # This is hardly readable. Use the unit tests. # remove single quoted strings: sql.gsub!(/'(.*?[^\\'])??'(?!')/, '?') # remove double quoted strings: sql.gsub!(/"(.*?[^\\"])??"(?!")/, '?') # replace all number literals sql.gsub!(/\d+/, "?") sql end |
#reset ⇒ Object
162 163 164 |
# File 'lib/new_relic/agent/database.rb', line 162 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
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/new_relic/agent/database.rb', line 177 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 |