Sha256: 66494c7567adb89896276b38cad59c3360da329ff03b481043d8872c556c80bf

Contents?: true

Size: 1.43 KB

Versions: 24

Compression:

Stored size: 1.43 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"
        instrumenter = ::ActiveSupport::Notifications::Instrumenter
        parent_integration_module = Appsignal::Integrations::ActiveSupportNotificationsIntegration
        if instrumenter.method_defined?(:start) && instrumenter.method_defined?(:finish)
          install_module(parent_integration_module::StartFinishIntegration)
        else
          install_module(parent_integration_module::InstrumentIntegration)
        end

        return unless instrumenter.method_defined?(:finish_with_state)

        install_module(parent_integration_module::FinishStateIntegration)
      end

      def install_module(mod)
        ::ActiveSupport::Notifications::Instrumenter.send(:prepend, mod)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
appsignal-3.4.12-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.12 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.11-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.11 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.10-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.10 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.9-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.9 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.8-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.8 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.7-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.7 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.6-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.6 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.5-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.5 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.4-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.4 lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.3-java lib/appsignal/hooks/active_support_notifications.rb
appsignal-3.4.3 lib/appsignal/hooks/active_support_notifications.rb