class ElasticAPM::Subscriber

@api private

Constants

Notification

AS::Notifications API

Public Class Methods

new(agent) click to toggle source
# File lib/elastic_apm/subscriber.rb, line 11
def initialize(agent)
  @agent = agent
  @normalizers = Normalizers.build(agent.config)
end

Public Instance Methods

finish(_name, id, _payload) click to toggle source
# File lib/elastic_apm/subscriber.rb, line 49
def finish(_name, id, _payload)
  # debug "AS::Notification#finish:#{name}:#{id}"
  return unless (transaction = @agent.current_transaction)

  while (notification = transaction.notifications.pop)
    next unless notification.id == id

    if (span = notification.span)
      @agent.end_span if span == @agent.current_span
    end
    return
  end
end
register!() click to toggle source
# File lib/elastic_apm/subscriber.rb, line 16
def register!
  unregister! if @subscription

  @subscription =
    ActiveSupport::Notifications.subscribe(notifications_regex, self)
end
start(name, id, payload) click to toggle source
# File lib/elastic_apm/subscriber.rb, line 32
def start(name, id, payload)
  # debug "AS::Notification#start:#{name}:#{id}"
  return unless (transaction = @agent.current_transaction)

  normalized = @normalizers.normalize(transaction, name, payload)

  span =
    if normalized == :skip
      nil
    else
      name, type, context = normalized
      @agent.start_span(name, type, context: context)
    end

  transaction.notifications << Notification.new(id, span)
end
unregister!() click to toggle source
# File lib/elastic_apm/subscriber.rb, line 23
def unregister!
  ActiveSupport::Notifications.unsubscribe @subscription
  @subscription = nil
end

Private Instance Methods

notifications_regex() click to toggle source
# File lib/elastic_apm/subscriber.rb, line 65
def notifications_regex
  @notifications_regex ||= /(#{@normalizers.keys.join('|')})/
end