Sha256: 42525e1b5dfec7655b31200fc593f05c6a1b30cd4c94d50faacac97b6eea9cc8

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Appsignal
  class Hooks
    class ActiveSupportNotificationsHook < Appsignal::Hooks::Hook
      register :active_support_notifications

      BANG = "!".freeze

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

      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
appsignal-2.1.2 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.1.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.1.1.beta.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.1.0 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.1.0.beta.1 lib/appsignal/hooks/active_support_notifications.rb