Sha256: f3befa013a9b5142295ca87f9da073d8d50f7cb58658fff4a73a9208204f9931

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module OpenTracing
  module Instrumentation
    module Bunny
      # PublishOperationNameBuilder build publish command name from
      # exchange and publish options
      class PublishOperationNameBuilder
        DEFAULT_OPERATION_NAME_PATTERN = \
          'bunny_publish(' \
            'routing_key=%<routing_key>s, ' \
            'exchange=%<exchange>s' \
          ')'

        # @param routing_key_sanitazer [RegexpRoutingKeySanitazer]
        # @param operation_name_pattern [String]
        def initialize(
          routing_key_sanitazer: RegexpRoutingKeySanitazer.new,
          operation_name_pattern: DEFAULT_OPERATION_NAME_PATTERN
        )
          @routing_key_sanitazer = routing_key_sanitazer
          @operation_name_pattern = operation_name_pattern
        end

        # @param exchange [Bunny::Exchange]
        # @param opts [Hash<Symbol, Object>]
        # @option opts [String] :routing_key
        # @return [String]
        def build_operation_name(exchange, opts)
          format_args = build_format_args(exchange, opts)
          format(@operation_name_pattern, **format_args)
        end

        private

        def build_format_args(exchange, opts)
          opts
            .merge(exchange: exchange.name)
            .merge(routing_key: sanitaze_routing_key(opts[:routing_key]))
        end

        def sanitaze_routing_key(routing_key)
          return if routing_key.nil?

          @routing_key_sanitazer.sanitaze_routing_key(routing_key)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
opentracing-instrumentation-0.2.1 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.2.0 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.18 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.17 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.16 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.15 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.14 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.13 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.12 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.11 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.10 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.9 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.8 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.7 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.6 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.5 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.4 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb
opentracing-instrumentation-0.1.3 lib/opentracing/instrumentation/bunny/publish_operation_name_builder.rb