Sha256: e67d7c8f911ee529d0160993a406554a088ed0141e837598558bb1d38b86edf2

Contents?: true

Size: 881 Bytes

Versions: 49

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

module Kafka
  class Instrumenter
    NAMESPACE = "kafka"

    def initialize(default_payload = {})
      @default_payload = default_payload

      if defined?(ActiveSupport::Notifications)
        @backend = ActiveSupport::Notifications
      else
        @backend = nil
      end
    end

    def instrument(event_name, payload = {}, &block)
      if @backend
        payload.update(@default_payload)

        @backend.instrument("#{event_name}.#{NAMESPACE}", payload, &block)
      else
        block.call(payload) if block
      end
    end
  end

  class DecoratingInstrumenter
    def initialize(backend, extra_payload = {})
      @backend = backend
      @extra_payload = extra_payload
    end

    def instrument(event_name, payload = {}, &block)
      @backend.instrument(event_name, @extra_payload.merge(payload), &block)
    end
  end
end

Version data entries

49 entries across 49 versions & 4 rubygems

Version Path
ruby-kafka-1.5.0 lib/kafka/instrumenter.rb
ruby-kafka-aws-iam-1.4.5 lib/kafka/instrumenter.rb
ruby-kafka-aws-iam-1.4.4 lib/kafka/instrumenter.rb
ruby-kafka-aws-iam-1.4.3 lib/kafka/instrumenter.rb
ruby-kafka-aws-iam-1.4.2 lib/kafka/instrumenter.rb
ruby-kafka-aws-iam-1.4.1 lib/kafka/instrumenter.rb
ruby-kafka-1.4.0 lib/kafka/instrumenter.rb
ruby-kafka-temp-fork-0.0.2 lib/kafka/instrumenter.rb
ruby-kafka-temp-fork-0.0.1 lib/kafka/instrumenter.rb
ruby-kafka-1.3.0 lib/kafka/instrumenter.rb
ruby-kafka-1.2.0 lib/kafka/instrumenter.rb
ruby-kafka-1.1.0 lib/kafka/instrumenter.rb
ruby-kafka-1.1.0.beta1 lib/kafka/instrumenter.rb
ruby-kafka-1.0.0 lib/kafka/instrumenter.rb
ruby-kafka-0.7.10 lib/kafka/instrumenter.rb
ruby-kafka-0.7.9 lib/kafka/instrumenter.rb
ruby-kafka-0.7.8 lib/kafka/instrumenter.rb
ruby-kafka-0.7.7 lib/kafka/instrumenter.rb
ruby-kafka-custom-0.7.7.26 lib/kafka/instrumenter.rb
ruby-kafka-0.7.6 lib/kafka/instrumenter.rb