Sha256: cea2c5fac164e63256da284c1c861c0b2344f0bb81193b44f1d9274bad37aabc

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

module Appsignal
  class Subscriber
    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.nil_transaction? || transaction.paused?

      Appsignal::Extension.start_event(transaction.transaction_index)
    end

    def finish(name, id, payload)
      return unless transaction = Appsignal::Transaction.current
      return if transaction.nil_transaction? || 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

6 entries across 6 versions & 1 rubygems

Version Path
appsignal-1.0.2.beta.3 lib/appsignal/subscriber.rb
appsignal-1.0.2.beta.2 lib/appsignal/subscriber.rb
appsignal-1.0.2.beta.1 lib/appsignal/subscriber.rb
appsignal-1.0.1 lib/appsignal/subscriber.rb
appsignal-1.0.0 lib/appsignal/subscriber.rb
appsignal-1.0.0.rc.1 lib/appsignal/subscriber.rb