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.
-
#health_check ⇒ Object
readonly
the agent control health check file generator.
-
#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)
182 183 184 |
# File 'lib/new_relic/agent/agent.rb', line 182 def adaptive_sampler @adaptive_sampler end |
#attribute_filter ⇒ Object (readonly)
181 182 183 |
# File 'lib/new_relic/agent/agent.rb', line 181 def attribute_filter @attribute_filter end |
#cross_process_id ⇒ Object (readonly)
cross application tracing ids and encoding
160 161 162 |
# File 'lib/new_relic/agent/agent.rb', line 160 def cross_process_id @cross_process_id end |
#custom_event_aggregator ⇒ Object (readonly)
177 178 179 |
# File 'lib/new_relic/agent/agent.rb', line 177 def custom_event_aggregator @custom_event_aggregator end |
#error_collector ⇒ Object (readonly)
error collector is a simple collection of recorded errors
154 155 156 |
# File 'lib/new_relic/agent/agent.rb', line 154 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.
166 167 168 |
# File 'lib/new_relic/agent/agent.rb', line 166 def events @events end |
#health_check ⇒ Object (readonly)
the agent control health check file generator
147 148 149 |
# File 'lib/new_relic/agent/agent.rb', line 147 def health_check @health_check end |
#javascript_instrumentor ⇒ Object (readonly)
builder for JS agent scripts to inject
158 159 160 |
# File 'lib/new_relic/agent/agent.rb', line 158 def javascript_instrumentor @javascript_instrumentor end |
#log_event_aggregator ⇒ Object (readonly)
179 180 181 |
# File 'lib/new_relic/agent/agent.rb', line 179 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
170 171 172 |
# File 'lib/new_relic/agent/agent.rb', line 170 def monitors @monitors end |
#monotonic_gc_profiler ⇒ Object (readonly)
GC::Profiler.total_time is not monotonic so we wrap it.
176 177 178 |
# File 'lib/new_relic/agent/agent.rb', line 176 def monotonic_gc_profiler @monotonic_gc_profiler end |
#record_sql ⇒ Object (readonly)
whether we should record raw, obfuscated, or no sql
156 157 158 |
# File 'lib/new_relic/agent/agent.rb', line 156 def record_sql @record_sql end |
#serverless_handler ⇒ Object (readonly)
183 184 185 |
# File 'lib/new_relic/agent/agent.rb', line 183 def serverless_handler @serverless_handler end |
#service ⇒ Object (readonly)
service for communicating with collector
162 163 164 |
# File 'lib/new_relic/agent/agent.rb', line 162 def service @service end |
#span_event_aggregator ⇒ Object (readonly)
178 179 180 |
# File 'lib/new_relic/agent/agent.rb', line 178 def span_event_aggregator @span_event_aggregator end |
#sql_sampler ⇒ Object (readonly)
152 153 154 |
# File 'lib/new_relic/agent/agent.rb', line 152 def sql_sampler @sql_sampler end |
#stats_engine ⇒ Object (readonly)
the statistics engine that holds all the timeslice data
149 150 151 |
# File 'lib/new_relic/agent/agent.rb', line 149 def stats_engine @stats_engine end |
#transaction_event_recorder ⇒ Object (readonly)
180 181 182 |
# File 'lib/new_relic/agent/agent.rb', line 180 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.
174 175 176 |
# File 'lib/new_relic/agent/agent.rb', line 174 def transaction_rules @transaction_rules end |
#transaction_sampler ⇒ Object (readonly)
the transaction sampler that handles recording transactions
151 152 153 |
# File 'lib/new_relic/agent/agent.rb', line 151 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_reconnectis not true
Options:
-
:force_reconnect => trueto 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 => falseif 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.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/new_relic/agent/agent.rb', line 216 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
193 194 195 |
# File 'lib/new_relic/agent/agent.rb', line 193 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.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/new_relic/agent/agent.rb', line 297 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
319 320 321 322 323 |
# File 'lib/new_relic/agent/agent.rb', line 319 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
247 248 249 250 251 252 253 254 255 256 |
# File 'lib/new_relic/agent/agent.rb', line 247 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
346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/new_relic/agent/agent.rb', line 346 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
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/new_relic/agent/agent.rb', line 231 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.
292 293 294 |
# File 'lib/new_relic/agent/agent.rb', line 292 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
286 287 288 |
# File 'lib/new_relic/agent/agent.rb', line 286 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.
315 316 317 |
# File 'lib/new_relic/agent/agent.rb', line 315 def reset_objects_with_locks @stats_engine = StatsEngine.new end |
#revert_to_default_configuration ⇒ Object
258 259 260 261 |
# File 'lib/new_relic/agent/agent.rb', line 258 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
275 276 277 278 279 280 |
# File 'lib/new_relic/agent/agent.rb', line 275 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
189 190 191 |
# File 'lib/new_relic/agent/agent.rb', line 189 def synthetics_event_aggregator @transaction_event_recorder.synthetics_event_aggregator end |
#transaction_event_aggregator ⇒ Object
185 186 187 |
# File 'lib/new_relic/agent/agent.rb', line 185 def transaction_event_aggregator @transaction_event_recorder.transaction_event_aggregator end |
#trap_signals_for_litespeed ⇒ Object
263 264 265 266 267 268 269 270 |
# File 'lib/new_relic/agent/agent.rb', line 263 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 |