Class: FastExists::Instrumentation::EventSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_exists/instrumentation/event_subscriber.rb

Constant Summary collapse

EVENTS =
%w[
  fast_exists.lookup
  fast_exists.hit
  fast_exists.miss
  fast_exists.false_positive
  fast_exists.database_lookup
].freeze

Class Method Summary collapse

Class Method Details

.instrument(event_name, payload = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fast_exists/instrumentation/event_subscriber.rb', line 24

def self.instrument(event_name, payload = {})
  if defined?(ActiveSupport::Notifications) && FastExists.configuration.instrumentation
    ActiveSupport::Notifications.instrument("fast_exists.#{event_name}", payload) do
      yield if block_given?
    end
  elsif block_given?
    yield
  end
end

.subscribe!Object



14
15
16
17
18
19
20
21
22
# File 'lib/fast_exists/instrumentation/event_subscriber.rb', line 14

def self.subscribe!
  return unless defined?(ActiveSupport::Notifications)

  EVENTS.each do |event_name|
    ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, payload|
      # Can log or forward metrics
    end
  end
end