Sha256: edf50d48e8b18fa5c550ad4526d827986b9fffe487eb505724af4c4330f087c9

Contents?: true

Size: 1.47 KB

Versions: 72

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module Appsignal
  class Hooks
    # @api private
    class ActiveSupportNotificationsHook < Appsignal::Hooks::Hook
      register :active_support_notifications

      BANG = "!".freeze

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

      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

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

            Appsignal::Transaction.current.start_event if instrument_this

            instrument_without_appsignal(name, payload, &block)
          ensure
            if instrument_this
              title, body, body_format = Appsignal::EventFormatter.format(name, payload)
              Appsignal::Transaction.current.finish_event(
                name.to_s,
                title,
                body,
                body_format
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
appsignal-2.10.2-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.10.2 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.10.1-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.10.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.10.0-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.10.0 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18.beta.2-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18.beta.2 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18.beta.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.18.beta.1-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.17-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.17 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.16-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.16 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.15-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.15 lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.14-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-2.9.14 lib/appsignal/hooks/active_support_notifications.rb