class OpenTracing::Instrumentation::Bunny::RegexpRoutingKeySanitazer

Replace id into routing key with placeholder

Example:

sanitazer = RegexpRoutingKeySanitazer.new
sanitazer.sanitaze_routing_key('prefix.1234567890abcdef12345678')

# 'prefix.:object_id'

sanitazer.sanitaze_routing_key('prefix.123.suffix')

# 'prefix.:sequence_id.suffis'

Constants

DEFAULT_REPLCE_REGEXP_MAP
ROUTING_KEY_SEPARATOR

Attributes

replace_regexp_map[R]

Public Class Methods

new(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) click to toggle source

@param replace_regexp_map [Hash<String, String>]

# File lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb, line 26
def initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP)
  @replace_regexp_map = replace_regexp_map
end

Public Instance Methods

sanitaze_routing_key(routing_key) click to toggle source

@param routing_key [String] souce routing key @return [String] sanitazed routing key

# File lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb, line 32
def sanitaze_routing_key(routing_key)
  routing_key
    .split(ROUTING_KEY_SEPARATOR)
    .map { |part| filter_part(part) }
    .join(ROUTING_KEY_SEPARATOR)
end

Private Instance Methods

filter_part(routing_key_part) click to toggle source
# File lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb, line 43
def filter_part(routing_key_part)
  replace_regexp_map.each do |placeholder, regexp|
    return placeholder if regexp.match?(routing_key_part)
  end
  routing_key_part
end