class InfluxReporter::Subscriber

@api private

Attributes

config[R]

Public Class Methods

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

Public Instance Methods

finish(_name, id, _payload) click to toggle source
# File lib/influx_reporter/subscriber.rb, line 60
def finish(_name, id, _payload)
  return unless transaction = @client.current_transaction

  while notification = transaction.notifications.pop
    next unless notification.id == id
    if trace = notification.trace
      trace.done
    end
    return
  end
end
register!() click to toggle source
# File lib/influx_reporter/subscriber.rb, line 19
def register!
  unregister! if @subscription
  @subscription = ActiveSupport::Notifications.subscribe actions_regex, self
end
start(name, id, payload) click to toggle source
# File lib/influx_reporter/subscriber.rb, line 39
def start(name, id, payload)
  return unless transaction = @client.current_transaction

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

  trace = nil

  unless normalized == :skip
    sig, kind, extra = normalized

    trace = Trace.new(transaction, sig, kind, transaction.running_traces, extra)
    offset = transaction.current_offset

    transaction.traces << trace

    trace.start offset
  end

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

Private Instance Methods

actions_regex() click to toggle source
# File lib/influx_reporter/subscriber.rb, line 74
def actions_regex
  @actions_regex ||= Regexp.new(
      '(' + @normalizers.keys.join('|') + ')'
  )
end