class NewRelic::Agent::Database::Obfuscator

Constants

ELLIPSIS
QUERY_TOO_LARGE_MESSAGE

Attributes

obfuscator[R]

Public Class Methods

new() click to toggle source
# File lib/new_relic/agent/database/obfuscator.rb, line 20
def initialize
  reset
end

Public Instance Methods

default_sql_obfuscator(sql) click to toggle source
# 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() click to toggle source
# File lib/new_relic/agent/database/obfuscator.rb, line 24
def reset
  @obfuscator = method(:default_sql_obfuscator)
end
set_sql_obfuscator(type, &block) click to toggle source

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

# 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