Skip to main content

Filtering Errors

Not every error needs to be reported. Configure filtering to reduce noise and focus on what matters.

Exclude Exceptions

Ignore specific exception classes:
BrainzLab.configure do |config|
  config.reflex_excluded_exceptions = [
    'ActionController::RoutingError',
    'ActionController::InvalidAuthenticityToken',
    'ActiveRecord::RecordNotFound'
  ]
end

Exclude by Message

Ignore errors matching a pattern:
BrainzLab.configure do |config|
  config.reflex_excluded_messages = [
    /Bot detected/i,
    /Crawler blocked/i,
    /Rate limit exceeded/
  ]
end

Before Send Hook

Full control over error filtering and modification:
BrainzLab.configure do |config|
  config.reflex_before_send = ->(event) {
    # Return nil to drop the event
    return nil if event.exception.message.include?("expected")

    # Return nil for specific users
    return nil if event.user&.dig(:email)&.end_with?("@test.com")

    # Modify the event
    event.tags[:custom] = "value"

    # Return the event to send it
    event
  }
end

Filter by Environment

Only report in certain environments:
BrainzLab.configure do |config|
  config.reflex_enabled = Rails.env.production? || Rails.env.staging?
end

Sample Errors

Sample high-volume errors:
BrainzLab.configure do |config|
  config.reflex_sample_rate = 0.5  # Report 50% of errors
end

Per-Exception Sampling

BrainzLab.configure do |config|
  config.reflex_before_send = ->(event) {
    # Sample specific errors more aggressively
    if event.exception.is_a?(TimeoutError)
      return nil if rand > 0.1  # Only report 10%
    end
    event
  }
end

Fingerprinting

Control how errors are grouped:
BrainzLab.configure do |config|
  config.reflex_fingerprint = ->(event) {
    # Group by exception class and first line of backtrace
    [
      event.exception.class.name,
      event.backtrace.first
    ]
  }
end

Custom Grouping

Group related errors together:
config.reflex_fingerprint = ->(event) {
  case event.exception
  when Stripe::CardError
    ["payment_failure", event.exception.code]
  when Net::TimeoutError
    ["timeout", event.extra[:endpoint]]
  else
    nil  # Use default fingerprinting
  end
}

Data Scrubbing

Remove sensitive data before sending:
BrainzLab.configure do |config|
  config.scrub_fields = [
    :password,
    :password_confirmation,
    :credit_card,
    :card_number,
    :cvv,
    :ssn,
    :social_security,
    /token/i,
    /secret/i,
    /key/i
  ]
end

Custom Scrubbing

BrainzLab.configure do |config|
  config.reflex_before_send = ->(event) {
    # Remove specific data
    event.extra.delete(:internal_id)

    # Mask email domains
    if event.user&.dig(:email)
      event.user[:email] = event.user[:email].gsub(/@.+/, "@[REDACTED]")
    end

    event
  }
end

Ignore in Code

Temporarily ignore errors:
BrainzLab::Reflex.without_capture do
  # Errors here are not reported
  risky_operation
end

Error Budgets

Set thresholds in the dashboard:
  • Stop alerting after N occurrences per hour
  • Auto-resolve after N days without occurrence
  • Escalate if error rate exceeds threshold