wd_newrelic_rpm 3.3.4.1 → 3.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +317 -39
- data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
- data/Gemfile +16 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +71 -55
- data/Rakefile +62 -0
- data/bin/mongrel_rpm +1 -1
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/init.rb +31 -0
- data/lib/new_relic/agent.rb +31 -60
- data/lib/new_relic/agent/agent.rb +277 -502
- data/lib/new_relic/agent/agent_logger.rb +165 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +36 -50
- data/lib/new_relic/agent/browser_monitoring.rb +114 -61
- data/lib/new_relic/agent/busy_calculator.rb +14 -6
- data/lib/new_relic/agent/configuration.rb +74 -0
- data/lib/new_relic/agent/configuration/defaults.rb +126 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
- data/lib/new_relic/agent/configuration/manager.rb +136 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
- data/lib/new_relic/agent/configuration/server_source.rb +27 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
- data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
- data/lib/new_relic/agent/database.rb +39 -26
- data/lib/new_relic/agent/error_collector.rb +48 -49
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
- data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +11 -9
- data/lib/new_relic/agent/new_relic_service.rb +379 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
- data/lib/new_relic/agent/pipe_service.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
- data/lib/new_relic/agent/sql_sampler.rb +31 -74
- data/lib/new_relic/agent/stats_engine.rb +0 -5
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
- data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
- data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
- data/lib/new_relic/agent/thread.rb +32 -0
- data/lib/new_relic/agent/thread_profiler.rb +306 -0
- data/lib/new_relic/agent/transaction_info.rb +24 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
- data/lib/new_relic/agent/transaction_sampler.rb +49 -65
- data/lib/new_relic/agent/worker_loop.rb +31 -25
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +19 -10
- data/lib/new_relic/control.rb +1 -3
- data/lib/new_relic/control/class_methods.rb +10 -5
- data/lib/new_relic/control/frameworks/merb.rb +0 -6
- data/lib/new_relic/control/frameworks/rails.rb +30 -45
- data/lib/new_relic/control/frameworks/rails3.rb +23 -18
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +2 -23
- data/lib/new_relic/control/instance_methods.rb +35 -73
- data/lib/new_relic/control/instrumentation.rb +7 -12
- data/lib/new_relic/control/server_methods.rb +17 -19
- data/lib/new_relic/delayed_job_injection.rb +2 -2
- data/lib/new_relic/helper.rb +34 -0
- data/lib/new_relic/language_support.rb +56 -37
- data/lib/new_relic/local_environment.rb +32 -67
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/metric_spec.rb +7 -3
- data/lib/new_relic/noticed_error.rb +32 -9
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/browser_monitoring.rb +34 -25
- data/lib/new_relic/rack/developer_mode.rb +3 -0
- data/lib/new_relic/rack/error_collector.rb +56 -0
- data/lib/new_relic/stats.rb +9 -7
- data/lib/new_relic/transaction_sample.rb +19 -18
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +19 -3
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/tasks/tests.rake +6 -8
- data/newrelic.yml +15 -32
- data/newrelic_rpm.gemspec +224 -43
- data/newrelic_rpm.gemspec.erb +54 -0
- data/test/config/newrelic.yml +4 -3
- data/test/config/test_control.rb +18 -18
- data/test/fixtures/gemspec_no_build.rb +442 -0
- data/test/fixtures/gemspec_with_build.rb +442 -0
- data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +85 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +162 -0
- data/test/multiverse/script/run_one +3 -0
- data/test/multiverse/script/runner +9 -0
- data/test/multiverse/suites/active_record/Envfile +13 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
- data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
- data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
- data/test/multiverse/suites/agent_only/Envfile +4 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
- data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
- data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/logging/Envfile +4 -0
- data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
- data/test/multiverse/suites/logging/logging_test.rb +143 -0
- data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
- data/test/multiverse/suites/no_load/Envfile +2 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
- data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
- data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
- data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
- data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
- data/test/multiverse/suites/rails_3_views/Envfile +16 -0
- data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
- data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
- data/test/multiverse/suites/resque/Envfile +21 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
- data/test/multiverse/suites/sinatra/Envfile +13 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
- data/test/multiverse/test/multiverse_test.rb +55 -0
- data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
- data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
- data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
- data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
- data/test/new_relic/agent/agent/connect_test.rb +151 -227
- data/test/new_relic/agent/agent/start_test.rb +68 -118
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +116 -30
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
- data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
- data/test/new_relic/agent/busy_calculator_test.rb +7 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
- data/test/new_relic/agent/configuration/manager_test.rb +204 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
- data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
- data/test/new_relic/agent/database_test.rb +12 -11
- data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
- data/test/new_relic/agent/error_collector_test.rb +33 -19
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
- data/test/new_relic/agent/method_tracer_test.rb +7 -6
- data/test/new_relic/agent/mock_scope_listener.rb +3 -0
- data/test/new_relic/agent/new_relic_service_test.rb +376 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +27 -50
- data/test/new_relic/agent/sql_sampler_test.rb +81 -56
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
- data/test/new_relic/agent/stats_engine_test.rb +17 -8
- data/test/new_relic/agent/thread_profiler_test.rb +537 -0
- data/test/new_relic/agent/thread_test.rb +89 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_info_test.rb +45 -4
- data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
- data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
- data/test/new_relic/agent/worker_loop_test.rb +26 -11
- data/test/new_relic/agent_test.rb +113 -33
- data/test/new_relic/collection_helper_test.rb +7 -8
- data/test/new_relic/command/deployments_test.rb +18 -2
- data/test/new_relic/control/class_methods_test.rb +0 -18
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control_test.rb +96 -137
- data/test/new_relic/delayed_job_injection_test.rb +6 -1
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +283 -0
- data/test/new_relic/fake_service.rb +53 -0
- data/test/new_relic/fakes_sending_data.rb +30 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +11 -11
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +24 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
- data/test/new_relic/rack/developer_mode_test.rb +13 -7
- data/test/new_relic/rack/error_collector_test.rb +74 -0
- data/test/new_relic/stats_test.rb +10 -0
- data/test/new_relic/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +47 -2
- data/test/new_relic/version_number_test.rb +32 -0
- data/test/script/build_test_gem.sh +9 -3
- data/test/script/ci.sh +108 -35
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +68 -18
- data/ui/helpers/developer_mode_helper.rb +21 -11
- data/ui/views/layouts/newrelic_default.rhtml +1 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/show_sample.rhtml +1 -1
- data/ui/views/newrelic/threads.rhtml +2 -10
- data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
- metadata +191 -65
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/control/configuration.rb +0 -206
- data/lib/new_relic/control/logging_methods.rb +0 -143
- data/lib/new_relic/data_serialization.rb +0 -151
- data/test/new_relic/control/configuration_test.rb +0 -84
- data/test/new_relic/control/logging_methods_test.rb +0 -185
- data/test/new_relic/data_serialization_test.rb +0 -208
@@ -19,8 +19,7 @@ module NewRelic
|
|
19
19
|
|
20
20
|
BUILDER_KEY = :transaction_sample_builder
|
21
21
|
|
22
|
-
attr_accessor :
|
23
|
-
attr_accessor :explain_threshold, :explain_enabled, :transaction_threshold
|
22
|
+
attr_accessor :random_sampling, :sampling_rate
|
24
23
|
attr_accessor :slow_capture_threshold
|
25
24
|
attr_reader :samples, :last_sample, :disabled
|
26
25
|
|
@@ -36,38 +35,27 @@ module NewRelic
|
|
36
35
|
# sampling - we pull 1 @random_sample in every @sampling_rate harvests
|
37
36
|
@harvest_count = 0
|
38
37
|
@random_sample = nil
|
39
|
-
@sampling_rate =
|
40
|
-
@slow_capture_threshold = 2.0
|
41
|
-
configure!
|
38
|
+
@sampling_rate = Agent.config[:sample_rate]
|
42
39
|
|
43
40
|
# This lock is used to synchronize access to the @last_sample
|
44
41
|
# and related variables. It can become necessary on JRuby or
|
45
42
|
# any 'honest-to-god'-multithreaded system
|
46
43
|
@samples_lock = Mutex.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def configure!
|
50
|
-
# @segment_limit and @stack_trace_threshold come from the
|
51
|
-
# configuration file, with built-in defaults that should
|
52
|
-
# suffice for most customers
|
53
|
-
|
54
|
-
# enable if config.fetch('enabled', true)
|
55
44
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@store_sampler_methods = [ :store_random_sample, :store_slowest_sample ]
|
64
|
-
if NewRelic::Control.instance.developer_mode?
|
65
|
-
@store_sampler_methods << :store_sample_for_developer_mode
|
45
|
+
Agent.config.register_callback(:'transaction_tracer.enabled') do |enabled|
|
46
|
+
if enabled
|
47
|
+
threshold = Agent.config[:'transaction_tracer.transaction_threshold']
|
48
|
+
::NewRelic::Agent.logger.debug "Transaction tracing threshold is #{threshold} seconds."
|
49
|
+
else
|
50
|
+
::NewRelic::Agent.logger.debug "Transaction traces will not be sent to the New Relic service."
|
51
|
+
end
|
66
52
|
end
|
67
|
-
end
|
68
53
|
|
69
|
-
|
70
|
-
|
54
|
+
Agent.config.register_callback(:'transaction_tracer.record_sql') do |config|
|
55
|
+
if config == 'raw'
|
56
|
+
::NewRelic::Agent.logger.warn("Agent is configured to send raw SQL to the service")
|
57
|
+
end
|
58
|
+
end
|
71
59
|
end
|
72
60
|
|
73
61
|
# Returns the current sample id, delegated from `builder`
|
@@ -76,22 +64,8 @@ module NewRelic
|
|
76
64
|
b and b.sample_id
|
77
65
|
end
|
78
66
|
|
79
|
-
# Enable the transaction sampler - this also registers it with
|
80
|
-
# the statistics engine.
|
81
|
-
def enable
|
82
|
-
@disabled = false
|
83
|
-
NewRelic::Agent.instance.stats_engine.transaction_sampler = self
|
84
|
-
end
|
85
|
-
|
86
|
-
# Disable the transaction sampler - this also deregisters it
|
87
|
-
# with the statistics engine.
|
88
|
-
def disable
|
89
|
-
@disabled = true
|
90
|
-
NewRelic::Agent.instance.stats_engine.remove_transaction_sampler(self)
|
91
|
-
end
|
92
|
-
|
93
67
|
def enabled?
|
94
|
-
|
68
|
+
Agent.config[:'transaction_tracer.enabled'] || Agent.config[:developer_mode]
|
95
69
|
end
|
96
70
|
|
97
71
|
# Set with an integer value n, this takes one in every n
|
@@ -107,7 +81,7 @@ module NewRelic
|
|
107
81
|
# transaction sampler is disabled. Takes a time parameter for
|
108
82
|
# the start of the transaction sample
|
109
83
|
def notice_first_scope_push(time)
|
110
|
-
start_builder(time.to_f)
|
84
|
+
start_builder(time.to_f) if enabled?
|
111
85
|
end
|
112
86
|
|
113
87
|
# This delegates to the builder to create a new open transaction
|
@@ -121,14 +95,14 @@ module NewRelic
|
|
121
95
|
|
122
96
|
builder.trace_entry(scope, time.to_f)
|
123
97
|
|
124
|
-
capture_segment_trace if
|
98
|
+
capture_segment_trace if Agent.config[:developer_mode]
|
125
99
|
end
|
126
100
|
|
127
101
|
# in developer mode, capture the stack trace with the segment.
|
128
102
|
# this is cpu and memory expensive and therefore should not be
|
129
103
|
# turned on in production mode
|
130
104
|
def capture_segment_trace
|
131
|
-
return unless
|
105
|
+
return unless Agent.config[:developer_mode]
|
132
106
|
segment = builder.current_segment
|
133
107
|
if segment
|
134
108
|
# Strip stack frames off the top that match /new_relic/agent/
|
@@ -166,7 +140,6 @@ module NewRelic
|
|
166
140
|
# It sets various instance variables to the finished sample,
|
167
141
|
# depending on which settings are active. See `store_sample`
|
168
142
|
def notice_scope_empty(time=Time.now)
|
169
|
-
|
170
143
|
last_builder = builder
|
171
144
|
return unless last_builder
|
172
145
|
|
@@ -187,20 +160,26 @@ module NewRelic
|
|
187
160
|
# @samples array, and the @slowest_sample variable if it is
|
188
161
|
# slower than the current occupant of that slot
|
189
162
|
def store_sample(sample)
|
190
|
-
|
163
|
+
sampler_methods = [ :store_slowest_sample ]
|
164
|
+
if Agent.config[:developer_mode]
|
165
|
+
sampler_methods << :store_sample_for_developer_mode
|
166
|
+
end
|
167
|
+
if Agent.config[:'transaction_tracer.random_sample']
|
168
|
+
sampler_methods << :store_random_sample
|
169
|
+
end
|
170
|
+
|
171
|
+
sampler_methods.each{|sym| send(sym, sample) }
|
172
|
+
|
191
173
|
if NewRelic::Agent::TransactionInfo.get.force_persist_sample?(sample)
|
192
174
|
store_force_persist(sample)
|
193
175
|
end
|
194
|
-
|
195
176
|
end
|
196
177
|
|
197
178
|
# Only active when random sampling is true - this is very rarely
|
198
179
|
# used. Always store the most recent sample so that random
|
199
180
|
# sampling can pick a few of the samples to store, upon harvest
|
200
181
|
def store_random_sample(sample)
|
201
|
-
if
|
202
|
-
@random_sample = sample
|
203
|
-
end
|
182
|
+
@random_sample = sample if Agent.config[:'transaction_tracer.random_sample']
|
204
183
|
end
|
205
184
|
|
206
185
|
def store_force_persist(sample)
|
@@ -216,7 +195,7 @@ module NewRelic
|
|
216
195
|
# Samples take up a ton of memory, so we only store a lot of
|
217
196
|
# them in developer mode - we truncate to @max_samples
|
218
197
|
def store_sample_for_developer_mode(sample)
|
219
|
-
return unless
|
198
|
+
return unless Agent.config[:developer_mode]
|
220
199
|
@samples = [] unless @samples
|
221
200
|
@samples << sample
|
222
201
|
truncate_samples
|
@@ -230,7 +209,7 @@ module NewRelic
|
|
230
209
|
end
|
231
210
|
end
|
232
211
|
|
233
|
-
# Checks to see if the old sample exists, or if
|
212
|
+
# Checks to see if the old sample exists, or if its duration is
|
234
213
|
# less than the new sample
|
235
214
|
def slowest_sample?(old_sample, new_sample)
|
236
215
|
old_sample.nil? || (new_sample.duration > old_sample.duration)
|
@@ -247,7 +226,7 @@ module NewRelic
|
|
247
226
|
# Delegates to the builder to store the path, uri, and
|
248
227
|
# parameters if the sampler is active
|
249
228
|
def notice_transaction(path, uri=nil, params={})
|
250
|
-
builder.set_transaction_info(path, uri, params) if
|
229
|
+
builder.set_transaction_info(path, uri, params) if enabled? && builder
|
251
230
|
end
|
252
231
|
|
253
232
|
# Tells the builder to ignore a transaction, if we are currently
|
@@ -316,7 +295,10 @@ module NewRelic
|
|
316
295
|
# Appends a backtrace to a segment if that segment took longer
|
317
296
|
# than the specified duration
|
318
297
|
def append_backtrace(segment, duration)
|
319
|
-
|
298
|
+
if (duration >= Agent.config[:'transaction_tracer.stack_trace_threshold'] ||
|
299
|
+
Thread.current[:capture_deep_tt])
|
300
|
+
segment[:backtrace] = caller.join("\n")
|
301
|
+
end
|
320
302
|
end
|
321
303
|
|
322
304
|
# some statements (particularly INSERTS with large BLOBS
|
@@ -344,9 +326,10 @@ module NewRelic
|
|
344
326
|
#
|
345
327
|
# random sampling is very, very seldom used
|
346
328
|
def add_random_sample_to(result)
|
347
|
-
return unless @
|
329
|
+
return unless @random_sample &&
|
330
|
+
Agent.config[:sample_rate] && Agent.config[:sample_rate].to_i > 0
|
348
331
|
@harvest_count += 1
|
349
|
-
if (@harvest_count.to_i %
|
332
|
+
if (@harvest_count.to_i % Agent.config[:sample_rate].to_i) == 0
|
350
333
|
result << @random_sample if @random_sample
|
351
334
|
@harvest_count = 0
|
352
335
|
end
|
@@ -362,8 +345,7 @@ module NewRelic
|
|
362
345
|
# elements - one element unless random sampling is enabled. The
|
363
346
|
# sample returned will be the slowest sample among those
|
364
347
|
# available during this harvest
|
365
|
-
def add_samples_to(result
|
366
|
-
|
348
|
+
def add_samples_to(result)
|
367
349
|
# pull out force persist
|
368
350
|
force_persist = result.select {|sample| sample.force_persist} || []
|
369
351
|
result.reject! {|sample| sample.force_persist}
|
@@ -372,7 +354,9 @@ module NewRelic
|
|
372
354
|
|
373
355
|
|
374
356
|
# Now get the slowest sample
|
375
|
-
if @slowest_sample &&
|
357
|
+
if @slowest_sample &&
|
358
|
+
@slowest_sample.duration >=
|
359
|
+
Agent.config[:'transaction_tracer.transaction_threshold']
|
376
360
|
result << @slowest_sample
|
377
361
|
end
|
378
362
|
|
@@ -388,14 +372,14 @@ module NewRelic
|
|
388
372
|
|
389
373
|
# get the set of collected samples, merging into previous samples,
|
390
374
|
# and clear the collected sample list. Truncates samples to a
|
391
|
-
# specified
|
375
|
+
# specified segment_limit to save memory and bandwith
|
392
376
|
# transmitting samples to the server.
|
393
|
-
def harvest(previous
|
394
|
-
return [] if
|
377
|
+
def harvest(previous=[])
|
378
|
+
return [] if !enabled?
|
395
379
|
result = Array(previous)
|
396
380
|
|
397
381
|
@samples_lock.synchronize do
|
398
|
-
result = add_samples_to(result
|
382
|
+
result = add_samples_to(result)
|
399
383
|
|
400
384
|
# clear previous transaction samples
|
401
385
|
@slowest_sample = nil
|
@@ -409,7 +393,7 @@ module NewRelic
|
|
409
393
|
|
410
394
|
# Truncate the samples at 2100 segments. The UI will clamp them at 2000 segments anyway.
|
411
395
|
# This will save us memory and bandwidth.
|
412
|
-
result.each { |sample| sample.truncate(
|
396
|
+
result.each { |sample| sample.truncate(Agent.config[:'transaction_tracer.limit_segments']) }
|
413
397
|
result
|
414
398
|
end
|
415
399
|
|
@@ -445,7 +429,7 @@ module NewRelic
|
|
445
429
|
# new transaction sample builder with the stated time as a
|
446
430
|
# starting point and saves it in the thread local variable
|
447
431
|
def start_builder(time=nil)
|
448
|
-
if
|
432
|
+
if !enabled? || !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
449
433
|
clear_builder
|
450
434
|
else
|
451
435
|
Thread::current[BUILDER_KEY] ||= TransactionSampleBuilder.new(time)
|
@@ -6,23 +6,22 @@ module NewRelic
|
|
6
6
|
# A task is a proc or block with a specified call period in seconds.
|
7
7
|
class WorkerLoop
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# Optional argument :duration (in seconds) for how long the worker loop runs
|
10
|
+
# or :limit (integer) for max number of iterations
|
11
|
+
def initialize(opts={})
|
11
12
|
@should_run = true
|
12
13
|
@next_invocation_time = Time.now
|
13
14
|
@period = 60.0
|
15
|
+
@deadline = Time.now + opts[:duration] if opts[:duration]
|
16
|
+
@limit = opts[:limit] if opts[:limit]
|
17
|
+
@iterations = 0
|
14
18
|
end
|
15
|
-
|
19
|
+
|
16
20
|
# returns a class-level memoized mutex to make sure we don't run overlapping
|
17
21
|
def lock
|
18
22
|
@@lock ||= Mutex.new
|
19
23
|
end
|
20
|
-
|
21
|
-
# a helper to access the NewRelic::Control.instance.log
|
22
|
-
def log
|
23
|
-
NewRelic::Control.instance.log
|
24
|
-
end
|
25
|
-
|
24
|
+
|
26
25
|
# Run infinitely, calling the registered tasks at their specified
|
27
26
|
# call periods. The caller is responsible for creating the thread
|
28
27
|
# that runs this worker loop. This will run the task immediately.
|
@@ -30,28 +29,37 @@ module NewRelic
|
|
30
29
|
@period = period if period
|
31
30
|
@next_invocation_time = (Time.now + @period)
|
32
31
|
@task = block
|
33
|
-
while keep_running do
|
34
|
-
now
|
35
|
-
while now < @next_invocation_time
|
32
|
+
while keep_running? do
|
33
|
+
while @now < @next_invocation_time
|
36
34
|
# sleep until this next task's scheduled invocation time
|
37
|
-
sleep_time = @next_invocation_time - now
|
35
|
+
sleep_time = @next_invocation_time - @now
|
38
36
|
sleep sleep_time if sleep_time > 0
|
39
|
-
now = Time.now
|
37
|
+
@now = Time.now
|
40
38
|
end
|
41
|
-
run_task if keep_running
|
39
|
+
run_task if keep_running?
|
40
|
+
@iterations += 1 if !@limit.nil?
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
# a simple accessor for @should_run
|
46
|
-
def keep_running
|
47
|
-
@
|
45
|
+
def keep_running?
|
46
|
+
@now = Time.now
|
47
|
+
@should_run && under_duration? && under_limit?
|
48
|
+
end
|
49
|
+
|
50
|
+
def under_duration?
|
51
|
+
!@deadline || @now < @deadline
|
52
|
+
end
|
53
|
+
|
54
|
+
def under_limit?
|
55
|
+
!@limit || @iterations < @limit
|
48
56
|
end
|
49
|
-
|
57
|
+
|
50
58
|
# Sets @should_run to false. Returns false
|
51
59
|
def stop
|
52
60
|
@should_run = false
|
53
61
|
end
|
54
|
-
|
62
|
+
|
55
63
|
# Executes the block given to the worker loop, and handles many
|
56
64
|
# possible errors. Also updates the execution time so that the
|
57
65
|
# next run occurs on schedule, even if we execute at some odd time
|
@@ -61,23 +69,21 @@ module NewRelic
|
|
61
69
|
@task.call
|
62
70
|
end
|
63
71
|
rescue ServerError => e
|
64
|
-
|
72
|
+
::NewRelic::Agent.logger.debug "Server Error:", e
|
65
73
|
rescue NewRelic::Agent::ForceRestartException, NewRelic::Agent::ForceDisconnectException
|
66
74
|
# blow out the loop
|
67
75
|
raise
|
68
76
|
rescue RuntimeError => e
|
69
77
|
# This is probably a server error which has been logged in the server along
|
70
78
|
# with your account name.
|
71
|
-
|
72
|
-
log.debug e.backtrace.join("\n")
|
79
|
+
::NewRelic::Agent.logger.error "Error running task in worker loop, likely a server error:", e
|
73
80
|
rescue Timeout::Error, NewRelic::Agent::ServerConnectionException
|
74
81
|
# Want to ignore these because they are handled already
|
75
82
|
rescue SystemExit, NoMemoryError, SignalException
|
76
83
|
raise
|
77
84
|
rescue => e
|
78
85
|
# Don't blow out the stack for anything that hasn't already propagated
|
79
|
-
|
80
|
-
log.debug e.backtrace.join("\n")
|
86
|
+
::NewRelic::Agent.logger.error "Error running task in Agent Worker Loop:", e
|
81
87
|
end
|
82
88
|
now = Time.now
|
83
89
|
while @next_invocation_time <= now && @period > 0
|
@@ -33,7 +33,7 @@ module NewRelic
|
|
33
33
|
# Return nil if there is no backtrace
|
34
34
|
|
35
35
|
def strip_nr_from_backtrace(backtrace)
|
36
|
-
if backtrace && !
|
36
|
+
if backtrace && !Agent.config[:disable_backtrace_cleanup]
|
37
37
|
# this is for 1.9.1, where strings no longer have Enumerable
|
38
38
|
backtrace = backtrace.split("\n") if String === backtrace
|
39
39
|
backtrace = backtrace.map &:to_s
|
@@ -11,7 +11,7 @@ require 'rexml/document'
|
|
11
11
|
require 'new_relic/control' unless defined? NewRelic::Control
|
12
12
|
|
13
13
|
class NewRelic::Command::Deployments < NewRelic::Command
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :control
|
15
15
|
def self.command; "deployments"; end
|
16
16
|
|
17
17
|
# Initialize the deployment uploader with command line args.
|
@@ -24,12 +24,18 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
24
24
|
# Will throw CommandFailed exception if there's any error.
|
25
25
|
#
|
26
26
|
def initialize command_line_args
|
27
|
-
@
|
27
|
+
@control = NewRelic::Control.instance
|
28
28
|
super(command_line_args)
|
29
29
|
@description ||= @leftover && @leftover.join(" ")
|
30
30
|
@user ||= ENV['USER']
|
31
|
-
|
32
|
-
|
31
|
+
control.env = @environment if @environment
|
32
|
+
load_yaml_from_env(control.env)
|
33
|
+
@appname ||= NewRelic::Agent.config.app_names[0] || control.env || 'development'
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_yaml_from_env(env)
|
37
|
+
yaml = NewRelic::Agent::Configuration::YamlSource.new(NewRelic::Agent.config[:config_path], env)
|
38
|
+
NewRelic::Agent.config.replace_or_add_config(yaml, 1)
|
33
39
|
end
|
34
40
|
|
35
41
|
# Run the Deployment upload in New Relic via Active Resource.
|
@@ -48,12 +54,15 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
48
54
|
}.each do |k, v|
|
49
55
|
create_params["deployment[#{k}]"] = v unless v.nil? || v == ''
|
50
56
|
end
|
51
|
-
http =
|
57
|
+
http = control.http_connection(control.api_server)
|
52
58
|
|
53
59
|
uri = "/deployments.xml"
|
54
60
|
|
55
|
-
|
56
|
-
|
61
|
+
if NewRelic::Agent.config[:license_key].nil? ||
|
62
|
+
NewRelic::Agent.config[:license_key].empty?
|
63
|
+
raise "license_key was not set in newrelic.yml for #{control.env}"
|
64
|
+
end
|
65
|
+
request = Net::HTTP::Post.new(uri, {'x-license-key' => NewRelic::Agent.config[:license_key]})
|
57
66
|
request.content_type = "application/octet-stream"
|
58
67
|
|
59
68
|
request.set_form_data(create_params)
|
@@ -68,12 +77,12 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
68
77
|
end
|
69
78
|
rescue SystemCallError, SocketError => e
|
70
79
|
# These include Errno connection errors
|
71
|
-
err_string = "Transient error attempting to connect to #{
|
80
|
+
err_string = "Transient error attempting to connect to #{control.api_server} (#{e})"
|
72
81
|
raise NewRelic::Command::CommandFailure.new(err_string)
|
73
82
|
rescue NewRelic::Command::CommandFailure
|
74
83
|
raise
|
75
84
|
rescue => e
|
76
|
-
err "Unexpected error attempting to connect to #{
|
85
|
+
err "Unexpected error attempting to connect to #{control.api_server}"
|
77
86
|
info "#{e}: #{e.backtrace.join("\n ")}"
|
78
87
|
raise NewRelic::Command::CommandFailure.new(e.to_s)
|
79
88
|
end
|
@@ -89,7 +98,7 @@ class NewRelic::Command::Deployments < NewRelic::Command
|
|
89
98
|
"Default is app_name setting in newrelic.yml") { | e | @appname = e }
|
90
99
|
o.on("-e", "--environment=name", String,
|
91
100
|
"Override the (RAILS|MERB|RUBY|RACK)_ENV setting",
|
92
|
-
"currently: #{
|
101
|
+
"currently: #{control.env}") { | e | @environment = e }
|
93
102
|
o.on("-u", "--user=USER", String,
|
94
103
|
"Specify the user deploying, for information only",
|
95
104
|
"Default: #{@user || '<none>'}") { | u | @user = u }
|
data/lib/new_relic/control.rb
CHANGED
@@ -2,6 +2,7 @@ require 'yaml'
|
|
2
2
|
require 'conditional_vendored_metric_parser'
|
3
3
|
require 'conditional_vendored_dependency_detection'
|
4
4
|
require 'new_relic/local_environment'
|
5
|
+
require 'new_relic/helper'
|
5
6
|
|
6
7
|
require 'singleton'
|
7
8
|
require 'erb'
|
@@ -10,8 +11,6 @@ require 'net/https'
|
|
10
11
|
require 'logger'
|
11
12
|
require 'new_relic/control/frameworks'
|
12
13
|
require 'new_relic/control/profiling'
|
13
|
-
require 'new_relic/control/logging_methods'
|
14
|
-
require 'new_relic/control/configuration'
|
15
14
|
require 'new_relic/control/server_methods'
|
16
15
|
require 'new_relic/control/instrumentation'
|
17
16
|
require 'new_relic/control/class_methods'
|
@@ -35,7 +34,6 @@ module NewRelic
|
|
35
34
|
# extend ClassMethods
|
36
35
|
# include InstanceMethods
|
37
36
|
# include Profiling
|
38
|
-
# include LoggingMethods
|
39
37
|
# include Configuration
|
40
38
|
# include ServerMethods
|
41
39
|
# include Instrumentation
|