Class: Appsignal::Hooks::ActiveSupportNotificationsHook

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

Constant Summary collapse

BANG =
'!'.freeze

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

Returns:

  • (Boolean)


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

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

#installObject



12
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
# File 'lib/appsignal/hooks/active_support_notifications.rb', line 12

def install
  ::ActiveSupport::Notifications::Instrumenter.class_eval do
    alias instrument_without_appsignal instrument

    def instrument(name, payload={}, &block)
      # Events that start with a bang are internal to Rails
      instrument_this = name[0] != BANG

      if instrument_this
        transaction = Appsignal::Transaction.current
        transaction.start_event
      end

      return_value = instrument_without_appsignal(name, payload, &block)

      if instrument_this
        title, body, body_format = Appsignal::EventFormatter.format(name, payload)
        transaction.finish_event(
          name,
          title,
          body,
          body_format
        )
      end

      return_value
    end
  end
end