Class: Karafka::Core::Monitoring::Monitor
- Inherits:
-
Object
- Object
- Karafka::Core::Monitoring::Monitor
- Defined in:
- lib/karafka/core/monitoring/monitor.rb
Overview
Karafka monitor that can be used to pass through instrumentation calls to selected notifications bus.
It provides abstraction layer that allows us to use both our internal notifications as well as ActiveSupport::Notifications
.
Instance Method Summary collapse
-
#initialize(notifications_bus, namespace = nil) ⇒ Monitor
constructor
A new instance of Monitor.
-
#instrument(event_id, payload = EMPTY_HASH, &block) ⇒ Object
Passes the instrumentation block (if any) into the notifications bus.
-
#subscribe(*args, &block) ⇒ Object
Allows us to subscribe to the notification bus.
Constructor Details
#initialize(notifications_bus, namespace = nil) ⇒ Monitor
Returns a new instance of Monitor.
20 21 22 23 24 |
# File 'lib/karafka/core/monitoring/monitor.rb', line 20 def initialize(notifications_bus, namespace = nil) @notifications_bus = notifications_bus @namespace = namespace @mapped_events = {} end |
Instance Method Details
#instrument(event_id, payload = EMPTY_HASH, &block) ⇒ Object
Passes the instrumentation block (if any) into the notifications bus
31 32 33 34 35 |
# File 'lib/karafka/core/monitoring/monitor.rb', line 31 def instrument(event_id, payload = EMPTY_HASH, &block) full_event_name = @mapped_events[event_id] ||= [event_id, @namespace].compact.join('.') @notifications_bus.instrument(full_event_name, payload, &block) end |
#subscribe(*args, &block) ⇒ Object
Allows us to subscribe to the notification bus
41 42 43 |
# File 'lib/karafka/core/monitoring/monitor.rb', line 41 def subscribe(*args, &block) @notifications_bus.subscribe(*args, &block) end |