Class: Apmlens::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/apmlens/railtie.rb

Class Method Summary collapse

Class Method Details

.fingerprint_sql(sql) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/apmlens/railtie.rb', line 82

def self.fingerprint_sql(sql)
  return "unknown" if sql.nil?
  
  # Remove literals and normalize whitespace
  normalized = sql.gsub(/\b\d+\b/, '?')                    # Numbers
                  .gsub(/'[^']*'/, '?')                     # Strings
                  .gsub(/\s+/, ' ')                         # Whitespace
                  .strip
  
  # Extract table name if possible
  if normalized =~ /FROM\s+["']?(\w+)["']?/i
    table = $1
    "#{table}:#{normalized[0..50]}"
  else
    normalized[0..50]
  end
end