Class: OpenTracing::Instrumentation::Bunny::RegexpRoutingKeySanitazer

Inherits:
Object
  • Object
show all
Defined in:
lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb

Overview

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'

Constant Summary collapse

ROUTING_KEY_SEPARATOR =
'.'
DEFAULT_REPLCE_REGEXP_MAP =
{
  ':sequence_id' => /^\d+$/,
  ':object_id' => /^[0-9a-f]{24}$/,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) ⇒ RegexpRoutingKeySanitazer

Returns a new instance of RegexpRoutingKeySanitazer.

Parameters:

  • replace_regexp_map (Hash<String, String>) (defaults to: DEFAULT_REPLCE_REGEXP_MAP)


26
27
28
# 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

Instance Method Details

#sanitaze_routing_key(routing_key) ⇒ String

Returns sanitazed routing key.

Parameters:

  • routing_key (String)

    souce routing key

Returns:

  • (String)

    sanitazed routing key



32
33
34
35
36
37
# 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