<commit_before>require 'rollbar/rails'

Rollbar.configure do |config|
  config.access_token = Cartodb.config[:rollbar_api_key]
  config.enabled = (Rails.env.production? || Rails.env.staging?) && config.access_token.present?
  config.net_retries = 1 # This is actually 6 requests (18s), as Rollbar retries two times (failsafes) and CartoDB once

  # Add exception class names to the exception_level_filters hash to
  # change the level that exception is reported at. Note that if an exception
  # has already been reported and logged the level will need to be changed
  # via the rollbar interface.
  # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
  # 'ignore' will cause the exception to not be reported at all.
  info_errors = ['error creating usertable']
  config.exception_level_filters.merge!(
    'ActionController::RoutingError' => 'ignore',
    'Sequel::DatabaseConnectionError' => 'warning',
    'ActiveRecord::RecordInvalid' => lambda do
      |error| info_errors.any? { |message| error.to_s.downcase.include?(message) } ? 'info' : 'error'
    end
  )
end

# TODO: remove this wrapper for legacy logger
module CartoDB

  extend ::LoggerHelper

  def self.notify_exception(e, extra = {})
    log_error(exception: e, **extra)
  end

  def self.notify_error(message, additional_data = {})
    log_error(message: message, **additional_data)
  end

  # Add `:request` and `:user` to additional_data if you want request content
  def self.report_exception(e, message = nil, additional_data = {})
    log_error(exception: e, message: message, **additional_data)
  end<commit_msg>Don't send ActionController::RoutingError to Rollbar<commit_after>require 'rollbar/rails'

Rollbar.configure do |config|
  config.access_token = Cartodb.config[:rollbar_api_key]
  config.enabled = (Rails.env.production? || Rails.env.staging?) && config.access_token.present?
  config.net_retries = 1 # This is actually 6 requests (18s), as Rollbar retries two times (failsafes) and CartoDB once

  # Add exception class names to the exception_level_filters hash to
  # change the level that exception is reported at. Note that if an exception
  # has already been reported and logged the level will need to be changed
  # via the rollbar interface.
  # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
  # 'ignore' will cause the exception to not be reported at all.
  info_errors = ['error creating usertable']

  # TODO: This approach is currently not working (I suspect the usage of rescue_from StandardError)
  config.exception_level_filters.merge!(
    'ActionController::RoutingError' => 'ignore',
    'Sequel::DatabaseConnectionError' => 'warning',
    'ActiveRecord::RecordInvalid' => lambda do
      |error| info_errors.any? { |message| error.to_s.downcase.include?(message) } ? 'info' : 'error'
    end
  )

  config.before_process << proc do |options|
    raise Rollbar::Ignore if options.is_a?(Hash) &&
                             options[:message]&.include?('ActionController::RoutingError')
  end
end

# TODO: remove this wrapper for legacy logger
module CartoDB

  extend ::LoggerHelper

  def self.notify_exception(e, extra = {})
    log_error(exception: e, **extra)
  end

  def self.notify_error(message, additional_data = {})
    log_error(message: message, **additional_data)
  end

  # Add `:request` and `:user` to additional_data if you want request content
  def self.report_exception(e, message = nil, additional_data = {})
    log_error(exception: e, message: message, **additional_data)
  end
{'fraction_non_alphanumeric': 0.10870177414812729, 'fraction_numerical': 0.002252886510842016, 'mean_word_length': 4.464615384615384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1065722', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1041, 'n_words': 333}