Sha256: f0732b6d68b5b5fa7362e25ac78f5f6ab6801647081d774ab9304b577883b3e4

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module OpenTracing
  module Instrumentation
    module Bunny
      # ConsumeTagsBuidler build consume tags from delivery_info and
      # properties
      class ConsumeTagsBuilder
        DEFAULT_STATIC_TAGS = {
          'span.kind' => 'consumer',
          'component' => 'bunny',
        }.freeze

        # @param static_tags [Hash<String, String>]
        def initialize(static_tags: DEFAULT_STATIC_TAGS)
          @static_tags = static_tags
        end

        # @param delivery_info [Bunny::DeliveryInfo]
        # @param properties [Bunny::MessageProperties]
        # @return [Hash] consume span tags
        def build_tags(delivery_info, properties)
          @static_tags
            .merge(build_properties_tags(properties))
            .merge(build_delivery_info_tags(delivery_info))
            .merge(build_consumer_tags(delivery_info[:consumer]))
        end

        private

        def build_properties_tags(properties)
          {
            'amqp.content_type' => properties[:content_type],
          }
        end

        def build_delivery_info_tags(delivery_info)
          {
            'amqp.redelivered' => delivery_info[:redelivered],
            'amqp.exchange' => delivery_info[:exchange],
            'amqp.routing_key' => delivery_info[:routing_key],
          }
        end

        def build_consumer_tags(consumer)
          {
            'amqp.queue' => consumer.queue.name,
            'amqp.no_ack' => consumer.no_ack,
            'amqp.exclusive' => consumer.exclusive,
          }
        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/consume_tags_builder.rb
opentracing-instrumentation-0.2.0 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.18 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.17 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.16 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.15 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.14 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.13 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.12 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.11 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.10 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.9 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.8 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.7 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.6 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.5 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.4 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb
opentracing-instrumentation-0.1.3 lib/opentracing/instrumentation/bunny/consume_tags_builder.rb