Sha256: 17c6264af5526ec7b5b6cdc6b756bfe4d0bee3e6bb39f22754a7e01f535fbb54

Contents?: true

Size: 1.72 KB

Versions: 126

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

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

      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

        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

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

Version data entries

126 entries across 126 versions & 1 rubygems

Version Path
appsignal-4.3.3-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.3 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.2-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.2 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.1-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.0-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.3.0 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.3-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.3 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.2-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.2 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.1-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.1 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.0-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.2.0 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.1.3-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.1.3 lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.1.2-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-4.1.2 lib/appsignal/hooks/active_support_notifications.rb