Module NewRelic::Agent
In: lib/new_relic/agent/error_event_aggregator.rb
lib/new_relic/agent/null_logger.rb
lib/new_relic/agent/event_buffer.rb
lib/new_relic/agent/datastores/mongo.rb
lib/new_relic/agent/datastores/mongo/obfuscator.rb
lib/new_relic/agent/datastores/mongo/event_formatter.rb
lib/new_relic/agent/datastores/mongo/metric_translator.rb
lib/new_relic/agent/datastores/mongo/statement_formatter.rb
lib/new_relic/agent/datastores/metric_helper.rb
lib/new_relic/agent/datastores/redis.rb
lib/new_relic/agent/rules_engine.rb
lib/new_relic/agent/transaction_sample_builder.rb
lib/new_relic/agent/sampler.rb
lib/new_relic/agent/method_tracer.rb
lib/new_relic/agent/encoding_normalizer.rb
lib/new_relic/agent/traced_method_stack.rb
lib/new_relic/agent/pipe_service.rb
lib/new_relic/agent/error_trace_aggregator.rb
lib/new_relic/agent/harvester.rb
lib/new_relic/agent/obfuscator.rb
lib/new_relic/agent/vm/monotonic_gc_profiler.rb
lib/new_relic/agent/vm/snapshot.rb
lib/new_relic/agent/vm/rubinius_vm.rb
lib/new_relic/agent/vm/mri_vm.rb
lib/new_relic/agent/vm/jruby_vm.rb
lib/new_relic/agent/configuration/high_security_source.rb
lib/new_relic/agent/configuration/yaml_source.rb
lib/new_relic/agent/configuration/manager.rb
lib/new_relic/agent/configuration/mask_defaults.rb
lib/new_relic/agent/configuration/dotted_hash.rb
lib/new_relic/agent/configuration/default_source.rb
lib/new_relic/agent/configuration/environment_source.rb
lib/new_relic/agent/configuration/server_source.rb
lib/new_relic/agent/configuration/manual_source.rb
lib/new_relic/agent/hostname.rb
lib/new_relic/agent/event_aggregator.rb
lib/new_relic/agent/attribute_filter.rb
lib/new_relic/agent/error_collector.rb
lib/new_relic/agent/transaction_state.rb
lib/new_relic/agent/synthetics_event_buffer.rb
lib/new_relic/agent/http_clients/http_rb_wrappers.rb
lib/new_relic/agent/http_clients/curb_wrappers.rb
lib/new_relic/agent/http_clients/net_http_wrappers.rb
lib/new_relic/agent/http_clients/uri_util.rb
lib/new_relic/agent/http_clients/httpclient_wrappers.rb
lib/new_relic/agent/http_clients/excon_wrappers.rb
lib/new_relic/agent/http_clients/typhoeus_wrappers.rb
lib/new_relic/agent/event_loop.rb
lib/new_relic/agent/event_listener.rb
lib/new_relic/agent/cross_app_monitor.rb
lib/new_relic/agent/stats.rb
lib/new_relic/agent/datastores.rb
lib/new_relic/agent/payload_metric_mapping.rb
lib/new_relic/agent/utilization_data.rb
lib/new_relic/agent/vm.rb
lib/new_relic/agent/commands/agent_command_router.rb
lib/new_relic/agent/commands/thread_profiler_session.rb
lib/new_relic/agent/commands/agent_command.rb
lib/new_relic/agent/commands/xray_session_collection.rb
lib/new_relic/agent/commands/xray_session.rb
lib/new_relic/agent/custom_event_aggregator.rb
lib/new_relic/agent/transaction/abstract_segment.rb
lib/new_relic/agent/transaction/external_request_segment.rb
lib/new_relic/agent/transaction/segment.rb
lib/new_relic/agent/transaction/request_attributes.rb
lib/new_relic/agent/transaction/transaction_sample_buffer.rb
lib/new_relic/agent/transaction/trace_node.rb
lib/new_relic/agent/transaction/synthetics_sample_buffer.rb
lib/new_relic/agent/transaction/slowest_sample_buffer.rb
lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb
lib/new_relic/agent/transaction/tracing.rb
lib/new_relic/agent/transaction/xray_sample_buffer.rb
lib/new_relic/agent/transaction/attributes.rb
lib/new_relic/agent/transaction/trace.rb
lib/new_relic/agent/transaction/datastore_segment.rb
lib/new_relic/agent/audit_logger.rb
lib/new_relic/agent/samplers/vm_sampler.rb
lib/new_relic/agent/samplers/object_sampler.rb
lib/new_relic/agent/samplers/delayed_job_sampler.rb
lib/new_relic/agent/samplers/cpu_sampler.rb
lib/new_relic/agent/samplers/memory_sampler.rb
lib/new_relic/agent/cross_app_tracing.rb
lib/new_relic/agent/sampled_buffer.rb
lib/new_relic/agent/instrumentation.rb
lib/new_relic/agent/busy_calculator.rb
lib/new_relic/agent/transaction.rb
lib/new_relic/agent/transaction_event_aggregator.rb
lib/new_relic/agent/worker_loop.rb
lib/new_relic/agent/javascript_instrumentor.rb
lib/new_relic/agent/hash_extensions.rb
lib/new_relic/agent/synthetics_monitor.rb
lib/new_relic/agent/stats_engine.rb
lib/new_relic/agent/new_relic_service.rb
lib/new_relic/agent/memory_logger.rb
lib/new_relic/agent/attribute_processing.rb
lib/new_relic/agent/agent_logger.rb
lib/new_relic/agent/method_tracer_helpers.rb
lib/new_relic/agent/system_info.rb
lib/new_relic/agent/synthetics_event_aggregator.rb
lib/new_relic/agent/configuration.rb
lib/new_relic/agent/sampler_collection.rb
lib/new_relic/agent/aws_info.rb
lib/new_relic/agent/autostart.rb
lib/new_relic/agent/stats_engine/metric_stats.rb
lib/new_relic/agent/stats_engine/gc_profiler.rb
lib/new_relic/agent/stats_engine/stats_hash.rb
lib/new_relic/agent/stats_engine/samplers.rb
lib/new_relic/agent/pipe_channel_manager.rb
lib/new_relic/agent/transaction_sampler.rb
lib/new_relic/agent/supported_versions.rb
lib/new_relic/agent/inbound_request_monitor.rb
lib/new_relic/agent/threading/thread_profile.rb
lib/new_relic/agent/threading/backtrace_service.rb
lib/new_relic/agent/threading/backtrace_node.rb
lib/new_relic/agent/threading/agent_thread.rb
lib/new_relic/agent/log_once.rb
lib/new_relic/agent/database.rb
lib/new_relic/agent/internal_agent_error.rb
lib/new_relic/agent/new_relic_service/json_marshaller.rb
lib/new_relic/agent/new_relic_service/encoders.rb
lib/new_relic/agent/new_relic_service/marshaller.rb
lib/new_relic/agent/parameter_filtering.rb
lib/new_relic/agent/database/obfuscator.rb
lib/new_relic/agent/database/explain_plan_helpers.rb
lib/new_relic/agent/database/obfuscation_helpers.rb
lib/new_relic/agent/database/postgres_explain_obfuscator.rb
lib/new_relic/agent/transaction_event_recorder.rb
lib/new_relic/agent/sized_buffer.rb
lib/new_relic/agent/rules_engine/replacement_rule.rb
lib/new_relic/agent/rules_engine/segment_terms_rule.rb
lib/new_relic/agent/sql_sampler.rb
lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
lib/new_relic/agent/instrumentation/metric_frame.rb
lib/new_relic/agent/instrumentation/controller_instrumentation.rb
lib/new_relic/agent/instrumentation/sinatra.rb
lib/new_relic/agent/instrumentation/active_job.rb
lib/new_relic/agent/instrumentation/sequel_helper.rb
lib/new_relic/agent/instrumentation/queue_time.rb
lib/new_relic/agent/instrumentation/padrino.rb
lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
lib/new_relic/agent/instrumentation/data_mapper.rb
lib/new_relic/agent/instrumentation/action_controller_subscriber.rb
lib/new_relic/agent/instrumentation/rack.rb
lib/new_relic/agent/instrumentation/middleware_proxy.rb
lib/new_relic/agent/instrumentation/sinatra/ignorer.rb
lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb
lib/new_relic/agent/instrumentation/middleware_tracing.rb
lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb
lib/new_relic/agent/instrumentation/active_record_helper.rb
lib/new_relic/agent/instrumentation/memcache.rb
lib/new_relic/agent/instrumentation/active_record.rb
lib/new_relic/agent/instrumentation/rails3/action_controller.rb
lib/new_relic/agent/instrumentation/rails3/errors.rb
lib/new_relic/agent/instrumentation/grape.rb
lib/new_relic/agent/instrumentation/resque.rb
lib/new_relic/agent/instrumentation/redis.rb
lib/new_relic/agent/instrumentation/memcache/dalli.rb
lib/new_relic/agent/instrumentation/ignore_actions.rb
lib/new_relic/agent/instrumentation/active_record_subscriber.rb
lib/new_relic/agent/instrumentation/rails4/errors.rb
lib/new_relic/agent/instrumentation/active_record_5.rb
lib/new_relic/agent/instrumentation/evented_subscriber.rb
lib/new_relic/agent/instrumentation/rake.rb
lib/new_relic/agent/instrumentation/action_view_subscriber.rb
lib/new_relic/agent/transaction_timings.rb
lib/new_relic/agent/transaction_metrics.rb
lib/new_relic/agent/deprecator.rb
lib/new_relic/agent/transaction_event_primitive.rb
lib/new_relic/agent/transaction_error_primitive.rb
lib/new_relic/agent/agent.rb
lib/new_relic/agent.rb

This module contains most of the public API methods for the Ruby Agent.

For adding custom instrumentation to method invocations, see the docs for {NewRelic::Agent::MethodTracer} and {NewRelic::Agent::MethodTracer::ClassMethods}.

For information on how to trace transactions in non-Rack contexts, see {NewRelic::Agent::Instrumentation::ControllerInstrumentation}.

For general documentation about the Ruby agent, see: docs.newrelic.com/docs/agents/ruby-agent

@api public

Methods

Included Modules

::NewRelic::Agent::Instrumentation::ActiveRecord

Classes and Modules

Module NewRelic::Agent::AttributeProcessing
Module NewRelic::Agent::Autostart
Module NewRelic::Agent::BusyCalculator
Module NewRelic::Agent::Commands
Module NewRelic::Agent::Configuration
Module NewRelic::Agent::CrossAppTracing
Module NewRelic::Agent::DataMapperTracing
Module NewRelic::Agent::Database
Module NewRelic::Agent::Datastores
Module NewRelic::Agent::Deprecator
Module NewRelic::Agent::EncodingNormalizer
Module NewRelic::Agent::HTTPClients
Module NewRelic::Agent::HashExtensions
Module NewRelic::Agent::Hostname
Module NewRelic::Agent::Instrumentation
Module NewRelic::Agent::LogOnce
Module NewRelic::Agent::MethodTracer
Module NewRelic::Agent::MethodTracerHelpers
Module NewRelic::Agent::ParameterFiltering
Module NewRelic::Agent::PayloadMetricMapping
Module NewRelic::Agent::PipeChannelManager
Module NewRelic::Agent::Samplers
Module NewRelic::Agent::SystemInfo
Module NewRelic::Agent::Threading
Module NewRelic::Agent::TransactionErrorPrimitive
Module NewRelic::Agent::TransactionEventPrimitive
Module NewRelic::Agent::VM
Class NewRelic::Agent::AWSInfo
Class NewRelic::Agent::Agent
Class NewRelic::Agent::AgentLogger
Class NewRelic::Agent::AttributeFilter
Class NewRelic::Agent::AttributeFilterRule
Class NewRelic::Agent::AuditLogger
Class NewRelic::Agent::BackgroundLoadingError
Class NewRelic::Agent::ChainedStats
Class NewRelic::Agent::CrossAppMonitor
Class NewRelic::Agent::CustomEventAggregator
Class NewRelic::Agent::ErrorCollector
Class NewRelic::Agent::ErrorEventAggregator
Class NewRelic::Agent::ErrorTraceAggregator
Class NewRelic::Agent::EventAggregator
Class NewRelic::Agent::EventBuffer
Class NewRelic::Agent::EventListener
Class NewRelic::Agent::EventLoop
Class NewRelic::Agent::ForceDisconnectException
Class NewRelic::Agent::ForceRestartException
Class NewRelic::Agent::Harvester
Class NewRelic::Agent::InboundRequestMonitor
Class NewRelic::Agent::InternalAgentError
Class NewRelic::Agent::JavascriptInstrumentor
Class NewRelic::Agent::LicenseException
Class NewRelic::Agent::MemoryLogger
Class NewRelic::Agent::NewRelicService
Class NewRelic::Agent::NullLogger
Class NewRelic::Agent::Obfuscator
Class NewRelic::Agent::PipeService
Class NewRelic::Agent::RulesEngine
Class NewRelic::Agent::SampledBuffer
Class NewRelic::Agent::Sampler
Class NewRelic::Agent::SamplerCollection
Class NewRelic::Agent::SerializationError
Class NewRelic::Agent::ServerConnectionException
Class NewRelic::Agent::SizedBuffer
Class NewRelic::Agent::SlowSql
Class NewRelic::Agent::SqlSampler
Class NewRelic::Agent::SqlTrace
Class NewRelic::Agent::Stats
Class NewRelic::Agent::StatsEngine
Class NewRelic::Agent::StatsHash
Class NewRelic::Agent::SyntheticsEventAggregator
Class NewRelic::Agent::SyntheticsEventBuffer
Class NewRelic::Agent::SyntheticsMonitor
Class NewRelic::Agent::TracedMethodFrame
Class NewRelic::Agent::TracedMethodStack
Class NewRelic::Agent::Transaction
Class NewRelic::Agent::TransactionEventAggregator
Class NewRelic::Agent::TransactionEventRecorder
Class NewRelic::Agent::TransactionMetrics
Class NewRelic::Agent::TransactionSampleBuilder
Class NewRelic::Agent::TransactionSampler
Class NewRelic::Agent::TransactionSqlData
Class NewRelic::Agent::TransactionState
Class NewRelic::Agent::TransactionTimings
Class NewRelic::Agent::UnrecoverableAgentException
Class NewRelic::Agent::UnrecoverableServerException
Class NewRelic::Agent::UtilizationData
Class NewRelic::Agent::WorkerLoop

Constants

LOG_LEVELS = { "debug" => ::Logger::DEBUG, "info" => ::Logger::INFO, "warn" => ::Logger::WARN, "error" => ::Logger::ERROR, "fatal" => ::Logger::FATAL, }
SUPPORTED_VERSIONS = { # Rubies :mri => { :type => :ruby, :name => "MRI", :supported => ["1.8.7", "1.9.2", "1.9.3", "2.0.0", "~> 2.1.0", "~> 2.2.0", "~> 2.3.0"], :experimental=> ["2.4.0-preview3"], :url => "https://www.ruby-lang.org", :feed => "https://www.ruby-lang.org/en/feeds/news.rss", :notes => [ "1.8.7 includes support for Ruby Enterprise Edition (REE).", "1.8.7 & REE require the 'json' gem to be present in your Gemfile/operating environment.", "Last supported agent on 1.8.6 was 3.6.8.168."]
UNKNOWN_METRIC = '(unknown)'.freeze   placeholder name used when we cannot determine a transaction‘s name
ADD_CUSTOM_ATTRIBUTES = "NewRelic::Agent.add_custom_attributes".freeze
ADD_CUSTOM_PARAMETERS = "NewRelic::Agent.add_custom_parameters".freeze
ADD_REQUEST_PARAMETERS = "NewRelic::Agent.add_request_parameters".freeze
SET_USER_ATTRIBUTES = "NewRelic::Agent.set_user_attributes".freeze

External Aliases

agent -> instance

Attributes

config  [R] 

Public Class methods

Public Instance methods

Cancel the collection of the current transaction in progress, if any. Only affects the transaction started on this thread once it has started and before it has completed.

This method has been deprecated in favor of ignore_transaction, which does what people expect this method to do.

@api public @deprecated

Add attributes to the transaction trace, Insights Transaction event, and any traced errors recorded for the current transaction.

If Browser Monitoring is enabled, and the browser_monitoring.attributes.enabled configuration setting is true, these custom attributes will also be present in the script injected into the response body, making them available on Insights PageView events.

@api public

Deprecated. Use add_custom_attributes instead.

@deprecated @api public

Add instrumentation files to the agent. The argument should be a glob matching ruby scripts which will be executed at the time instrumentation is loaded. Since instrumentation is not loaded when the agent is not running it‘s better to use this method to register instrumentation than just loading the files directly, although that probably also works.

@api public

Deprecated. Use add_custom_attributes instead.

@deprecated @api public

Register this method as a callback for processes that fork jobs.

If the master/parent connects to the agent prior to forking the agent in the forked process will use that agent_run. Otherwise the forked process will establish a new connection with the server.

Use this especially when you fork the process to run background jobs or other work. If you are doing this with a web dispatcher that forks worker processes then you will need to force the agent to reconnect, which it won‘t do by default. Passenger and Rainbows and Unicorn are already handled, nothing special needed for them.

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.

@api public

In previous agent releases, this method was required for manual RUM instrumentation. That work is now all done by the browser_timing_header method, but this is left for compatibility.

@api public @deprecated

This method returns a string suitable for inclusion in a page - known as ‘manual instrumentation’ for Real User Monitoring. Can return either a script tag with associated javascript, or in the case of disabled Real User Monitoring, an empty string

This is the header string - it should be placed as high in the page as is reasonably possible - that is, before any style or javascript inclusions, but after any header-related meta tags

In previous agents there was a corresponding footer required, but all the work is now done by this single method.

@api public

Yield to the block without collecting any metrics or traces in any of the subsequent calls. If executed recursively, will keep track of the first entry point and turn on tracing again after leaving that block. This uses the thread local TransactionState.

@api public

This method sets the state of sql recording in the transaction sampler feature. Within the given block, no sql will be recorded

usage:

  NewRelic::Agent.disable_sql_recording do
    ...
  end

@api public

This method disables the recording of transaction traces in the given block. See also disable_all_tracing

@api public

Clear out any data the agent has buffered but has not yet transmitted to the collector.

@api public

Get or create a statistics gatherer that will aggregate numerical data under a metric name.

metric_name should follow a slash separated path convention. Application specific metrics should begin with "Custom/".

Return a NewRelic::Agent::Stats that accepts data via calls to add_data_point(value).

This method is deprecated in favor of record_metric and increment_metric, and is not thread-safe.

@api public @deprecated

get_stats_no_scope(metric_name, use_scope=false)

Alias for get_stats

Get the name of the current running transaction. This is useful if you want to modify the default name.

@api public

This method disables the recording of Apdex metrics in the current transaction.

@api public

This method disables browser monitoring javascript injection in the current transaction.

@api public

Set a filter to be applied to errors that the Ruby Agent will track. The block should evalute to the exception to track (which could be different from the original exception) or nil to ignore this exception.

The block is yielded to with the exception to filter.

Return the new block or the existing filter Proc if no block is passed.

@api public

This method disables the recording of the current transaction. No metrics, traced errors, transaction traces, Insights events, slow SQL traces, or RUM injection will happen for this transaction.

@api public

Increment a simple counter metric.

metric_name should follow a slash separated path convention. Application specific metrics should begin with "Custom/".

This method is safe to use from any thread.

@api public

Primary interface to logging is fronted by this accessor Access via ::NewRelic::Agent.logger

Call this to manually start the Agent in situations where the Agent does not auto-start.

When the app environment loads, so does the Agent. However, the Agent will only connect to the service if a web front-end is found. If you want to selectively monitor ruby processes that don‘t use web plugins, then call this method in your code and the Agent will fire up and start reporting to the service.

Options are passed in as overrides for values in the newrelic.yml, such as app_name. In addition, the option log will take a logger that will be used instead of the standard file logger. The setting for the newrelic.yml section to use (ie, RAILS_ENV) can be overridden with an :env argument.

@api public

Send an error to New Relic.

@param [Exception] exception Error you wish to send @param [Hash] options Modify how New Relic processes the error @option options [Hash] :custom_params Custom parameters to attach to the trace @option options [Boolean] :trace_only Only record the error trace

                          (do not affect error rate or Apdex status)

@option options [String] :uri Request path, minus request params or query string

                          (usually not needed)

@option options [String] :metric Metric name associated with the transaction

                          (usually not needed)

Any option keys other than the ones listed here are treated as :custom_params.

*Note:* Previous versions of the agent allowed passing :request_params, but those are now ignored. If you need to record the request parameters, call this method inside a transaction or pass the information in :custom_params.

Most of the time, you do not need to specify the :uri or :metric options; only pass them if you are calling notice_error outside a transaction.

@api public

Fire an event of the specified event_type, passing it an the given args to any registered handlers.

Record a custom event to be sent to New Relic Insights. The recorded event will be buffered in memory until the next time the agent sends data to New Relic‘s servers.

If you want to be able to tie the information recorded via this call back to the web request or background job that it happened in, you may want to instead use the add_custom_attributes API call to attach attributes to the Transaction event that will automatically be generated for the request.

A timestamp will be automatically added to the recorded event when this method is called.

@param [Symbol or String] event_type The name of the event type to record. Event

                          types must consist of only alphanumeric
                          characters, '_', ':', or ' '.

@param [Hash] event_attrs A Hash of attributes to be attached to the event.

                          Keys should be strings or symbols, and values
                          may be strings, symbols, numeric values or
                          booleans.

@api public

Record a value for the given metric name.

This method should be used to record event-based metrics such as method calls that are associated with a specific duration or magnitude.

metric_name should follow a slash separated path convention. Application specific metrics should begin with "Custom/".

value should be either a single Numeric value representing the duration/ magnitude of the event being recorded, or a Hash containing :count, :total, :min, :max, and :sum_of_squares keys. The latter form is useful for recording pre-aggregated metrics collected externally.

This method is safe to use from any thread.

@api public

Remove after 5/9/15

Require agent testing helper methods

@api public

For testing Important that we don‘t change the instance or we orphan callbacks

Deprecated in favor of drop_buffered_data

@api public @deprecated

This method sets the block sent to this method as a sql obfuscator. The block will be called with a single String SQL statement to obfuscate. The method must return the obfuscated String SQL. If chaining of obfuscators is required, use type = :before or :after

type = :before, :replace, :after

Example:

   NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
      my_obfuscator(sql)
   end

@api public

Set the name of the current running transaction. The agent will apply a reasonable default based on framework routing, but in cases where this is insufficient, this can be used to manually control the name of the transaction. The category of transaction can be specified via the +:category+ option:

  • :category => :controller indicates that this is a controller action and will appear with all the other actions.
  • :category => :task indicates that this is a background task and will show up in New Relic with other background tasks instead of in the controllers list
  • :category => :middleware if you are instrumenting a rack middleware call. The :name is optional, useful if you have more than one potential transaction in the call.
  • :category => :uri indicates that this is a web transaction whose name is a normalized URI, where ‘normalized’ means the URI does not have any elements with data in them such as in many REST URIs.

The default category is the same as the running transaction.

@api public

Deprecated. Use add_custom_attributes instead.

@deprecated @api public

Shutdown the agent. Call this before exiting. Sends any queued data and kills the background thread.

@param options [Hash] Unused options Hash, for back compatibility only

@api public

Subscribe to events of event_type, calling the given handler when one is sent.

Check to see if we are capturing metrics currently on this thread.

helper method to check the thread local to determine whether sql is being recorded or not

helper method to check the thread local to determine whether the transaction in progress is traced or not

Yield to a block that is run with a database metric name context. This means the Database instrumentation will use this for the metric name if it does not otherwise know about a model. This is re-entrant.

@param [String,Class,to_s] model the DB model class

@param [String] method the name of the finder method or other method to identify the operation with.

[Validate]