Sha256: 66abc77d42060fd4a68edaafd6e7b4221c77a2cf4ed03786a7b7711bef2c4e10
Contents?: true
Size: 1.45 KB
Versions: 5
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true module OpenTracing module Instrumentation module Bunny # 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' class RegexpRoutingKeySanitazer ROUTING_KEY_SEPARATOR = '.' DEFAULT_REPLCE_REGEXP_MAP = { ':sequence_id' => /^\d+$/, ':object_id' => /^[0-9a-f]{24}$/, }.freeze # @param replace_regexp_map [Hash<String, String>] def initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) @replace_regexp_map = replace_regexp_map end # @param routing_key [String] souce routing key # @return [String] sanitazed routing key def sanitaze_routing_key(routing_key) routing_key .split(ROUTING_KEY_SEPARATOR) .map(&method(:filter_part)) .join(ROUTING_KEY_SEPARATOR) end private attr_reader :replace_regexp_map def filter_part(routing_key_part) replace_regexp_map.each do |placeholder, regexp| return placeholder if regexp =~ routing_key_part end routing_key_part end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems