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 28
def initialize(agent)
  @agent = agent
  @normalizers = Normalizers.build(agent.config)
end

Public Instance Methods

finish(name, id, payload) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity

# File lib/elastic_apm/subscriber.rb, line 73
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)
      if @agent.config.span_frames_min_duration?
        span.original_backtrace ||= @normalizers.backtrace(name, payload)
      end
      @agent.end_span if span == @agent.current_span
    end
    return
  end
end
register!() click to toggle source
# File lib/elastic_apm/subscriber.rb, line 33
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 49
def start(name, id, payload)
  return unless (transaction = @agent.current_transaction)

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

  span =
    if normalized == :skip
      nil
    else
      name, type, subtype, action, context = normalized

      @agent.start_span(
        name,
        type,
        subtype: subtype,
        action: action,
        context: context
      )
    end

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

Private Instance Methods

notifications_regex() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity

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