Sha256: ea76ef7a89b6822a7b19c258c427514ec5e792e2cd09e7ce6b60dda349b58d10

Contents?: true

Size: 1.06 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
plain_apm-0.6.6 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.6.5 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.6.4 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.6.3 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.6.2 lib/plain_apm/hooks/active_support_subscriber.rb
plain_apm-0.6.1 lib/plain_apm/hooks/active_support_subscriber.rb