Class: Lapsoss::Fingerprinter

Inherits:
Object
  • Object
show all
Defined in:
lib/lapsoss/fingerprinter.rb

Constant Summary collapse

BASE_PATTERNS =

Base patterns that are always available

[
  # Generic error message normalization
  {
    pattern: /User \d+ (not found|invalid|missing)/i,
    fingerprint: "user-lookup-error"
  },
  {
    pattern: /Record \d+ (not found|invalid|missing)/i,
    fingerprint: "record-lookup-error"
  },

  # Network error patterns
  {
    pattern: /Net::(TimeoutError|ReadTimeout|OpenTimeout)/,
    fingerprint: "network-timeout"
  },
  {
    pattern: /Errno::(ECONNREFUSED|ECONNRESET|EHOSTUNREACH)/,
    fingerprint: "network-connection-error"
  },

  # Memory/Resource patterns
  {
    pattern: /NoMemoryError|SystemStackError/,
    fingerprint: "memory-resource-error"
  }
].freeze
ACTIVERECORD_PATTERNS =

ActiveRecord-specific patterns (only loaded if ActiveRecord is defined)

[
  {
    pattern: /ActiveRecord::RecordNotFound/,
    fingerprint: "record-not-found"
  },
  {
    pattern: /ActiveRecord::StatementInvalid.*timeout/i,
    fingerprint: "database-timeout"
  },
  {
    pattern: /ActiveRecord::ConnectionTimeoutError/,
    fingerprint: "database-connection-timeout"
  }
].freeze
DATABASE_PATTERNS =

Database adapter patterns (only loaded if adapters are defined)

[
  {
    pattern: /PG::ConnectionBad/,
    fingerprint: "postgres-connection-error",
    condition: -> { defined?(PG) }
  },
  {
    pattern: /Mysql2::Error/,
    fingerprint: "mysql-connection-error",
    condition: -> { defined?(Mysql2) }
  },
  {
    pattern: /SQLite3::BusyException/,
    fingerprint: "sqlite-busy-error",
    condition: -> { defined?(SQLite3) }
  }
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Fingerprinter



71
72
73
74
75
76
# File 'lib/lapsoss/fingerprinter.rb', line 71

def initialize(config = {})
  @custom_callback = config[:custom_callback]
  @patterns = build_patterns(config[:patterns])
  @normalize_ids = config.fetch(:normalize_ids, true)
  @include_environment = config.fetch(:include_environment, false)
end

Instance Method Details

#generate_fingerprint(event) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lapsoss/fingerprinter.rb', line 78

def generate_fingerprint(event)
  # Try custom callback first
  if @custom_callback
    custom_result = @custom_callback.call(event)
    return custom_result if custom_result
  end

  # Try pattern matching
  pattern_result = match_patterns(event)
  return pattern_result if pattern_result

  # Fall back to default fingerprinting
  generate_default_fingerprint(event)
end