Sha256: 30cf918e93ec731487800b349dfc075c210abe894698d643a397f18958919b1e

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'honeybadger/plugin'

module Honeybadger
  module Plugins
    Plugin.register :karafka do
      requirement { defined?(::Karafka) && ::Karafka.respond_to?(:monitor) }

      execution do
        ::Karafka.monitor.subscribe('error.occurred') do |event|
          Honeybadger.notify(event[:error])
          Honeybadger.event('error.occurred', error: event[:error]) if config.load_plugin_insights?(:karafka)
        end

        if config.load_plugin_insights?(:karafka)
          ::Karafka.monitor.subscribe("consumer.consumed") do |event|
            context = {
              duration: event.payload[:time],
              consumer: event.payload[:caller].class.to_s,
              id: event.payload[:caller].id,
              topic: event.payload[:caller].messages.metadata.topic,
              messages_count: event.payload[:caller].messages.metadata.size,
              partition: event.payload[:caller].messages.metadata.partition
            }

            Honeybadger.event('consumer.consumed.karafka', context)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
honeybadger-5.15.6 lib/honeybadger/plugins/karafka.rb