lib/new_relic/agent/agent.rb in newrelic_rpm-2.14.1 vs lib/new_relic/agent/agent.rb in newrelic_rpm-3.0.0.beta1
- old
+ new
@@ -60,10 +60,11 @@
attr_reader :error_collector
attr_reader :record_sql
attr_reader :histogram
attr_reader :metric_ids
attr_reader :url_rules
+ attr_reader :beacon_configuration
def record_transaction(duration_seconds, options={})
is_error = options['is_error'] || options['error_message'] || options['exception']
metric = options['metric']
metric ||= options['uri'] # normalize this with url rules
@@ -196,11 +197,16 @@
prev.nil? || prev
end
# Push flag indicating whether we should be tracing in this
# thread.
def push_trace_execution_flag(should_trace=false)
- (Thread.current[:newrelic_untraced] ||= []) << should_trace
+ value = Thread.current[:newrelic_untraced]
+ if (value.nil?)
+ Thread.current[:newrelic_untraced] = []
+ end
+
+ Thread.current[:newrelic_untraced] << should_trace
end
# Pop the current trace execution status. Restore trace execution status
# to what it was before we pushed the current flag.
def pop_trace_execution_flag
@@ -220,11 +226,11 @@
end
def log
NewRelic::Agent.logger
end
-
+
# Herein lies the corpse of the former 'start' method. May
# it's unmatched flog score rest in pieces.
module Start
def already_started?
if started?
@@ -234,27 +240,27 @@
end
def disabled?
!control.agent_enabled?
end
-
+
def log_dispatcher
dispatcher_name = control.dispatcher.to_s
return if log_if(dispatcher_name.empty?, :info, "No dispatcher detected.")
log.info "Dispatcher: #{dispatcher_name}"
end
-
+
def log_app_names
log.info "Application: #{control.app_names.join(", ")}"
end
def apdex_f
(4 * NewRelic::Control.instance.apdex_t).to_f
end
def apdex_f_threshold?
- sampler_config.fetch('transaction_threshold', '') =~ /apdex_f/i
+ sampler_config.fetch('transaction_threshold', '') =~ /apdex_f/i
end
def set_sql_recording!
record_sql_config = sampler_config.fetch('record_sql', :obfuscated)
case record_sql_config.to_s
@@ -267,32 +273,32 @@
when 'raw'
@record_sql = :raw
else
@record_sql = :obfuscated
end
-
+
log_sql_transmission_warning?
end
def log_sql_transmission_warning?
log_if((@record_sql == :raw), :warn, "Agent is configured to send raw SQL to RPM service")
end
def sampler_config
control.fetch('transaction_tracer', {})
end
-
+
# this entire method should be done on the transaction
# sampler object, rather than here. We should pass in the
# sampler config.
def config_transaction_tracer
@should_send_samples = @config_should_send_samples = sampler_config.fetch('enabled', true)
@should_send_random_samples = sampler_config.fetch('random_sample', false)
@explain_threshold = sampler_config.fetch('explain_threshold', 0.5).to_f
@explain_enabled = sampler_config.fetch('explain_enabled', true)
set_sql_recording!
-
+
# default to 2.0, string 'apdex_f' will turn into your
# apdex * 4
@slowest_transaction_threshold = sampler_config.fetch('transaction_threshold', 2.0).to_f
@slowest_transaction_threshold = apdex_f if apdex_f_threshold?
end
@@ -300,27 +306,27 @@
def connect_in_foreground
NewRelic::Agent.disable_all_tracing { connect(:keep_retrying => false) }
end
def using_rubinius?
- RUBY_VERSION =~ /rubinius/i
+ RUBY_VERSION =~ /rubinius/i
end
-
+
def using_jruby?
- defined?(JRuby)
+ defined?(JRuby)
end
-
+
def using_sinatra?
defined?(Sinatra::Application)
end
-
+
# we should not set an at_exit block if people are using
# these as they don't do standard at_exit behavior per MRI/YARV
def weird_ruby?
using_rubinius? || using_jruby? || using_sinatra?
end
-
+
def install_exit_handler
if control.send_data_on_exit && !weird_ruby?
# Our shutdown handler needs to run after other shutdown handlers
at_exit { at_exit { shutdown } }
end
@@ -332,21 +338,21 @@
end
def log_version_and_pid
log.info "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}"
end
-
+
def log_if(boolean, level, message)
self.log.send(level, message) if boolean
boolean
end
def log_unless(boolean, level, message)
self.log.send(level, message) unless boolean
boolean
end
-
+
def monitoring?
log_unless(control.monitor_mode?, :warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
end
def has_license_key?
@@ -354,20 +360,20 @@
end
def has_correct_license_key?
has_license_key? && correct_license_length
end
-
+
def correct_license_length
key = control.license_key
log_unless((key.length == 40), :error, "Invalid license key: #{key}")
end
def using_forking_dispatcher?
log_if([:passenger, :unicorn].include?(control.dispatcher), :info, "Connecting workers after forking.")
end
-
+
def check_config_and_start_agent
return unless monitoring? && has_correct_license_key?
return if using_forking_dispatcher?
connect_in_foreground if control.sync_startup
start_worker_thread
@@ -471,11 +477,11 @@
rescue NewRelic::Agent::ServerConnectionException => e
handle_server_connection_problem(e)
rescue Exception => e
handle_other_error(e)
end
-
+
def deferred_work!(connection_options)
catch_errors do
NewRelic::Agent.disable_all_tracing do
# We try to connect. If this returns false that means
# the server rejected us for a licensing reason and we should
@@ -492,11 +498,11 @@
end
end
end
end
include StartWorkerThread
-
+
# Try to launch the worker thread and connect to the server.
#
# See #connect for a description of connection_options.
def start_worker_thread(connection_options = {})
log.debug "Creating RPM worker thread."
@@ -507,11 +513,11 @@
end
def control
NewRelic::Control.instance
end
-
+
module Connect
attr_accessor :connect_retry_period
attr_accessor :connect_attempts
def disconnect
@@ -556,11 +562,11 @@
def handle_license_error(error)
log.error error.message
log.info "Visit NewRelic.com to obtain a valid license key, or to upgrade your account."
disconnect
end
-
+
def log_seed_token
if control.validate_seed
log.debug "Connecting with validation seed/token: #{control.validate_seed}/#{control.validate_token}"
end
end
@@ -600,18 +606,19 @@
else
error_collector.enabled = false
end
log.debug "Errors will #{enabled ? '' : 'not '}be sent to the RPM service."
end
-
+
def enable_random_samples!(sample_rate)
+ sample_rate = 10 unless sample_rate.to_i > 0# a sane default for random sampling
@transaction_sampler.random_sampling = true
@transaction_sampler.sampling_rate = sample_rate
log.info "Transaction sampling enabled, rate = #{@transaction_sampler.sampling_rate}"
end
-
+
def configure_transaction_tracer!(server_enabled, sample_rate)
# Ask the server for permission to send transaction samples.
# determined by subscription license.
@should_send_samples = @config_should_send_samples && server_enabled
@@ -631,17 +638,18 @@
end
end
def query_server_for_configuration
set_collector_host!
-
+
finish_setup(connect_to_server)
end
def finish_setup(config_data)
@agent_id = config_data['agent_run_id']
@report_period = config_data['data_report_period']
@url_rules = config_data['url_rules']
+ @beacon_configuration = BeaconConfiguration.new(config_data)
log_connection!(config_data)
configure_transaction_tracer!(config_data['collect_traces'], config_data['sample_rate'])
configure_error_collector!(config_data['collect_errors'])
end
@@ -936,8 +944,9 @@
end
end
extend ClassMethods
include InstanceMethods
+ include BrowserMonitoring
end
end
end