newrelic_rpm 3.8.1.221 → 3.9.0.229
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +1 -0
- data/.yardopts +2 -0
- data/CHANGELOG +95 -0
- data/README.md +9 -3
- data/Rakefile +6 -0
- data/lib/new_relic/agent.rb +37 -52
- data/lib/new_relic/agent/agent.rb +32 -64
- data/lib/new_relic/agent/agent_logger.rb +3 -2
- data/lib/new_relic/agent/audit_logger.rb +2 -1
- data/lib/new_relic/agent/busy_calculator.rb +10 -8
- data/lib/new_relic/agent/configuration.rb +0 -13
- data/lib/new_relic/agent/configuration/default_source.rb +27 -20
- data/lib/new_relic/agent/configuration/manager.rb +101 -27
- data/lib/new_relic/agent/cross_app_monitor.rb +43 -50
- data/lib/new_relic/agent/cross_app_tracing.rb +13 -12
- data/lib/new_relic/agent/error_collector.rb +31 -35
- data/lib/new_relic/agent/harvester.rb +5 -1
- data/lib/new_relic/agent/hostname.rb +17 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
- data/lib/new_relic/agent/http_clients/uri_util.rb +13 -0
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +18 -32
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +15 -15
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +6 -4
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +3 -2
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +18 -20
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +79 -93
- data/lib/new_relic/agent/instrumentation/curb.rb +3 -3
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +5 -4
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +96 -0
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +69 -0
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/queue_time.rb +21 -13
- data/lib/new_relic/agent/instrumentation/rack.rb +85 -74
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -1
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +39 -0
- data/lib/new_relic/agent/instrumentation/rubyprof.rb +3 -3
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +28 -5
- data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -4
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +4 -2
- data/lib/new_relic/agent/javascript_instrumentor.rb +34 -30
- data/lib/new_relic/agent/memory_logger.rb +12 -12
- data/lib/new_relic/agent/method_tracer.rb +34 -74
- data/lib/new_relic/agent/new_relic_service.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +3 -3
- data/lib/new_relic/agent/request_sampler.rb +10 -11
- data/lib/new_relic/agent/samplers/vm_sampler.rb +6 -6
- data/lib/new_relic/agent/shim_agent.rb +2 -1
- data/lib/new_relic/agent/sql_sampler.rb +52 -27
- data/lib/new_relic/agent/stats.rb +24 -10
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +5 -17
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +106 -58
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +20 -24
- data/lib/new_relic/agent/supported_versions.rb +3 -1
- data/lib/new_relic/agent/threading/agent_thread.rb +42 -11
- data/lib/new_relic/agent/threading/backtrace_service.rb +3 -7
- data/lib/new_relic/agent/threading/thread_profile.rb +2 -2
- data/lib/new_relic/agent/traced_method_stack.rb +28 -18
- data/lib/new_relic/agent/transaction.rb +249 -196
- data/lib/new_relic/agent/transaction_metrics.rb +57 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +10 -7
- data/lib/new_relic/agent/transaction_sampler.rb +81 -45
- data/lib/new_relic/agent/transaction_state.rb +38 -49
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +15 -18
- data/lib/new_relic/agent/vm/rubinius_vm.rb +4 -2
- data/lib/new_relic/cli/commands/deployments.rb +3 -2
- data/lib/new_relic/control/frameworks/ruby.rb +2 -3
- data/lib/new_relic/control/frameworks/sinatra.rb +0 -7
- data/lib/new_relic/control/instance_methods.rb +3 -5
- data/lib/new_relic/json_wrapper.rb +2 -0
- data/lib/new_relic/language_support.rb +1 -1
- data/lib/new_relic/local_environment.rb +0 -16
- data/lib/new_relic/metric_spec.rb +10 -38
- data/lib/new_relic/noticed_error.rb +16 -11
- data/lib/new_relic/rack/agent_hooks.rb +4 -10
- data/lib/new_relic/rack/agent_middleware.rb +31 -0
- data/lib/new_relic/rack/browser_monitoring.rb +7 -13
- data/lib/new_relic/rack/developer_mode.rb +16 -59
- data/lib/new_relic/rack/error_collector.rb +16 -54
- data/lib/new_relic/recipes.rb +8 -101
- data/lib/new_relic/recipes/capistrano3.rb +66 -0
- data/lib/new_relic/recipes/capistrano_legacy.rb +98 -0
- data/lib/new_relic/transaction_sample.rb +6 -54
- data/lib/new_relic/transaction_sample/composite_segment.rb +1 -1
- data/lib/new_relic/transaction_sample/segment.rb +12 -4
- data/lib/new_relic/transaction_sample/summary_segment.rb +1 -1
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +19 -19
- data/lib/tasks/tests.rake +20 -1
- data/lib/tasks/versions.html.erb +0 -4
- data/lib/tasks/versions.rake +4 -3
- data/newrelic.yml +4 -12
- data/newrelic_rpm.gemspec +1 -1
- data/test/agent_helper.rb +146 -44
- data/test/config/newrelic.yml +0 -1
- data/test/environments/norails/Gemfile +1 -1
- data/test/environments/rails21/Gemfile +1 -1
- data/test/environments/rails22/Gemfile +1 -1
- data/test/environments/rails23/Gemfile +1 -1
- data/test/environments/rails30/Gemfile +1 -1
- data/test/environments/rails31/Gemfile +1 -1
- data/test/environments/rails32/Gemfile +1 -1
- data/test/environments/rails40/Gemfile +1 -1
- data/test/environments/rails41/Gemfile +1 -1
- data/test/multiverse/lib/multiverse/runner.rb +13 -1
- data/test/multiverse/lib/multiverse/suite.rb +26 -9
- data/test/multiverse/suites/active_record/config/newrelic.yml +0 -1
- data/test/multiverse/suites/activemerchant/Envfile +18 -1
- data/test/multiverse/suites/agent_only/audit_log_test.rb +4 -3
- data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +35 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +0 -1
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +1 -0
- data/test/multiverse/suites/agent_only/encoding_handling_test.rb +3 -2
- data/test/multiverse/suites/agent_only/exclusive_time_test.rb +178 -0
- data/test/multiverse/suites/agent_only/logging_test.rb +10 -6
- data/test/multiverse/suites/agent_only/marshaling_test.rb +11 -9
- data/test/multiverse/suites/agent_only/script/loading.rb +1 -1
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +5 -1
- data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +2 -1
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +9 -9
- data/test/multiverse/suites/capistrano/Capfile +26 -0
- data/test/multiverse/suites/capistrano/Envfile +18 -0
- data/test/multiverse/suites/capistrano/config/deploy.rb +10 -0
- data/test/multiverse/suites/capistrano/config/deploy/production.rb +9 -0
- data/test/multiverse/suites/capistrano/config/newrelic.yml +21 -0
- data/test/multiverse/suites/capistrano/deployment_test.rb +47 -0
- data/test/multiverse/suites/capistrano2/Capfile +4 -0
- data/test/multiverse/suites/capistrano2/Envfile +4 -0
- data/test/multiverse/suites/capistrano2/config/deploy.rb +19 -0
- data/test/multiverse/suites/capistrano2/config/newrelic.yml +21 -0
- data/test/multiverse/suites/capistrano2/deployment_test.rb +38 -0
- data/test/multiverse/suites/curb/Envfile +10 -1
- data/test/multiverse/suites/curb/config/newrelic.yml +0 -1
- data/test/multiverse/suites/datamapper/config/newrelic.yml +0 -1
- data/test/multiverse/suites/deferred_instrumentation/config/newrelic.yml +0 -1
- data/test/multiverse/suites/excon/config/newrelic.yml +0 -1
- data/test/multiverse/suites/httpclient/config/newrelic.yml +0 -1
- data/test/multiverse/suites/mongo/config/newrelic.yml +0 -1
- data/test/multiverse/suites/net_http/config/newrelic.yml +0 -1
- data/test/multiverse/suites/padrino/config/newrelic.yml +0 -1
- data/test/multiverse/suites/rack/Envfile +25 -0
- data/test/multiverse/suites/rack/example_app.rb +50 -0
- data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +66 -0
- data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +143 -0
- data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +45 -0
- data/test/multiverse/suites/rack/url_map_test.rb +120 -0
- data/test/multiverse/suites/rails/Envfile +10 -0
- data/test/multiverse/suites/rails/app.rb +28 -63
- data/test/multiverse/suites/rails/bad_instrumentation_test.rb +2 -4
- data/test/multiverse/suites/rails/config/newrelic.yml +1 -2
- data/test/multiverse/suites/rails/dummy.txt +1 -0
- data/test/multiverse/suites/rails/error_tracing_test.rb +46 -31
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/rails/ignore_test.rb +9 -3
- data/test/multiverse/suites/rails/middleware_instrumentation_test.rb +41 -0
- data/test/multiverse/suites/rails/middlewares.rb +19 -0
- data/test/multiverse/suites/rails/parameter_capture_test.rb +169 -0
- data/test/multiverse/suites/rails/queue_time_test.rb +14 -4
- data/test/multiverse/suites/rails/rails2_app/app/controllers/application.rb +7 -0
- data/test/multiverse/suites/rails/rails2_app/config/boot.rb +127 -0
- data/test/multiverse/suites/rails/rails2_app/config/database.yml +18 -0
- data/test/multiverse/suites/rails/rails2_app/config/environment.rb +16 -0
- data/test/multiverse/suites/rails/rails2_app/config/environments/development.rb +10 -0
- data/test/multiverse/suites/rails/rails2_app/config/initializers/load_newrelic_rpm.rb +9 -0
- data/test/multiverse/suites/rails/rails2_app/config/preinitializer.rb +25 -0
- data/test/multiverse/suites/rails/rails2_app/config/routes.rb +18 -0
- data/test/multiverse/suites/rails/rails2_app/db/schema.rb +5 -0
- data/test/multiverse/suites/rails/rails3_app/app_rails3_plus.rb +76 -0
- data/test/multiverse/suites/rails/request_statistics_test.rb +2 -4
- data/test/multiverse/suites/rails/transaction_ignoring_test.rb +3 -5
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +73 -42
- data/test/multiverse/suites/resque/config/newrelic.yml +0 -1
- data/test/multiverse/suites/sequel/config/newrelic.yml +0 -1
- data/test/multiverse/suites/sidekiq/Envfile +4 -0
- data/test/multiverse/suites/sidekiq/after_suite.rb +7 -0
- data/test/multiverse/suites/sidekiq/config/newrelic.yml +0 -1
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +55 -34
- data/test/multiverse/suites/sidekiq/sidekiq_server.rb +30 -0
- data/test/multiverse/suites/sidekiq/test_worker.rb +60 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +0 -1
- data/test/multiverse/suites/sinatra/ignoring_test.rb +33 -11
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +3 -1
- data/test/multiverse/suites/typhoeus/Envfile +9 -0
- data/test/multiverse/suites/typhoeus/config/newrelic.yml +0 -1
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +10 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +0 -1
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +0 -1
- data/test/new_relic/agent/agent/connect_test.rb +3 -10
- data/test/new_relic/agent/agent_logger_test.rb +24 -6
- data/test/new_relic/agent/agent_test.rb +7 -8
- data/test/new_relic/agent/agent_test_controller.rb +2 -2
- data/test/new_relic/agent/audit_logger_test.rb +5 -1
- data/test/new_relic/agent/busy_calculator_test.rb +1 -1
- data/test/new_relic/agent/configuration/manager_test.rb +68 -69
- data/test/new_relic/agent/cross_app_monitor_test.rb +32 -14
- data/test/new_relic/agent/cross_app_tracing_test.rb +2 -2
- data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -33
- data/test/new_relic/agent/error_collector_test.rb +45 -14
- data/test/new_relic/agent/harvester_test.rb +9 -0
- data/test/new_relic/agent/hostname_test.rb +41 -0
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +27 -19
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/active_record_test.rb +3 -3
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +95 -14
- data/test/new_relic/agent/instrumentation/middleware_proxy_test.rb +189 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +2 -2
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +18 -1
- data/test/new_relic/agent/instrumentation/rack_test.rb +10 -1
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +3 -1
- data/test/new_relic/agent/javascript_instrumentor_test.rb +28 -41
- data/test/new_relic/agent/memory_logger_test.rb +14 -0
- data/test/new_relic/agent/method_interrobang_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -30
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +5 -21
- data/test/new_relic/agent/method_tracer_test.rb +5 -4
- data/test/new_relic/agent/mock_scope_listener.rb +2 -2
- data/test/new_relic/agent/obfuscator_test.rb +1 -1
- data/test/new_relic/agent/pipe_channel_manager_test.rb +17 -5
- data/test/new_relic/agent/request_sampler_test.rb +16 -16
- data/test/new_relic/agent/rpm_agent_test.rb +23 -29
- data/test/new_relic/agent/sql_sampler_test.rb +39 -31
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +189 -117
- data/test/new_relic/agent/stats_engine_test.rb +1 -1
- data/test/new_relic/agent/stats_hash_test.rb +28 -1
- data/test/new_relic/agent/stats_test.rb +1 -12
- data/test/new_relic/agent/threading/agent_thread_test.rb +23 -9
- data/test/new_relic/agent/threading/backtrace_service_test.rb +33 -32
- data/test/new_relic/agent/threading/fake_thread.rb +4 -8
- data/test/new_relic/agent/threading/threaded_test_case.rb +4 -14
- data/test/new_relic/agent/traced_method_stack_test.rb +43 -27
- data/test/new_relic/agent/transaction_interrobang_test.rb +1 -1
- data/test/new_relic/agent/transaction_metrics_test.rb +113 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -61
- data/test/new_relic/agent/transaction_sampler_test.rb +176 -228
- data/test/new_relic/agent/transaction_state_test.rb +62 -26
- data/test/new_relic/agent/transaction_test.rb +198 -80
- data/test/new_relic/agent/vm/monotonic_gc_profiler_test.rb +4 -4
- data/test/new_relic/agent/vm/rubinius_vm_test.rb +68 -0
- data/test/new_relic/agent_test.rb +31 -27
- data/test/new_relic/cli/commands/deployments_test.rb +7 -2
- data/test/new_relic/control/instance_methods_test.rb +4 -4
- data/test/new_relic/control_test.rb +28 -22
- data/test/new_relic/dependency_detection_test.rb +14 -0
- data/test/new_relic/fake_external_server.rb +1 -0
- data/test/new_relic/fake_rpm_site.rb +35 -0
- data/test/new_relic/http_client_test_cases.rb +12 -3
- data/test/new_relic/json_wrapper_test.rb +5 -0
- data/test/new_relic/language_support_test.rb +7 -0
- data/test/new_relic/license_test.rb +11 -5
- data/test/new_relic/local_environment_test.rb +0 -18
- data/test/new_relic/metric_data_test.rb +2 -2
- data/test/new_relic/metric_spec_test.rb +4 -23
- data/test/new_relic/multiverse_helpers.rb +1 -3
- data/test/new_relic/noticed_error_test.rb +6 -22
- data/test/new_relic/rack/agent_hooks_test.rb +5 -1
- data/test/new_relic/rack/agent_middleware_test.rb +32 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +14 -1
- data/test/new_relic/rack/developer_mode_helper_test.rb +0 -8
- data/test/new_relic/rack/developer_mode_test.rb +1 -1
- data/test/new_relic/rack/error_collector_test.rb +6 -30
- data/test/new_relic/transaction_sample/fake_segment_test.rb +2 -2
- data/test/new_relic/transaction_sample/segment_test.rb +47 -47
- data/test/new_relic/transaction_sample_test.rb +9 -8
- data/test/performance/lib/performance/instrumentation/stackprof.rb +11 -8
- data/test/performance/script/runner +13 -0
- data/test/performance/suites/config.rb +5 -2
- data/test/performance/suites/rack_middleware.rb +84 -0
- data/test/performance/suites/rum_autoinsertion.rb +1 -1
- data/test/performance/suites/thread_profiling.rb +1 -1
- data/test/test_helper.rb +12 -10
- data/ui/helpers/developer_mode_helper.rb +3 -43
- data/ui/views/layouts/newrelic_default.rhtml +2 -2
- data/ui/views/newrelic/_sample.rhtml +2 -2
- data/ui/views/newrelic/_sql_row.rhtml +11 -11
- data/ui/views/newrelic/index.rhtml +21 -22
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +15 -10
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +2 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/middleware.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/nested.rb +24 -0
- metadata +108 -31
- metadata.gz.sig +0 -0
- data/lib/new_relic/rack/transaction_reset.rb +0 -20
- data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +0 -42
- data/test/new_relic/rack/transaction_reset_test.rb +0 -35
- data/ui/views/newrelic/show_source.rhtml +0 -3
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
# This class represents a set of metrics that were recorded during a single
|
6
|
+
# transaction. Since the name of the transaction is not known until its end, we
|
7
|
+
# don't save explicit scopes with these metrics, we just keep separate
|
8
|
+
# collections of scoped and unscoped metrics.
|
9
|
+
|
10
|
+
module NewRelic
|
11
|
+
module Agent
|
12
|
+
class TransactionMetrics
|
13
|
+
DEFAULT_PROC = Proc.new { |hash, name| hash[name] = NewRelic::Agent::Stats.new }
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@unscoped = Hash.new(&DEFAULT_PROC)
|
17
|
+
@scoped = Hash.new(&DEFAULT_PROC)
|
18
|
+
end
|
19
|
+
|
20
|
+
def record_scoped(names, value=nil, aux=nil, &blk)
|
21
|
+
_record_metrics(names, value, aux, @scoped, &blk)
|
22
|
+
end
|
23
|
+
|
24
|
+
def record_unscoped(names, value=nil, aux=nil, &blk)
|
25
|
+
_record_metrics(names, value, aux, @unscoped, &blk)
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_key?(key)
|
29
|
+
@unscoped.has_key?(key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](key)
|
33
|
+
@unscoped[key]
|
34
|
+
end
|
35
|
+
|
36
|
+
def each_unscoped
|
37
|
+
@unscoped.each { |name, stats| yield name, stats }
|
38
|
+
end
|
39
|
+
|
40
|
+
def each_scoped
|
41
|
+
@scoped.each { |name, stats| yield name, stats }
|
42
|
+
end
|
43
|
+
|
44
|
+
def _record_metrics(names, value, aux, target, &blk)
|
45
|
+
# This looks dumb, but we're avoiding an extra Array allocation.
|
46
|
+
case names
|
47
|
+
when Array
|
48
|
+
names.each do |name|
|
49
|
+
target[name].record(value, aux, &blk)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
target[names].record(value, aux, &blk)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -118,10 +118,11 @@ module NewRelic
|
|
118
118
|
|
119
119
|
TT_THRESHOLD_KEY = :'transaction_tracer.transaction_threshold'
|
120
120
|
|
121
|
-
def transaction_trace_threshold
|
121
|
+
def transaction_trace_threshold #THREAD_LOCAL_ACCESS
|
122
|
+
state = TransactionState.tl_get
|
122
123
|
source_class = Agent.config.source(TT_THRESHOLD_KEY).class
|
123
|
-
if source_class == Configuration::DefaultSource &&
|
124
|
-
|
124
|
+
if source_class == Configuration::DefaultSource && state.current_transaction
|
125
|
+
state.current_transaction.apdex_t * 4
|
125
126
|
else
|
126
127
|
Agent.config[TT_THRESHOLD_KEY]
|
127
128
|
end
|
@@ -139,15 +140,17 @@ module NewRelic
|
|
139
140
|
depth
|
140
141
|
end
|
141
142
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
143
|
+
def set_transaction_uri(uri)
|
144
|
+
@sample.params[:uri] ||= uri
|
145
|
+
end
|
145
146
|
|
147
|
+
def set_request_params(params)
|
148
|
+
if Agent.config[:capture_params]
|
149
|
+
params = normalize_params(params)
|
146
150
|
@sample.params[:request_params].merge!(params)
|
147
151
|
@sample.params[:request_params].delete :controller
|
148
152
|
@sample.params[:request_params].delete :action
|
149
153
|
end
|
150
|
-
@sample.params[:uri] ||= uri || params[:uri]
|
151
154
|
end
|
152
155
|
|
153
156
|
def set_transaction_name(name)
|
@@ -13,8 +13,14 @@ require 'new_relic/agent/transaction/xray_sample_buffer'
|
|
13
13
|
module NewRelic
|
14
14
|
module Agent
|
15
15
|
|
16
|
-
# This class contains the logic
|
17
|
-
#
|
16
|
+
# This class contains the logic for recording and storing transaction
|
17
|
+
# traces (sometimes referred to as 'transaction samples').
|
18
|
+
#
|
19
|
+
# A transaction trace is a detailed timeline of the events that happened
|
20
|
+
# during the processing of a single transaction, including database calls,
|
21
|
+
# template rendering calls, and other instrumented method calls.
|
22
|
+
#
|
23
|
+
# @api public
|
18
24
|
class TransactionSampler
|
19
25
|
|
20
26
|
# Module defining methods stubbed out when the agent is disabled
|
@@ -62,10 +68,11 @@ module NewRelic
|
|
62
68
|
Agent.config[:'transaction_tracer.enabled'] || Agent.config[:developer_mode]
|
63
69
|
end
|
64
70
|
|
65
|
-
def on_start_transaction(start_time, uri=nil
|
71
|
+
def on_start_transaction(state, start_time, uri=nil)
|
66
72
|
if enabled?
|
67
|
-
start_builder(start_time.to_f)
|
68
|
-
builder
|
73
|
+
start_builder(state, start_time.to_f)
|
74
|
+
builder = state.transaction_sample_builder
|
75
|
+
builder.set_transaction_uri(uri) if builder
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
@@ -74,16 +81,20 @@ module NewRelic
|
|
74
81
|
#
|
75
82
|
# Note that in developer mode, this captures a stacktrace for
|
76
83
|
# the beginning of each segment, which can be fairly slow
|
77
|
-
def notice_push_frame(time=Time.now)
|
84
|
+
def notice_push_frame(state, time=Time.now)
|
85
|
+
builder = state.transaction_sample_builder
|
78
86
|
return unless builder
|
79
87
|
|
80
88
|
segment = builder.trace_entry(time.to_f)
|
81
|
-
@
|
82
|
-
|
89
|
+
if @dev_mode_sample_buffer
|
90
|
+
@dev_mode_sample_buffer.visit_segment(segment)
|
91
|
+
end
|
92
|
+
segment
|
83
93
|
end
|
84
94
|
|
85
95
|
# Informs the transaction sample builder about the end of a traced frame
|
86
|
-
def notice_pop_frame(frame, time = Time.now)
|
96
|
+
def notice_pop_frame(state, frame, time = Time.now)
|
97
|
+
builder = state.transaction_sample_builder
|
87
98
|
return unless builder
|
88
99
|
raise "finished already???" if builder.sample.finished
|
89
100
|
builder.trace_exit(frame, time.to_f)
|
@@ -104,15 +115,16 @@ module NewRelic
|
|
104
115
|
#
|
105
116
|
# It sets various instance variables to the finished sample,
|
106
117
|
# depending on which settings are active. See `store_sample`
|
107
|
-
def on_finishing_transaction(txn, time=Time.now, gc_time=nil)
|
108
|
-
last_builder =
|
109
|
-
last_builder
|
118
|
+
def on_finishing_transaction(state, txn, time=Time.now, gc_time=nil)
|
119
|
+
last_builder = state.transaction_sample_builder
|
120
|
+
return unless last_builder && enabled?
|
110
121
|
|
111
|
-
|
122
|
+
state.transaction_sample_builder = nil
|
123
|
+
return if last_builder.ignored?
|
112
124
|
|
125
|
+
last_builder.set_request_params(txn.filtered_params)
|
126
|
+
last_builder.set_transaction_name(txn.best_name)
|
113
127
|
last_builder.finish_trace(time.to_f, custom_parameters_from_transaction(txn))
|
114
|
-
clear_builder
|
115
|
-
return if last_builder.ignored?
|
116
128
|
|
117
129
|
@samples_lock.synchronize do
|
118
130
|
@last_sample = last_builder.sample
|
@@ -133,12 +145,14 @@ module NewRelic
|
|
133
145
|
# creating one. Only causes the sample to be ignored upon end of
|
134
146
|
# the transaction, and does not change the metrics gathered
|
135
147
|
# outside of the sampler
|
136
|
-
def ignore_transaction
|
148
|
+
def ignore_transaction(state)
|
149
|
+
builder = state.transaction_sample_builder
|
137
150
|
builder.ignore_transaction if builder
|
138
151
|
end
|
139
152
|
|
140
153
|
# Sets the CPU time used by a transaction, delegates to the builder
|
141
|
-
def notice_transaction_cpu_time(cpu_time)
|
154
|
+
def notice_transaction_cpu_time(state, cpu_time)
|
155
|
+
builder = state.transaction_sample_builder
|
142
156
|
builder.set_transaction_cpu_time(cpu_time) if builder
|
143
157
|
end
|
144
158
|
|
@@ -147,7 +161,7 @@ module NewRelic
|
|
147
161
|
# active segment like a sql query, memcache key, or Net::HTTP uri
|
148
162
|
#
|
149
163
|
# duration is seconds, float value.
|
150
|
-
def notice_extra_data(message, duration, key)
|
164
|
+
def notice_extra_data(builder, message, duration, key)
|
151
165
|
return unless builder
|
152
166
|
segment = builder.current_segment
|
153
167
|
if segment
|
@@ -182,14 +196,28 @@ module NewRelic
|
|
182
196
|
end
|
183
197
|
end
|
184
198
|
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
|
190
|
-
|
199
|
+
# Attaches an SQL query on the current transaction trace segment.
|
200
|
+
#
|
201
|
+
# This method should be used only by gem authors wishing to extend
|
202
|
+
# the Ruby agent to instrument new database interfaces - it should
|
203
|
+
# generally not be called directly from application code.
|
204
|
+
#
|
205
|
+
# @param sql [String] the SQL query being recorded
|
206
|
+
# @param config [Object] the driver configuration for the connection
|
207
|
+
# @param duration [Float] number of seconds the query took to execute
|
208
|
+
# @param explainer [Proc] for internal use only - 3rd-party clients must
|
209
|
+
# not pass this parameter.
|
210
|
+
#
|
211
|
+
# @api public
|
212
|
+
#
|
213
|
+
def notice_sql(sql, config, duration, state=nil, &explainer) #THREAD_LOCAL_ACCESS sometimes
|
214
|
+
# some statements (particularly INSERTS with large BLOBS
|
215
|
+
# may be very large; we should trim them to a maximum usable length
|
216
|
+
state ||= TransactionState.tl_get
|
217
|
+
builder = state.transaction_sample_builder
|
218
|
+
if state.is_sql_recorded?
|
191
219
|
statement = build_database_statement(sql, config, explainer)
|
192
|
-
notice_extra_data(statement, duration, :sql)
|
220
|
+
notice_extra_data(builder, statement, duration, :sql)
|
193
221
|
end
|
194
222
|
end
|
195
223
|
|
@@ -204,19 +232,34 @@ module NewRelic
|
|
204
232
|
statement
|
205
233
|
end
|
206
234
|
|
207
|
-
#
|
235
|
+
# Attaches an additional non-SQL query parameter to the current
|
236
|
+
# transaction trace segment.
|
208
237
|
#
|
209
|
-
#
|
210
|
-
|
211
|
-
|
238
|
+
# This may be used for recording a query against a key-value store like
|
239
|
+
# memcached or redis.
|
240
|
+
#
|
241
|
+
# This method should be used only by gem authors wishing to extend
|
242
|
+
# the Ruby agent to instrument uninstrumented key-value stores - it should
|
243
|
+
# generally not be called directly from application code.
|
244
|
+
#
|
245
|
+
# @param key [String] the name of the key that was queried
|
246
|
+
# @param duration [Float] number of seconds the query took to execute
|
247
|
+
#
|
248
|
+
# @api public
|
249
|
+
#
|
250
|
+
def notice_nosql(key, duration) #THREAD_LOCAL_ACCESS
|
251
|
+
builder = tl_builder
|
252
|
+
notice_extra_data(builder, key, duration, :key)
|
212
253
|
end
|
213
254
|
|
214
|
-
def notice_nosql_statement(statement, duration)
|
215
|
-
|
255
|
+
def notice_nosql_statement(statement, duration) #THREAD_LOCAL_ACCESS
|
256
|
+
builder = tl_builder
|
257
|
+
notice_extra_data(builder, statement, duration, :statement)
|
216
258
|
end
|
217
259
|
|
218
260
|
# Set parameters on the current segment.
|
219
|
-
def add_segment_parameters(
|
261
|
+
def add_segment_parameters(params) #THREAD_LOCAL_ACCESS
|
262
|
+
builder = tl_builder
|
220
263
|
return unless builder
|
221
264
|
params.each { |k,v| builder.current_segment[k] = v }
|
222
265
|
end
|
@@ -283,25 +326,18 @@ module NewRelic
|
|
283
326
|
# sample builder from the thread local, otherwise it generates a
|
284
327
|
# new transaction sample builder with the stated time as a
|
285
328
|
# starting point and saves it in the thread local variable
|
286
|
-
def start_builder(time=nil)
|
287
|
-
if !enabled? || !
|
288
|
-
|
329
|
+
def start_builder(state, time=nil)
|
330
|
+
if !enabled? || !state.is_transaction_traced? || !state.is_execution_traced?
|
331
|
+
state.transaction_sample_builder = nil
|
289
332
|
else
|
290
|
-
|
333
|
+
state.transaction_sample_builder ||= TransactionSampleBuilder.new(time)
|
291
334
|
end
|
292
335
|
end
|
293
336
|
|
294
337
|
# The current thread-local transaction sample builder
|
295
|
-
def
|
296
|
-
TransactionState.
|
297
|
-
end
|
298
|
-
|
299
|
-
# Sets the thread local variable storing the transaction sample
|
300
|
-
# builder to nil to clear it
|
301
|
-
def clear_builder
|
302
|
-
TransactionState.get.transaction_sample_builder = nil
|
338
|
+
def tl_builder
|
339
|
+
TransactionState.tl_get.transaction_sample_builder
|
303
340
|
end
|
304
|
-
|
305
341
|
end
|
306
342
|
end
|
307
343
|
end
|
@@ -11,34 +11,31 @@ module NewRelic
|
|
11
11
|
# This is THE location to store thread local information during a transaction
|
12
12
|
# Need a new piece of data? Add a method here, NOT a new thread local variable.
|
13
13
|
class TransactionState
|
14
|
-
|
15
|
-
|
16
|
-
state_for(Thread.current)
|
14
|
+
def self.tl_get
|
15
|
+
tl_state_for(Thread.current)
|
17
16
|
end
|
18
17
|
|
19
18
|
# This method should only be used by TransactionState for access to the
|
20
19
|
# current thread's state or to provide read-only accessors for other threads
|
21
20
|
#
|
22
21
|
# If ever exposed, this requires additional synchronization
|
23
|
-
def self.
|
24
|
-
thread[:newrelic_transaction_state]
|
25
|
-
end
|
26
|
-
private_class_method :state_for
|
22
|
+
def self.tl_state_for(thread)
|
23
|
+
state = thread[:newrelic_transaction_state]
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
if state.nil?
|
26
|
+
state = TransactionState.new
|
27
|
+
thread[:newrelic_transaction_state] = state
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
def self.reset
|
34
|
-
self.get.reset
|
30
|
+
state
|
35
31
|
end
|
36
32
|
|
37
|
-
def self.
|
38
|
-
|
33
|
+
def self.tl_clear_for_testing
|
34
|
+
Thread.current[:newrelic_transaction_state] = nil
|
39
35
|
end
|
40
36
|
|
41
37
|
def initialize
|
38
|
+
@untraced = []
|
42
39
|
@traced_method_stack = TracedMethodStack.new
|
43
40
|
@current_transaction = nil
|
44
41
|
end
|
@@ -48,18 +45,27 @@ module NewRelic
|
|
48
45
|
@request_token = BrowserToken.get_token(request)
|
49
46
|
end
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
56
|
-
|
48
|
+
# This starts the timer for the transaction.
|
49
|
+
def reset(transaction=nil)
|
50
|
+
# We purposefully don't reset @untraced, @record_tt and @record_sql
|
51
|
+
# since those are managed by NewRelic::Agent.disable_* calls explicitly
|
52
|
+
# and (more importantly) outside the scope of a transaction
|
53
|
+
|
57
54
|
@timings = nil
|
58
55
|
@request = nil
|
56
|
+
@current_transaction = transaction
|
57
|
+
|
58
|
+
@traced_method_stack.clear
|
59
|
+
|
59
60
|
@request_token = nil
|
60
|
-
@request_ignore_enduser = false
|
61
61
|
@is_cross_app_caller = false
|
62
|
+
@client_cross_app_id = nil
|
62
63
|
@referring_transaction_info = nil
|
64
|
+
|
65
|
+
@transaction_sample_builder = nil
|
66
|
+
@sql_sampler_transaction_data = nil
|
67
|
+
|
68
|
+
@busy_entries = 0
|
63
69
|
end
|
64
70
|
|
65
71
|
def timings
|
@@ -85,11 +91,11 @@ module NewRelic
|
|
85
91
|
|
86
92
|
# Request data
|
87
93
|
attr_reader :request
|
88
|
-
attr_accessor :request_token
|
94
|
+
attr_accessor :request_token
|
89
95
|
|
90
96
|
def request_guid
|
91
|
-
return nil unless
|
92
|
-
|
97
|
+
return nil unless current_transaction
|
98
|
+
current_transaction.guid
|
93
99
|
end
|
94
100
|
|
95
101
|
def request_guid_to_include
|
@@ -98,39 +104,23 @@ module NewRelic
|
|
98
104
|
end
|
99
105
|
|
100
106
|
def include_guid?
|
101
|
-
request_token && timings.app_time_in_seconds >
|
107
|
+
request_token && timings.app_time_in_seconds > current_transaction.apdex_t
|
102
108
|
end
|
103
109
|
|
104
110
|
# Current transaction stack and sample building
|
105
|
-
|
106
|
-
|
111
|
+
attr_reader :current_transaction
|
112
|
+
attr_accessor :transaction_sample_builder
|
107
113
|
|
108
114
|
def transaction_start_time
|
109
|
-
if
|
110
|
-
@last_reset_time
|
111
|
-
else
|
112
|
-
most_recent_transaction.start_time
|
113
|
-
end
|
115
|
+
current_transaction.start_time if current_transaction
|
114
116
|
end
|
115
117
|
|
116
118
|
def transaction_queue_time
|
117
|
-
|
119
|
+
current_transaction.nil? ? 0.0 : current_transaction.queue_time
|
118
120
|
end
|
119
121
|
|
120
122
|
def transaction_name
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
def transaction_noticed_error_ids
|
125
|
-
most_recent_transaction.nil? ? [] : most_recent_transaction.noticed_error_ids
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.in_background_transaction?(thread)
|
129
|
-
state_for(thread).in_background_transaction?
|
130
|
-
end
|
131
|
-
|
132
|
-
def self.in_request_transaction?(thread)
|
133
|
-
state_for(thread).in_request_transaction?
|
123
|
+
current_transaction.nil? ? nil : current_transaction.best_name
|
134
124
|
end
|
135
125
|
|
136
126
|
def in_background_transaction?
|
@@ -145,7 +135,6 @@ module NewRelic
|
|
145
135
|
attr_accessor :untraced
|
146
136
|
|
147
137
|
def push_traced(should_trace)
|
148
|
-
@untraced ||= []
|
149
138
|
@untraced << should_trace
|
150
139
|
end
|
151
140
|
|
@@ -153,7 +142,7 @@ module NewRelic
|
|
153
142
|
@untraced.pop if @untraced
|
154
143
|
end
|
155
144
|
|
156
|
-
def
|
145
|
+
def is_execution_traced?
|
157
146
|
@untraced.nil? || @untraced.last != false
|
158
147
|
end
|
159
148
|
|