Class: Airbrake::Filters::KeysAllowlist

Inherits:
Object
  • Object
show all
Includes:
KeysFilter
Defined in:
lib/airbrake-ruby/filters/keys_allowlist.rb

Overview

A default Airbrake notice filter. Filters everything in the payload of a notice, but specified keys.

Examples:

filter = Airbrake::Filters::KeysAllowlist.new(
  [:email, /credit/i, 'password']
)
airbrake.add_filter(filter)
airbrake.notify(StandardError.new('App crashed!'), {
  user: 'John',
  password: 's3kr3t',
  email: '[email protected]',
  account_id: 42
})

# The dashboard will display this parameters as filtered, but other
# values won't be affected:
#   { user: 'John',
#     password: '[Filtered]',
#     email: '[email protected]',
#     account_id: 42 }

See Also:

Constant Summary

Constants included from KeysFilter

Airbrake::Filters::KeysFilter::FILTERABLE_CONTEXT_KEYS, Airbrake::Filters::KeysFilter::FILTERABLE_KEYS, Airbrake::Filters::KeysFilter::FILTERED, Airbrake::Filters::KeysFilter::VALID_PATTERN_CLASSES

Instance Attribute Summary

Attributes included from KeysFilter

#weight

Instance Method Summary collapse

Methods included from KeysFilter

#call

Methods included from Loggable

#logger

Constructor Details

#initializeKeysAllowlist

Returns a new instance of KeysAllowlist.



30
31
32
33
# File 'lib/airbrake-ruby/filters/keys_allowlist.rb', line 30

def initialize(*)
  super
  @weight = -100
end

Instance Method Details

#should_filter?(key) ⇒ Boolean

Returns true if the key doesn’t match any pattern, false otherwise.

Returns:

  • (Boolean)

    true if the key doesn’t match any pattern, false otherwise.



37
38
39
40
41
42
43
44
45
# File 'lib/airbrake-ruby/filters/keys_allowlist.rb', line 37

def should_filter?(key)
  @patterns.none? do |pattern|
    if pattern.is_a?(Regexp)
      key.match(pattern)
    else
      key.to_s == pattern.to_s
    end
  end
end