class NewRelic::Agent::Agent

The agent is a singleton that is instantiated when the plugin is activated. It collects performance data from ruby applications in realtime as the application runs, and periodically sends that data to the NewRelic server.

Public Class Methods

config() click to toggle source
# File lib/new_relic/agent/agent.rb, line 56
def self.config
  ::NewRelic::Agent.config
end
new() click to toggle source
# File lib/new_relic/agent/agent.rb, line 68
def initialize
  init_basics
  init_components
  init_event_handlers
  setup_attribute_filter
end

Public Instance Methods

refresh_attribute_filter() click to toggle source
# File lib/new_relic/agent/agent.rb, line 126
def refresh_attribute_filter
  @attribute_filter = AttributeFilter.new(Agent.config)
end

Private Instance Methods

init_basics() click to toggle source
# File lib/new_relic/agent/agent.rb, line 77
def init_basics
  @started = false
  @event_loop = nil
  @worker_thread = nil
  @connect_state = :pending
  @connect_attempts = 0
  @waited_on_connect = nil
  @connected_pid = nil
  @wait_on_connect_mutex = Mutex.new
  @after_fork_lock = Mutex.new
  @wait_on_connect_condition = ConditionVariable.new
end
init_components() click to toggle source
# File lib/new_relic/agent/agent.rb, line 90
def init_components
  @service = NewRelicService.new
  @events = EventListener.new
  @stats_engine = StatsEngine.new
  @transaction_sampler = TransactionSampler.new
  @sql_sampler = SqlSampler.new
  @transaction_rules = RulesEngine.new
  @monotonic_gc_profiler = VM::MonotonicGCProfiler.new
  @adaptive_sampler = AdaptiveSampler.new(Agent.config[:sampling_target],
    Agent.config[:sampling_target_period_in_seconds])
  @serverless_handler = ServerlessHandler.new
end
init_event_handlers() click to toggle source
# File lib/new_relic/agent/agent.rb, line 103
def init_event_handlers
  @agent_command_router = Commands::AgentCommandRouter.new(@events)
  @monitors = Monitors.new(@events)
  @error_collector = ErrorCollector.new(@events)
  @harvest_samplers = SamplerCollection.new(@events)
  @javascript_instrumentor = JavaScriptInstrumentor.new(@events)
  @harvester = Harvester.new(@events)
  @transaction_event_recorder = TransactionEventRecorder.new(@events)
  @custom_event_aggregator = CustomEventAggregator.new(@events)
  @span_event_aggregator = SpanEventAggregator.new(@events)
  @log_event_aggregator = LogEventAggregator.new(@events)
end
setup_attribute_filter() click to toggle source
# File lib/new_relic/agent/agent.rb, line 116
def setup_attribute_filter
  refresh_attribute_filter

  @events.subscribe(:initial_configuration_complete) do
    refresh_attribute_filter
  end
end