Class: Karafka::Instrumentation::Callbacks::Statistics
- Inherits:
-
Object
- Object
- Karafka::Instrumentation::Callbacks::Statistics
- Defined in:
- lib/karafka/instrumentation/callbacks/statistics.rb
Overview
Statistics callback handler
Instance Method Summary collapse
-
#call(statistics) ⇒ Object
Emits decorated statistics to the monitor.
-
#initialize(subscription_group_id, consumer_group_id, client_name) ⇒ Statistics
constructor
A new instance of Statistics.
Constructor Details
#initialize(subscription_group_id, consumer_group_id, client_name) ⇒ Statistics
Returns a new instance of Statistics.
17 18 19 20 21 22 |
# File 'lib/karafka/instrumentation/callbacks/statistics.rb', line 17 def initialize(subscription_group_id, consumer_group_id, client_name) @subscription_group_id = subscription_group_id @consumer_group_id = consumer_group_id @client_name = client_name @statistics_decorator = ::Karafka::Core::Monitoring::StatisticsDecorator.new end |
Instance Method Details
#call(statistics) ⇒ Object
Emits decorated statistics to the monitor
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/karafka/instrumentation/callbacks/statistics.rb', line 26 def call(statistics) # Emit only statistics related to our client # rdkafka does not have per-instance statistics hook, thus we need to make sure that we # emit only stats that are related to current producer. Otherwise we would emit all of # all the time. return unless @client_name == statistics['name'] monitor.instrument( 'statistics.emitted', subscription_group_id: @subscription_group_id, consumer_group_id: @consumer_group_id, statistics: @statistics_decorator.call(statistics) ) # We need to catch and handle any potential errors coming from the instrumentation pipeline # as otherwise, in case of statistics which run in the main librdkafka thread, any crash # will hang the whole process. rescue StandardError => e monitor.instrument( 'error.occurred', caller: self, subscription_group_id: @subscription_group_id, consumer_group_id: @consumer_group_id, type: 'callbacks.statistics.error', error: e ) end |