class OneApm::Agent::Instrumentation::EventedSubscriber

Public Class Methods

new() click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 7
def initialize
  @queue_key = ['OneApm', self.class.name, object_id].join('-')
end
subscribe(pattern) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 18
def self.subscribe(pattern)
  if !subscribed?
    ActiveSupport::Notifications.subscribe(pattern, new)
  end
end
subscribed?() click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 11
def self.subscribed?
  # TODO: need to talk to Rails core about an API for this,
  # rather than digging through Listener ivars
  ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers) \
    .find{|s| s.instance_variable_get(:@delegate).class == self }
end

Public Instance Methods

event_stack() click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 56
def event_stack
  Thread.current[@queue_key] ||= Hash.new {|h,id| h[id] = [] }
end
finish(name, id, payload) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 30
def finish(name, id, payload)
  pop_event(id)
end
log_notification_error(error, name, event_type) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 34
def log_notification_error(error, name, event_type)
  # These are important enough failures that we want the backtraces
  # logged at error level, hence the explicit log_exception call.
  OneApm::Manager.logger.error("Error during #{event_type} callback for event '#{name}':")
  OneApm::Manager.logger.log_exception(:error, error)
end
pop_event(transaction_id) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 50
def pop_event(transaction_id)
  event = event_stack[transaction_id].pop
  event.end = Time.now
  return event
end
push_event(event) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 41
def push_event(event)
  parent = event_stack[event.transaction_id].last
  if parent && event.respond_to?(:parent=)
    event.parent = parent
    parent << event
  end
  event_stack[event.transaction_id].push event
end
start(name, id, payload) click to toggle source
# File lib/one_apm/inst/support/evented_subscriber.rb, line 24
def start(name, id, payload)
  event = ActiveSupport::Notifications::Event.new(name, Time.now, nil, id, payload)
  push_event(event)
  return event
end