Sha256: d3cc7834f90e1889e552c7269d4de601f0cf2dfd5098516f1977291ed9cfaa3d

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

module Appsignal
  class Subscriber
    BLANK = ''.freeze

    attr_reader :as_subscriber

    def initialize
      subscribe
    end

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

    def unsubscribe
      if @as_subscriber
        Appsignal.logger.debug('Unsubscribing from notifications')
        ActiveSupport::Notifications.unsubscribe(@as_subscriber)
        @as_subscriber = nil
      end
    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

12 entries across 12 versions & 1 rubygems

Version Path
appsignal-1.0.4 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.6 lib/appsignal/subscriber.rb
appsignal-1.0.3 lib/appsignal/subscriber.rb
appsignal-1.0.3.beta.2 lib/appsignal/subscriber.rb
appsignal-1.0.3.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.5 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.4 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.3 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.2 lib/appsignal/subscriber.rb
appsignal-1.1.0.beta.1 lib/appsignal/subscriber.rb
appsignal-1.0.2 lib/appsignal/subscriber.rb
appsignal-1.0.2.beta.4 lib/appsignal/subscriber.rb