ghazel-newrelic_rpm 3.4.0.2 → 3.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +180 -1
- data/GUIDELINES_FOR_CONTRIBUTING.md +73 -0
- data/Gemfile +16 -0
- data/InstallationNotes.md +15 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +71 -55
- data/Rakefile +54 -0
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/init.rb +38 -0
- data/lib/new_relic/agent.rb +9 -4
- data/lib/new_relic/agent/agent.rb +189 -230
- data/lib/new_relic/agent/beacon_configuration.rb +34 -48
- data/lib/new_relic/agent/browser_monitoring.rb +108 -61
- data/lib/new_relic/agent/busy_calculator.rb +12 -4
- data/lib/new_relic/agent/configuration.rb +49 -0
- data/lib/new_relic/agent/configuration/defaults.rb +89 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +56 -0
- data/lib/new_relic/agent/configuration/manager.rb +116 -0
- data/lib/new_relic/agent/configuration/server_source.rb +27 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
- data/lib/new_relic/agent/database.rb +37 -22
- data/lib/new_relic/agent/error_collector.rb +47 -43
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +27 -6
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +2 -10
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +4 -18
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +5 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra.rb +14 -10
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +4 -3
- data/lib/new_relic/agent/method_tracer.rb +5 -1
- data/lib/new_relic/agent/new_relic_service.rb +231 -61
- data/lib/new_relic/agent/pipe_channel_manager.rb +37 -23
- data/lib/new_relic/agent/pipe_service.rb +5 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
- data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -2
- data/lib/new_relic/agent/sql_sampler.rb +44 -68
- 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 +7 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +19 -11
- data/lib/new_relic/agent/thread.rb +27 -0
- data/lib/new_relic/agent/thread_profiler.rb +295 -0
- data/lib/new_relic/agent/transaction_info.rb +24 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +11 -11
- data/lib/new_relic/agent/transaction_sampler.rb +51 -61
- data/lib/new_relic/agent/worker_loop.rb +29 -15
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +19 -10
- data/lib/new_relic/control.rb +0 -1
- data/lib/new_relic/control/class_methods.rb +2 -3
- data/lib/new_relic/control/frameworks/rails.rb +24 -18
- data/lib/new_relic/control/frameworks/rails3.rb +18 -1
- data/lib/new_relic/control/frameworks/ruby.rb +2 -2
- data/lib/new_relic/control/instance_methods.rb +36 -53
- data/lib/new_relic/control/logging_methods.rb +5 -23
- data/lib/new_relic/control/server_methods.rb +11 -13
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/helper.rb +13 -0
- data/lib/new_relic/language_support.rb +19 -22
- data/lib/new_relic/local_environment.rb +2 -3
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/metric_spec.rb +6 -2
- data/lib/new_relic/noticed_error.rb +24 -9
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/browser_monitoring.rb +28 -10
- data/lib/new_relic/rack/developer_mode.rb +3 -0
- data/lib/new_relic/rack/error_collector.rb +56 -0
- data/lib/new_relic/transaction_sample.rb +23 -13
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +3 -3
- data/lib/tasks/tests.rake +8 -8
- data/newrelic.yml +15 -32
- data/newrelic_rpm.gemspec +158 -38
- data/newrelic_rpm.gemspec.erb +55 -0
- data/test/config/newrelic.yml +3 -2
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +90 -0
- data/test/multiverse/Rakefile +17 -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 +3 -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/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/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 +23 -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/problem_response.html +422 -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 +115 -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 +76 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -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 +134 -164
- data/test/new_relic/agent/agent/start_test.rb +111 -81
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +6 -33
- data/test/new_relic/agent/agent_test.rb +88 -9
- 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/beacon_configuration_test.rb +63 -67
- data/test/new_relic/agent/browser_monitoring_test.rb +150 -79
- data/test/new_relic/agent/configuration/environment_source_test.rb +74 -0
- data/test/new_relic/agent/configuration/manager_test.rb +149 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
- data/test/new_relic/agent/error_collector_test.rb +22 -12
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +21 -11
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -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 +5 -5
- data/test/new_relic/agent/method_tracer_test.rb +6 -6
- data/test/new_relic/agent/mock_scope_listener.rb +3 -0
- data/test/new_relic/agent/new_relic_service_test.rb +208 -23
- data/test/new_relic/agent/pipe_channel_manager_test.rb +34 -17
- data/test/new_relic/agent/rpm_agent_test.rb +27 -23
- 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 +536 -0
- data/test/new_relic/agent/thread_test.rb +76 -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 -6
- data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
- data/test/new_relic/agent/worker_loop_test.rb +20 -0
- data/test/new_relic/agent_test.rb +69 -41
- 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/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control/logging_methods_test.rb +78 -52
- data/test/new_relic/control_test.rb +91 -129
- data/test/new_relic/fake_collector.rb +103 -31
- data/test/new_relic/fake_service.rb +8 -2
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +7 -10
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +14 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +15 -9
- 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/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +47 -2
- data/test/script/build_test_gem.sh +9 -3
- data/test/script/ci.sh +48 -21
- data/test/script/ci_multiverse_runner.sh +11 -11
- data/test/test_helper.rb +37 -18
- data/ui/helpers/developer_mode_helper.rb +21 -11
- data/ui/views/layouts/newrelic_default.rhtml +1 -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 +132 -58
- data/lib/new_relic/control/configuration.rb +0 -206
- data/test/new_relic/control/configuration_test.rb +0 -77
@@ -11,14 +11,15 @@ module NewRelic
|
|
11
11
|
@guid = ""
|
12
12
|
@transaction_name = "(unknown)"
|
13
13
|
@start_time = Time.now
|
14
|
+
@ignore_end_user = false
|
14
15
|
end
|
15
16
|
|
16
17
|
def force_persist_sample?(sample)
|
17
|
-
token && sample.duration >
|
18
|
+
token && sample.duration > Agent.config[:apdex_t]
|
18
19
|
end
|
19
20
|
|
20
21
|
def include_guid?
|
21
|
-
token && duration >
|
22
|
+
token && duration > Agent.config[:apdex_t]
|
22
23
|
end
|
23
24
|
|
24
25
|
def guid
|
@@ -32,6 +33,14 @@ module NewRelic
|
|
32
33
|
def duration
|
33
34
|
Time.now - start_time
|
34
35
|
end
|
36
|
+
|
37
|
+
def ignore_end_user?
|
38
|
+
@ignore_end_user
|
39
|
+
end
|
40
|
+
|
41
|
+
def ignore_end_user=(value)
|
42
|
+
@ignore_end_user = value
|
43
|
+
end
|
35
44
|
|
36
45
|
def self.get()
|
37
46
|
Thread.current[:newrelic_transaction_info] ||= TransactionInfo.new
|
@@ -57,17 +66,28 @@ module NewRelic
|
|
57
66
|
return nil unless request
|
58
67
|
|
59
68
|
agent_flag = request.cookies['NRAGENT']
|
60
|
-
if agent_flag
|
69
|
+
if agent_flag and agent_flag.instance_of? String
|
61
70
|
s = agent_flag.split("=")
|
62
71
|
if s.length == 2
|
63
72
|
if s[0] == "tk" && s[1]
|
64
|
-
ERB::Util.h(s[1])
|
73
|
+
ERB::Util.h(sanitize_token(s[1]))
|
65
74
|
end
|
66
75
|
end
|
67
76
|
else
|
68
77
|
nil
|
69
78
|
end
|
70
79
|
end
|
80
|
+
|
81
|
+
# Run through a collection of unsafe characters ( in the context of the token )
|
82
|
+
# and set the token to an empty string if any of them are found in the token so that
|
83
|
+
# potential XSS attacks via the token are avoided
|
84
|
+
def self.sanitize_token(token)
|
85
|
+
|
86
|
+
if ( /[<>'"]/ =~ token )
|
87
|
+
token.replace("")
|
88
|
+
end
|
89
|
+
token
|
90
|
+
end
|
71
91
|
end
|
72
92
|
end
|
73
93
|
end
|
@@ -9,7 +9,6 @@ module NewRelic
|
|
9
9
|
# accessed by any other thread so no need for synchronization.
|
10
10
|
class TransactionSampleBuilder
|
11
11
|
attr_reader :current_segment, :sample
|
12
|
-
attr_accessor :segment_limit
|
13
12
|
|
14
13
|
include NewRelic::CollectionHelper
|
15
14
|
|
@@ -17,8 +16,6 @@ module NewRelic
|
|
17
16
|
@sample = NewRelic::TransactionSample.new(time.to_f)
|
18
17
|
@sample_start = time.to_f
|
19
18
|
@current_segment = @sample.root_segment
|
20
|
-
@segment_limit = NewRelic::Control.instance.fetch('transaction_tracer', {}) \
|
21
|
-
.fetch('limit_segments', 4000)
|
22
19
|
end
|
23
20
|
|
24
21
|
def sample_id
|
@@ -34,19 +31,20 @@ module NewRelic
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def trace_entry(metric_name, time)
|
37
|
-
|
34
|
+
segment_limit = Agent.config[:'transaction_tracer.limit_segments']
|
35
|
+
if @sample.count_segments < segment_limit
|
38
36
|
segment = @sample.create_segment(time.to_f - @sample_start, metric_name)
|
39
37
|
@current_segment.add_called_segment(segment)
|
40
38
|
@current_segment = segment
|
41
|
-
if @sample.count_segments ==
|
42
|
-
NewRelic::Control.instance.log.debug("Segment limit of #{
|
39
|
+
if @sample.count_segments == segment_limit
|
40
|
+
NewRelic::Control.instance.log.debug("Segment limit of #{segment_limit} reached, ceasing collection.")
|
43
41
|
end
|
44
42
|
@current_segment
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
46
|
def trace_exit(metric_name, time)
|
49
|
-
return unless @sample.count_segments <
|
47
|
+
return unless @sample.count_segments < Agent.config[:'transaction_tracer.limit_segments']
|
50
48
|
if metric_name != @current_segment.metric_name
|
51
49
|
fail "unbalanced entry/exit: #{metric_name} != #{@current_segment.metric_name}"
|
52
50
|
end
|
@@ -63,8 +61,9 @@ module NewRelic
|
|
63
61
|
return
|
64
62
|
end
|
65
63
|
@sample.root_segment.end_trace(time.to_f - @sample_start)
|
66
|
-
@sample.params[:custom_params]
|
67
|
-
|
64
|
+
@sample.params[:custom_params] ||= {}
|
65
|
+
@sample.params[:custom_params].merge!(normalize_params(NewRelic::Agent::Instrumentation::MetricFrame.custom_parameters))
|
66
|
+
|
68
67
|
@sample.force_persist = NewRelic::Agent::TransactionInfo.get.force_persist_sample?(sample)
|
69
68
|
@sample.freeze
|
70
69
|
@current_segment = nil
|
@@ -93,7 +92,7 @@ module NewRelic
|
|
93
92
|
def set_transaction_info(path, uri, params)
|
94
93
|
@sample.params[:path] = path
|
95
94
|
|
96
|
-
if
|
95
|
+
if Agent.config[:capture_params]
|
97
96
|
params = normalize_params params
|
98
97
|
|
99
98
|
@sample.params[:request_params].merge!(params)
|
@@ -104,7 +103,8 @@ module NewRelic
|
|
104
103
|
end
|
105
104
|
|
106
105
|
def set_transaction_cpu_time(cpu_time)
|
107
|
-
@sample.params[:
|
106
|
+
@sample.params[:custom_params] ||= {}
|
107
|
+
@sample.params[:custom_params][:cpu_time] = cpu_time
|
108
108
|
end
|
109
109
|
|
110
110
|
def sample
|
@@ -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,31 @@ 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
|
-
|
45
|
+
Agent.config.register_callback(:'transaction_tracer.enabled') do |enabled|
|
46
|
+
if enabled
|
47
|
+
threshold = Agent.config[:'transaction_tracer.transaction_threshold']
|
48
|
+
log.debug "Transaction tracing threshold is #{threshold} seconds."
|
49
|
+
else
|
50
|
+
log.debug "Transaction traces will not be sent to the New Relic service."
|
51
|
+
end
|
52
|
+
end
|
61
53
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
54
|
+
Agent.config.register_callback(:'transaction_tracer.record_sql') do |config|
|
55
|
+
if config == 'raw'
|
56
|
+
log.warn("Agent is configured to send raw SQL to the service")
|
57
|
+
end
|
66
58
|
end
|
67
59
|
end
|
68
60
|
|
69
|
-
def
|
70
|
-
NewRelic::Control.instance.
|
61
|
+
def log
|
62
|
+
NewRelic::Control.instance.log
|
71
63
|
end
|
72
64
|
|
73
65
|
# Returns the current sample id, delegated from `builder`
|
@@ -76,22 +68,8 @@ module NewRelic
|
|
76
68
|
b and b.sample_id
|
77
69
|
end
|
78
70
|
|
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
71
|
def enabled?
|
94
|
-
|
72
|
+
Agent.config[:'transaction_tracer.enabled'] || Agent.config[:developer_mode]
|
95
73
|
end
|
96
74
|
|
97
75
|
# Set with an integer value n, this takes one in every n
|
@@ -107,7 +85,7 @@ module NewRelic
|
|
107
85
|
# transaction sampler is disabled. Takes a time parameter for
|
108
86
|
# the start of the transaction sample
|
109
87
|
def notice_first_scope_push(time)
|
110
|
-
start_builder(time.to_f)
|
88
|
+
start_builder(time.to_f) if enabled?
|
111
89
|
end
|
112
90
|
|
113
91
|
# This delegates to the builder to create a new open transaction
|
@@ -121,14 +99,14 @@ module NewRelic
|
|
121
99
|
|
122
100
|
builder.trace_entry(scope, time.to_f)
|
123
101
|
|
124
|
-
capture_segment_trace if
|
102
|
+
capture_segment_trace if Agent.config[:developer_mode]
|
125
103
|
end
|
126
104
|
|
127
105
|
# in developer mode, capture the stack trace with the segment.
|
128
106
|
# this is cpu and memory expensive and therefore should not be
|
129
107
|
# turned on in production mode
|
130
108
|
def capture_segment_trace
|
131
|
-
return unless
|
109
|
+
return unless Agent.config[:developer_mode]
|
132
110
|
segment = builder.current_segment
|
133
111
|
if segment
|
134
112
|
# Strip stack frames off the top that match /new_relic/agent/
|
@@ -186,20 +164,26 @@ module NewRelic
|
|
186
164
|
# @samples array, and the @slowest_sample variable if it is
|
187
165
|
# slower than the current occupant of that slot
|
188
166
|
def store_sample(sample)
|
189
|
-
|
167
|
+
sampler_methods = [ :store_slowest_sample ]
|
168
|
+
if Agent.config[:developer_mode]
|
169
|
+
sampler_methods << :store_sample_for_developer_mode
|
170
|
+
end
|
171
|
+
if Agent.config[:'transaction_tracer.random_sample']
|
172
|
+
sampler_methods << :store_random_sample
|
173
|
+
end
|
174
|
+
|
175
|
+
sampler_methods.each{|sym| send(sym, sample) }
|
176
|
+
|
190
177
|
if NewRelic::Agent::TransactionInfo.get.force_persist_sample?(sample)
|
191
178
|
store_force_persist(sample)
|
192
179
|
end
|
193
|
-
|
194
180
|
end
|
195
181
|
|
196
182
|
# Only active when random sampling is true - this is very rarely
|
197
183
|
# used. Always store the most recent sample so that random
|
198
184
|
# sampling can pick a few of the samples to store, upon harvest
|
199
185
|
def store_random_sample(sample)
|
200
|
-
if
|
201
|
-
@random_sample = sample
|
202
|
-
end
|
186
|
+
@random_sample = sample if Agent.config[:'transaction_tracer.random_sample']
|
203
187
|
end
|
204
188
|
|
205
189
|
def store_force_persist(sample)
|
@@ -215,7 +199,7 @@ module NewRelic
|
|
215
199
|
# Samples take up a ton of memory, so we only store a lot of
|
216
200
|
# them in developer mode - we truncate to @max_samples
|
217
201
|
def store_sample_for_developer_mode(sample)
|
218
|
-
return unless
|
202
|
+
return unless Agent.config[:developer_mode]
|
219
203
|
@samples = [] unless @samples
|
220
204
|
@samples << sample
|
221
205
|
truncate_samples
|
@@ -229,7 +213,7 @@ module NewRelic
|
|
229
213
|
end
|
230
214
|
end
|
231
215
|
|
232
|
-
# Checks to see if the old sample exists, or if
|
216
|
+
# Checks to see if the old sample exists, or if its duration is
|
233
217
|
# less than the new sample
|
234
218
|
def slowest_sample?(old_sample, new_sample)
|
235
219
|
old_sample.nil? || (new_sample.duration > old_sample.duration)
|
@@ -246,7 +230,7 @@ module NewRelic
|
|
246
230
|
# Delegates to the builder to store the path, uri, and
|
247
231
|
# parameters if the sampler is active
|
248
232
|
def notice_transaction(path, uri=nil, params={})
|
249
|
-
builder.set_transaction_info(path, uri, params) if
|
233
|
+
builder.set_transaction_info(path, uri, params) if enabled? && builder
|
250
234
|
end
|
251
235
|
|
252
236
|
# Tells the builder to ignore a transaction, if we are currently
|
@@ -315,7 +299,10 @@ module NewRelic
|
|
315
299
|
# Appends a backtrace to a segment if that segment took longer
|
316
300
|
# than the specified duration
|
317
301
|
def append_backtrace(segment, duration)
|
318
|
-
|
302
|
+
if (duration >= Agent.config[:'transaction_tracer.stack_trace_threshold'] ||
|
303
|
+
Thread.current[:capture_deep_tt])
|
304
|
+
segment[:backtrace] = caller.join("\n")
|
305
|
+
end
|
319
306
|
end
|
320
307
|
|
321
308
|
# some statements (particularly INSERTS with large BLOBS
|
@@ -343,9 +330,10 @@ module NewRelic
|
|
343
330
|
#
|
344
331
|
# random sampling is very, very seldom used
|
345
332
|
def add_random_sample_to(result)
|
346
|
-
return unless @
|
333
|
+
return unless @random_sample &&
|
334
|
+
Agent.config[:sample_rate] && Agent.config[:sample_rate].to_i > 0
|
347
335
|
@harvest_count += 1
|
348
|
-
if (@harvest_count.to_i %
|
336
|
+
if (@harvest_count.to_i % Agent.config[:sample_rate].to_i) == 0
|
349
337
|
result << @random_sample if @random_sample
|
350
338
|
@harvest_count = 0
|
351
339
|
end
|
@@ -361,7 +349,7 @@ module NewRelic
|
|
361
349
|
# elements - one element unless random sampling is enabled. The
|
362
350
|
# sample returned will be the slowest sample among those
|
363
351
|
# available during this harvest
|
364
|
-
def add_samples_to(result
|
352
|
+
def add_samples_to(result)
|
365
353
|
# pull out force persist
|
366
354
|
force_persist = result.select {|sample| sample.force_persist} || []
|
367
355
|
result.reject! {|sample| sample.force_persist}
|
@@ -370,7 +358,9 @@ module NewRelic
|
|
370
358
|
|
371
359
|
|
372
360
|
# Now get the slowest sample
|
373
|
-
if @slowest_sample &&
|
361
|
+
if @slowest_sample &&
|
362
|
+
@slowest_sample.duration >=
|
363
|
+
Agent.config[:'transaction_tracer.transaction_threshold']
|
374
364
|
result << @slowest_sample
|
375
365
|
end
|
376
366
|
|
@@ -386,14 +376,14 @@ module NewRelic
|
|
386
376
|
|
387
377
|
# get the set of collected samples, merging into previous samples,
|
388
378
|
# and clear the collected sample list. Truncates samples to a
|
389
|
-
# specified
|
379
|
+
# specified segment_limit to save memory and bandwith
|
390
380
|
# transmitting samples to the server.
|
391
|
-
def harvest(previous
|
392
|
-
return [] if
|
381
|
+
def harvest(previous=[])
|
382
|
+
return [] if !enabled?
|
393
383
|
result = Array(previous)
|
394
384
|
|
395
385
|
@samples_lock.synchronize do
|
396
|
-
result = add_samples_to(result
|
386
|
+
result = add_samples_to(result)
|
397
387
|
|
398
388
|
# clear previous transaction samples
|
399
389
|
@slowest_sample = nil
|
@@ -407,7 +397,7 @@ module NewRelic
|
|
407
397
|
|
408
398
|
# Truncate the samples at 2100 segments. The UI will clamp them at 2000 segments anyway.
|
409
399
|
# This will save us memory and bandwidth.
|
410
|
-
result.each { |sample| sample.truncate(
|
400
|
+
result.each { |sample| sample.truncate(Agent.config[:'transaction_tracer.limit_segments']) }
|
411
401
|
result
|
412
402
|
end
|
413
403
|
|
@@ -443,7 +433,7 @@ module NewRelic
|
|
443
433
|
# new transaction sample builder with the stated time as a
|
444
434
|
# starting point and saves it in the thread local variable
|
445
435
|
def start_builder(time=nil)
|
446
|
-
if
|
436
|
+
if !enabled? || !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
447
437
|
clear_builder
|
448
438
|
else
|
449
439
|
Thread::current[BUILDER_KEY] ||= TransactionSampleBuilder.new(time)
|
@@ -6,23 +6,28 @@ 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
|
-
|
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={})
|
10
12
|
@log = log
|
11
13
|
@should_run = true
|
12
14
|
@next_invocation_time = Time.now
|
13
15
|
@period = 60.0
|
16
|
+
@deadline = Time.now + opts[:duration] if opts[:duration]
|
17
|
+
@limit = opts[:limit] if opts[:limit]
|
18
|
+
@iterations = 0
|
14
19
|
end
|
15
|
-
|
20
|
+
|
16
21
|
# returns a class-level memoized mutex to make sure we don't run overlapping
|
17
22
|
def lock
|
18
23
|
@@lock ||= Mutex.new
|
19
24
|
end
|
20
|
-
|
25
|
+
|
21
26
|
# a helper to access the NewRelic::Control.instance.log
|
22
27
|
def log
|
23
28
|
NewRelic::Control.instance.log
|
24
29
|
end
|
25
|
-
|
30
|
+
|
26
31
|
# Run infinitely, calling the registered tasks at their specified
|
27
32
|
# call periods. The caller is responsible for creating the thread
|
28
33
|
# that runs this worker loop. This will run the task immediately.
|
@@ -30,28 +35,37 @@ module NewRelic
|
|
30
35
|
@period = period if period
|
31
36
|
@next_invocation_time = (Time.now + @period)
|
32
37
|
@task = block
|
33
|
-
while keep_running do
|
34
|
-
now
|
35
|
-
while now < @next_invocation_time
|
38
|
+
while keep_running? do
|
39
|
+
while @now < @next_invocation_time
|
36
40
|
# sleep until this next task's scheduled invocation time
|
37
|
-
sleep_time = @next_invocation_time - now
|
41
|
+
sleep_time = @next_invocation_time - @now
|
38
42
|
sleep sleep_time if sleep_time > 0
|
39
|
-
now = Time.now
|
43
|
+
@now = Time.now
|
40
44
|
end
|
41
|
-
run_task if keep_running
|
45
|
+
run_task if keep_running?
|
46
|
+
@iterations += 1 if !@limit.nil?
|
42
47
|
end
|
43
48
|
end
|
44
|
-
|
49
|
+
|
45
50
|
# a simple accessor for @should_run
|
46
|
-
def keep_running
|
47
|
-
@
|
51
|
+
def keep_running?
|
52
|
+
@now = Time.now
|
53
|
+
@should_run && under_duration? && under_limit?
|
54
|
+
end
|
55
|
+
|
56
|
+
def under_duration?
|
57
|
+
!@deadline || @now < @deadline
|
58
|
+
end
|
59
|
+
|
60
|
+
def under_limit?
|
61
|
+
!@limit || @iterations < @limit
|
48
62
|
end
|
49
|
-
|
63
|
+
|
50
64
|
# Sets @should_run to false. Returns false
|
51
65
|
def stop
|
52
66
|
@should_run = false
|
53
67
|
end
|
54
|
-
|
68
|
+
|
55
69
|
# Executes the block given to the worker loop, and handles many
|
56
70
|
# possible errors. Also updates the execution time so that the
|
57
71
|
# next run occurs on schedule, even if we execute at some odd time
|