Sha256: b123fddd2b6ffbba0da658c313f3f4f694dfedfd8074e1cf0a4d8ebbfbb30116

Contents?: true

Size: 1.66 KB

Versions: 22

Compression:

Stored size: 1.66 KB

Contents

module Appsignal
  class Subscriber
    PROCESS_ACTION_PREFIX = 'process_action'.freeze
    PERFORM_JOB_PREFIX    = 'perform_job'.freeze
    BLANK                 = ''.freeze

    def initialize
      subscribe
    end

    def subscribe
      Appsignal.logger.debug('Subscribing to notifications')
      # Subscribe to notifications that don't start with a !
      ActiveSupport::Notifications.subscribe(/^[^!]/, self)
    end

    def unsubscribe
      Appsignal.logger.debug('Unsubscribing from notifications')
      ActiveSupport::Notifications.unsubscribe(self)
    end

    def resubscribe
      Appsignal.logger.debug('Resubscribing to notifications')
      unsubscribe
      subscribe
    end

    def publish(name, *args)
      # Not used, it's part of AS notifications but is not used in Rails
      # and it seems to be unclear what it's function is. See:
      # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/notifications/fanout.rb#L49
    end

    def start(name, id, payload)
      return unless transaction = Appsignal::Transaction.current

      return if transaction.paused?
      Appsignal::Extension.start_event(transaction.transaction_index)
    end

    def finish(name, id, payload)
      return unless transaction = Appsignal::Transaction.current

      if name.start_with?(PROCESS_ACTION_PREFIX, PERFORM_JOB_PREFIX)
        transaction.set_root_event(name, payload)
      end

      return if transaction.paused?

      title, body = Appsignal::EventFormatter.format(name, payload)
      Appsignal::Extension.finish_event(
        transaction.transaction_index,
        name,
        title || BLANK,
        body || BLANK
      )
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
appsignal-0.12.beta.31 lib/appsignal/subscriber.rb
appsignal-0.12.beta.30 lib/appsignal/subscriber.rb
appsignal-0.12.beta.29 lib/appsignal/subscriber.rb
appsignal-0.12.beta.28 lib/appsignal/subscriber.rb
appsignal-0.12.beta.27 lib/appsignal/subscriber.rb
appsignal-0.12.beta.26 lib/appsignal/subscriber.rb
appsignal-0.12.beta.25 lib/appsignal/subscriber.rb
appsignal-0.12.beta.24 lib/appsignal/subscriber.rb
appsignal-0.12.beta.23 lib/appsignal/subscriber.rb
appsignal-0.12.beta.22 lib/appsignal/subscriber.rb
appsignal-0.12.beta.21 lib/appsignal/subscriber.rb
appsignal-0.12.beta.20 lib/appsignal/subscriber.rb
appsignal-0.12.beta.19 lib/appsignal/subscriber.rb
appsignal-0.12.beta.18 lib/appsignal/subscriber.rb
appsignal-0.12.beta.17 lib/appsignal/subscriber.rb
appsignal-0.12.beta.16 lib/appsignal/subscriber.rb
appsignal-0.12.beta.15 lib/appsignal/subscriber.rb
appsignal-0.12.beta.14 lib/appsignal/subscriber.rb
appsignal-0.12.beta.13 lib/appsignal/subscriber.rb
appsignal-0.12.beta.12 lib/appsignal/subscriber.rb