Class: Appsignal::Hooks::ActiveSupportNotificationsHook Private

Inherits:
Hook
  • Object
show all
Defined in:
lib/appsignal/hooks/active_support_notifications.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Hook

#initialize, #installed?, register, #try_to_install

Constructor Details

This class inherits a constructor from Appsignal::Hooks::Hook

Instance Method Details

#dependencies_present?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


9
10
11
# File 'lib/appsignal/hooks/active_support_notifications.rb', line 9

def dependencies_present?
  defined?(::ActiveSupport::Notifications::Instrumenter)
end

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/appsignal/hooks/active_support_notifications.rb', line 13

def install
  ::ActiveSupport::Notifications.class_eval do
    def self.instrument(name, payload = {})
      # Don't check the notifier if any subscriber is listening:
      # AppSignal is listening
      instrumenter.instrument(name, payload) do
        yield payload if block_given?
      end
    end
  end

  require "appsignal/integrations/active_support_notifications"
  parent_integration_module = Appsignal::Integrations::ActiveSupportNotificationsIntegration

  if defined?(::ActiveSupport::Notifications::Fanout::Handle)
    install_module(
      parent_integration_module::StartFinishHandlerIntegration,
      ::ActiveSupport::Notifications::Fanout::Handle
    )
  else
    instrumenter = ::ActiveSupport::Notifications::Instrumenter

    if instrumenter.method_defined?(:start) && instrumenter.method_defined?(:finish)
      install_module(parent_integration_module::StartFinishIntegration, instrumenter)
    else
      install_module(parent_integration_module::InstrumentIntegration, instrumenter)
    end

    return unless instrumenter.method_defined?(:finish_with_state)

    install_module(parent_integration_module::FinishStateIntegration, instrumenter)
  end
end

#install_module(mod, instrumenter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/appsignal/hooks/active_support_notifications.rb', line 47

def install_module(mod, instrumenter)
  instrumenter.send(:prepend, mod)
end