Skip to content

Commit

Permalink
feat: emit an event for karafka stats
Browse files Browse the repository at this point in the history
This sends an event when Karafka emits a `statistics_emitted` event. It
can be toggled off with the following configuration:

```
karafka:
  insights:
    events: false
```

All metrics in the karafka plugin should now be disabled by default and
will need to be enabled by:
```
karafka:
  insights:
    metrics: true
```

(actually this was already the case, but I missed one metric, so now all metrics are disabled)
  • Loading branch information
roelbondoc committed Nov 12, 2024
1 parent 6a64bf7 commit edc559b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/honeybadger/karafka.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def initialize
#
# @param event [Karafka::Core::Monitoring::Event]
def on_statistics_emitted(event)
if Honeybadger.config.load_plugin_insights_events?(:karafka)
Honeybadger.event("statistics_emitted.karafka", event.payload)
end

return unless Honeybadger.config.load_plugin_insights_metrics?(:karafka)

statistics = event[:statistics]
Expand Down Expand Up @@ -138,9 +142,7 @@ def on_error_occurred(event)
def on_connection_listener_fetch_loop_received(event)
time_taken = event[:time]
messages_count = event[:messages_buffer].size

consumer_group_id = event[:subscription_group].consumer_group.id

extra_tags = { consumer_group: consumer_group_id }

if Honeybadger.config.load_plugin_insights_metrics?(:karafka)
Expand Down Expand Up @@ -191,9 +193,10 @@ def on_consumer_consumed(event)
#
# @param event [Karafka::Core::Monitoring::Event]
def on_consumer_#{after}(event)
tags = consumer_tags(event.payload[:caller])
increment_counter('consumer_#{name}', value: 1, **tags)
if Honeybadger.config.load_plugin_insights_metrics?(:karafka)
tags = consumer_tags(event.payload[:caller])
increment_counter('consumer_#{name}', value: 1, **tags)
end
end
RUBY
end
Expand Down

0 comments on commit edc559b

Please sign in to comment.