Module: NewRelic::Agent::Agent::InstanceMethods
- Included in:
- NewRelic::Agent::Agent
- Defined in:
- lib/new_relic/agent/agent.rb
Overview
Holds all the methods defined on NewRelic::Agent::Agent instances
Instance Attribute Summary collapse
- #adaptive_sampler ⇒ Object readonly
- #attribute_filter ⇒ Object readonly
-
#cross_process_id ⇒ Object
readonly
cross application tracing ids and encoding.
- #custom_event_aggregator ⇒ Object readonly
-
#error_collector ⇒ Object
readonly
error collector is a simple collection of recorded errors.
-
#events ⇒ Object
readonly
Global events dispatcher.
-
#javascript_instrumentor ⇒ Object
readonly
builder for JS agent scripts to inject.
- #log_event_aggregator ⇒ Object readonly
-
#monitors ⇒ Object
readonly
listens and responds to events that need to process headers for synthetics and distributed tracing.
-
#monotonic_gc_profiler ⇒ Object
readonly
GC::Profiler.total_time is not monotonic so we wrap it.
-
#record_sql ⇒ Object
readonly
whether we should record raw, obfuscated, or no sql.
- #serverless_handler ⇒ Object readonly
-
#service ⇒ Object
readonly
service for communicating with collector.
- #span_event_aggregator ⇒ Object readonly
- #sql_sampler ⇒ Object readonly
-
#stats_engine ⇒ Object
readonly
the statistics engine that holds all the timeslice data.
- #transaction_event_recorder ⇒ Object readonly
-
#transaction_rules ⇒ Object
Transaction and metric renaming rules as provided by the collector on connect.
-
#transaction_sampler ⇒ Object
readonly
the transaction sampler that handles recording transactions.
Instance Method Summary collapse
-
#after_fork(options = {}) ⇒ Object
This method should be called in a forked process after a fork.
- #agent_id=(agent_id) ⇒ Object
-
#drop_buffered_data ⇒ Object
Clear out the metric data, errors, and transaction traces, etc.
-
#flush_pipe_data ⇒ Object
used only by resque.
- #install_pipe_service(channel_id) ⇒ Object
- #merge_data_for_endpoint(endpoint, data) ⇒ Object
- #needs_after_fork_work? ⇒ Boolean
-
#pop_trace_execution_flag ⇒ Object
Pop the current trace execution status.
-
#push_trace_execution_flag(should_trace = false) ⇒ Object
Push flag indicating whether we should be tracing in this thread.
-
#reset_objects_with_locks ⇒ Object
Clear out state for any objects that we know lock from our parents This is necessary for cases where we’re in a forked child and Ruby might be holding locks for background thread that aren’t there anymore.
- #revert_to_default_configuration ⇒ Object
-
#set_record_sql(should_record) ⇒ Object
Sets a thread local variable as to whether we should or should not record sql in the current thread.
- #synthetics_event_aggregator ⇒ Object
- #transaction_event_aggregator ⇒ Object
- #trap_signals_for_litespeed ⇒ Object
Instance Attribute Details
#adaptive_sampler ⇒ Object (readonly)
176 177 178 |
# File 'lib/new_relic/agent/agent.rb', line 176 def adaptive_sampler @adaptive_sampler end |
#attribute_filter ⇒ Object (readonly)
175 176 177 |
# File 'lib/new_relic/agent/agent.rb', line 175 def attribute_filter @attribute_filter end |
#cross_process_id ⇒ Object (readonly)
cross application tracing ids and encoding
154 155 156 |
# File 'lib/new_relic/agent/agent.rb', line 154 def cross_process_id @cross_process_id end |
#custom_event_aggregator ⇒ Object (readonly)
171 172 173 |
# File 'lib/new_relic/agent/agent.rb', line 171 def custom_event_aggregator @custom_event_aggregator end |
#error_collector ⇒ Object (readonly)
error collector is a simple collection of recorded errors
148 149 150 |
# File 'lib/new_relic/agent/agent.rb', line 148 def error_collector @error_collector end |
#events ⇒ Object (readonly)
Global events dispatcher. This will provides our primary mechanism for agent-wide events, such as finishing configuration, error notification and request before/after from Rack.
160 161 162 |
# File 'lib/new_relic/agent/agent.rb', line 160 def events @events end |
#javascript_instrumentor ⇒ Object (readonly)
builder for JS agent scripts to inject
152 153 154 |
# File 'lib/new_relic/agent/agent.rb', line 152 def javascript_instrumentor @javascript_instrumentor end |
#log_event_aggregator ⇒ Object (readonly)
173 174 175 |
# File 'lib/new_relic/agent/agent.rb', line 173 def log_event_aggregator @log_event_aggregator end |
#monitors ⇒ Object (readonly)
listens and responds to events that need to process headers for synthetics and distributed tracing
164 165 166 |
# File 'lib/new_relic/agent/agent.rb', line 164 def monitors @monitors end |
#monotonic_gc_profiler ⇒ Object (readonly)
GC::Profiler.total_time is not monotonic so we wrap it.
170 171 172 |
# File 'lib/new_relic/agent/agent.rb', line 170 def monotonic_gc_profiler @monotonic_gc_profiler end |
#record_sql ⇒ Object (readonly)
whether we should record raw, obfuscated, or no sql
150 151 152 |
# File 'lib/new_relic/agent/agent.rb', line 150 def record_sql @record_sql end |
#serverless_handler ⇒ Object (readonly)
177 178 179 |
# File 'lib/new_relic/agent/agent.rb', line 177 def serverless_handler @serverless_handler end |
#service ⇒ Object (readonly)
service for communicating with collector
156 157 158 |
# File 'lib/new_relic/agent/agent.rb', line 156 def service @service end |
#span_event_aggregator ⇒ Object (readonly)
172 173 174 |
# File 'lib/new_relic/agent/agent.rb', line 172 def span_event_aggregator @span_event_aggregator end |
#sql_sampler ⇒ Object (readonly)
146 147 148 |
# File 'lib/new_relic/agent/agent.rb', line 146 def sql_sampler @sql_sampler end |
#stats_engine ⇒ Object (readonly)
the statistics engine that holds all the timeslice data
143 144 145 |
# File 'lib/new_relic/agent/agent.rb', line 143 def stats_engine @stats_engine end |
#transaction_event_recorder ⇒ Object (readonly)
174 175 176 |
# File 'lib/new_relic/agent/agent.rb', line 174 def transaction_event_recorder @transaction_event_recorder end |
#transaction_rules ⇒ Object
Transaction and metric renaming rules as provided by the collector on connect. The former are applied during txns, the latter during harvest.
168 169 170 |
# File 'lib/new_relic/agent/agent.rb', line 168 def transaction_rules @transaction_rules end |
#transaction_sampler ⇒ Object (readonly)
the transaction sampler that handles recording transactions
145 146 147 |
# File 'lib/new_relic/agent/agent.rb', line 145 def transaction_sampler @transaction_sampler end |
Instance Method Details
#after_fork(options = {}) ⇒ Object
This method should be called in a forked process after a fork. It assumes the parent process initialized the agent, but does not assume the agent started.
The call is idempotent, but not reentrant.
-
It clears any metrics carried over from the parent process
-
Restarts the sampler thread if necessary
-
Initiates a new agent run and worker loop unless that was done in the parent process and
:force_reconnect
is not true
Options:
-
:force_reconnect => true
to force the spawned process to establish a new connection, such as when forking a long running process. The default is false–it will only connect to the server if the parent had not connected. -
:keep_retrying => false
if we try to initiate a new connection, this tells me to only try it once so this method returns quickly if there is some kind of latency with the server.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/new_relic/agent/agent.rb', line 210 def after_fork( = {}) return unless needs_after_fork_work? ::NewRelic::Agent.logger.debug("Starting the worker thread in #{Process.pid} (parent #{Process.ppid}) after forking.") channel_id = [:report_to_channel] install_pipe_service(channel_id) if channel_id # Clear out locks and stats left over from parent process reset_objects_with_locks drop_buffered_data setup_and_start_agent() end |
#agent_id=(agent_id) ⇒ Object
187 188 189 |
# File 'lib/new_relic/agent/agent.rb', line 187 def agent_id=(agent_id) @service.agent_id = agent_id end |
#drop_buffered_data ⇒ Object
Clear out the metric data, errors, and transaction traces, etc.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/new_relic/agent/agent.rb', line 291 def drop_buffered_data @stats_engine.reset! @error_collector.drop_buffered_data @transaction_sampler.reset! @transaction_event_recorder.drop_buffered_data @custom_event_aggregator.reset! @span_event_aggregator.reset! @log_event_aggregator.reset! @sql_sampler.reset! if Agent.config[:clear_transaction_state_after_fork] Tracer.clear_state end end |
#flush_pipe_data ⇒ Object
used only by resque
313 314 315 316 317 |
# File 'lib/new_relic/agent/agent.rb', line 313 def flush_pipe_data # used only by resque if connected? && @service.is_a?(PipeService) transmit_data_types end end |
#install_pipe_service(channel_id) ⇒ Object
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/new_relic/agent/agent.rb', line 241 def install_pipe_service(channel_id) @service = PipeService.new(channel_id) if connected? @connected_pid = Process.pid else ::NewRelic::Agent.logger.debug("Child process #{Process.pid} not reporting to non-connected parent (process #{Process.ppid}).") @service.shutdown disconnect end end |
#merge_data_for_endpoint(endpoint, data) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/new_relic/agent/agent.rb', line 340 def merge_data_for_endpoint(endpoint, data) if data && !data.empty? container = container_for_endpoint(endpoint) if container.respond_to?(:has_metadata?) && container. container_for_endpoint(endpoint).merge!(data, false) else container_for_endpoint(endpoint).merge!(data) end end rescue => e NewRelic::Agent.logger.error("Error while merging #{endpoint} data from child: ", e) end |
#needs_after_fork_work? ⇒ Boolean
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/new_relic/agent/agent.rb', line 225 def needs_after_fork_work? needs_restart = false @after_fork_lock.synchronize do needs_restart = @harvester.needs_restart? @harvester.mark_started end return false if !needs_restart || !Agent.config[:agent_enabled] || !Agent.config[:monitor_mode] || disconnected? || !control.security_settings_valid? true end |
#pop_trace_execution_flag ⇒ Object
Pop the current trace execution status. Restore trace execution status to what it was before we pushed the current flag.
286 287 288 |
# File 'lib/new_relic/agent/agent.rb', line 286 def pop_trace_execution_flag # THREAD_LOCAL_ACCESS Tracer.state.pop_traced end |
#push_trace_execution_flag(should_trace = false) ⇒ Object
Push flag indicating whether we should be tracing in this thread. This uses a stack which allows us to disable tracing children of a transaction without affecting the tracing of the whole transaction
280 281 282 |
# File 'lib/new_relic/agent/agent.rb', line 280 def push_trace_execution_flag(should_trace = false) # THREAD_LOCAL_ACCESS Tracer.state.push_traced(should_trace) end |
#reset_objects_with_locks ⇒ Object
Clear out state for any objects that we know lock from our parents This is necessary for cases where we’re in a forked child and Ruby might be holding locks for background thread that aren’t there anymore.
309 310 311 |
# File 'lib/new_relic/agent/agent.rb', line 309 def reset_objects_with_locks @stats_engine = StatsEngine.new end |
#revert_to_default_configuration ⇒ Object
252 253 254 255 |
# File 'lib/new_relic/agent/agent.rb', line 252 def revert_to_default_configuration Agent.config.remove_config_type(:manual) Agent.config.remove_config_type(:server) end |
#set_record_sql(should_record) ⇒ Object
Sets a thread local variable as to whether we should or should not record sql in the current thread. Returns the previous value, if there is one
269 270 271 272 273 274 |
# File 'lib/new_relic/agent/agent.rb', line 269 def set_record_sql(should_record) # THREAD_LOCAL_ACCESS state = Tracer.state prev = state.record_sql state.record_sql = should_record prev.nil? || prev end |
#synthetics_event_aggregator ⇒ Object
183 184 185 |
# File 'lib/new_relic/agent/agent.rb', line 183 def synthetics_event_aggregator @transaction_event_recorder.synthetics_event_aggregator end |
#transaction_event_aggregator ⇒ Object
179 180 181 |
# File 'lib/new_relic/agent/agent.rb', line 179 def transaction_event_aggregator @transaction_event_recorder.transaction_event_aggregator end |
#trap_signals_for_litespeed ⇒ Object
257 258 259 260 261 262 263 264 |
# File 'lib/new_relic/agent/agent.rb', line 257 def trap_signals_for_litespeed # if litespeed, then ignore all future SIGUSR1 - it's # litespeed trying to shut us down if Agent.config[:dispatcher] == :litespeed Signal.trap('SIGUSR1', 'IGNORE') Signal.trap('SIGTERM', 'IGNORE') end end |