Sha256: 860f95f0052b4b1caa5eb3cd9c277e0e263f0fdb9735da64c63e90a4e6676bca

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module PlainApm
  module Hooks
    class ActiveSupportSubscriber
      def install
        begin
          require "active_support/notifications"
        rescue LoadError
          return
        end

        asn = ActiveSupport::Notifications

        # Rails >= 6.1
        if asn.respond_to?(:monotonic_subscribe)
          asn.monotonic_subscribe(notification_pattern, method(:collect))
        else
          asn.subscribe(notification_pattern, method(:collect))
        end
      end

      def collect(event)
        # id / transaction_id is by instrumenter and thread
        payload = payload(event)

        return if payload.nil?

        Agent.instance.collect(payload)
      end

      private

      def pattern
        raise "Not implemented"
      end

      def payload(event)
        raise "Not implemented"
      end

      def filtered_backtrace
        if defined?(Rails) && defined?(Rails::BacktraceCleaner)
          @cleaner ||= Rails::BacktraceCleaner.new
          @cleaner.clean(caller)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
plain_apm-0.5.7 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.6 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.5 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.4 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.3 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.2 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.1 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.5.0 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.4.0 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.3.0 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.2.9 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.2.8 lib/plain_apm/hooks/active_support_subscriber.rb