Sha256: 1e7759d8e9c5e49e2077c928295262ce1050f2144a3d10c581a1e4819c853a7a

Contents?: true

Size: 1.64 KB

Versions: 42

Compression:

Stored size: 1.64 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, body_format = Appsignal::EventFormatter.format(name, payload)
      Appsignal::Extension.finish_event(
        transaction.transaction_index,
        name,
        title || BLANK,
        body || BLANK,
        body_format || 0
      )
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
appsignal-1.1.9 lib/appsignal/subscriber.rb
appsignal-1.1.9.beta.2 lib/appsignal/subscriber.rb
appsignal-1.1.9.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.8 lib/appsignal/subscriber.rb
appsignal-1.1.7 lib/appsignal/subscriber.rb
appsignal-1.1.7.beta.2 lib/appsignal/subscriber.rb
appsignal-1.2.0.alpha.1 lib/appsignal/subscriber.rb
appsignal-1.1.7.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.6 lib/appsignal/subscriber.rb
appsignal-1.1.6.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.5 lib/appsignal/subscriber.rb
appsignal-1.1.5.beta.4 lib/appsignal/subscriber.rb
appsignal-1.1.5.beta.3 lib/appsignal/subscriber.rb
appsignal-1.1.5.beta.2 lib/appsignal/subscriber.rb
appsignal-1.1.5.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.4 lib/appsignal/subscriber.rb
appsignal-1.1.4.beta.3 lib/appsignal/subscriber.rb
appsignal-1.1.4.beta.2 lib/appsignal/subscriber.rb
appsignal-1.1.4.beta.1 lib/appsignal/subscriber.rb
appsignal-1.1.3 lib/appsignal/subscriber.rb