Class: ElasticAPM::Transport::Filters::HashSanitizer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_apm/transport/filters/hash_sanitizer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

FILTERED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'[FILTERED]'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_patterns:) ⇒ HashSanitizer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HashSanitizer.

[View source]

29
30
31
# File 'lib/elastic_apm/transport/filters/hash_sanitizer.rb', line 29

def initialize(key_patterns:)
  @key_patterns = key_patterns
end

Instance Attribute Details

#key_patternsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


33
34
35
# File 'lib/elastic_apm/transport/filters/hash_sanitizer.rb', line 33

def key_patterns
  @key_patterns
end

Instance Method Details

#filter_key?(key) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)
[View source]

53
54
55
# File 'lib/elastic_apm/transport/filters/hash_sanitizer.rb', line 53

def filter_key?(key)
  @key_patterns.any? { |regex| regex.match(key) }
end

#strip_from(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

[View source]

35
36
37
# File 'lib/elastic_apm/transport/filters/hash_sanitizer.rb', line 35

def strip_from(obj)
  strip_from!(Util::DeepDup.dup(obj))
end

#strip_from!(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

[View source]

39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elastic_apm/transport/filters/hash_sanitizer.rb', line 39

def strip_from!(obj)
  return unless obj.is_a?(Hash)

  obj.each_pair do |k, v|
    case v
    when Hash
      strip_from!(v)
    else
      next unless filter_key?(k)
      obj[k] = FILTERED
    end
  end
end