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
@@ -26,7 +26,7 @@ DependencyDetection.defer do
|
|
26
26
|
gateway_name = self.name.split('::').last
|
27
27
|
[:authorize, :purchase, :credit, :void, :capture, :recurring, :store, :unstore, :update].each do |operation|
|
28
28
|
if implemented_methods.include?(operation)
|
29
|
-
add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}/#{operation}"
|
29
|
+
add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}/#{operation}"
|
30
30
|
add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}", :push_scope => false
|
31
31
|
add_method_tracer operation, "ActiveMerchant/operation/#{operation}", :push_scope => false
|
32
32
|
end
|
@@ -26,8 +26,10 @@ module NewRelic
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def log_with_newrelic_instrumentation(*args, &block)
|
30
|
-
|
29
|
+
def log_with_newrelic_instrumentation(*args, &block) #THREAD_LOCAL_ACCESS
|
30
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
31
|
+
|
32
|
+
if !state.is_execution_traced?
|
31
33
|
return log_without_newrelic_instrumentation(*args, &block)
|
32
34
|
end
|
33
35
|
|
@@ -49,10 +51,10 @@ module NewRelic
|
|
49
51
|
|
50
52
|
NewRelic::Agent.instance.transaction_sampler.notice_sql(sql,
|
51
53
|
@config, elapsed_time,
|
52
|
-
|
54
|
+
state, &EXPLAINER)
|
53
55
|
NewRelic::Agent.instance.sql_sampler.notice_sql(sql, metric,
|
54
56
|
@config, elapsed_time,
|
55
|
-
|
57
|
+
state, &EXPLAINER)
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -31,8 +31,9 @@ module NewRelic
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def metric_for_sql(sql)
|
35
|
-
|
34
|
+
def metric_for_sql(sql) #THREAD_LOCAL_ACCESS
|
35
|
+
txn = NewRelic::Agent::Transaction.tl_current
|
36
|
+
metric = txn && txn.database_metric_name
|
36
37
|
if metric.nil?
|
37
38
|
operation = NewRelic::Agent::Database.parse_operation_from_query(sql)
|
38
39
|
if operation
|
@@ -11,18 +11,19 @@ module NewRelic
|
|
11
11
|
module Agent
|
12
12
|
module Instrumentation
|
13
13
|
class ActiveRecordSubscriber < EventedSubscriber
|
14
|
-
def start(name, id, payload)
|
15
|
-
return unless NewRelic::Agent.
|
14
|
+
def start(name, id, payload) #THREAD_LOCAL_ACCESS
|
15
|
+
return unless NewRelic::Agent.tl_is_execution_traced?
|
16
16
|
super
|
17
17
|
rescue => e
|
18
18
|
log_notification_error(e, name, 'start')
|
19
19
|
end
|
20
20
|
|
21
|
-
def finish(name, id, payload)
|
22
|
-
|
21
|
+
def finish(name, id, payload) #THREAD_LOCAL_ACCESS
|
22
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
23
|
+
return unless state.is_execution_traced?
|
23
24
|
event = pop_event(id)
|
24
25
|
record_metrics(event)
|
25
|
-
notice_sql(event)
|
26
|
+
notice_sql(state, event)
|
26
27
|
rescue => e
|
27
28
|
log_notification_error(e, name, 'finish')
|
28
29
|
end
|
@@ -37,44 +38,41 @@ module NewRelic
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
def notice_sql(event)
|
41
|
+
def notice_sql(state, event)
|
42
|
+
stack = state.traced_method_stack
|
41
43
|
config = active_record_config_for_event(event)
|
42
44
|
metric = base_metric(event)
|
43
45
|
|
44
46
|
# enter transaction trace segment
|
45
|
-
frame =
|
47
|
+
frame = stack.push_frame(state, :active_record, event.time)
|
46
48
|
|
47
49
|
NewRelic::Agent.instance.transaction_sampler \
|
48
50
|
.notice_sql(event.payload[:sql], config,
|
49
51
|
Helper.milliseconds_to_seconds(event.duration),
|
50
|
-
&method(:get_explain_plan))
|
52
|
+
state, &method(:get_explain_plan))
|
51
53
|
|
52
54
|
NewRelic::Agent.instance.sql_sampler \
|
53
55
|
.notice_sql(event.payload[:sql], metric, config,
|
54
56
|
Helper.milliseconds_to_seconds(event.duration),
|
55
|
-
&method(:get_explain_plan))
|
57
|
+
state, &method(:get_explain_plan))
|
56
58
|
|
57
59
|
# exit transaction trace segment
|
58
|
-
|
60
|
+
stack.pop_frame(state, frame, metric, event.end)
|
59
61
|
end
|
60
62
|
|
61
|
-
def record_metrics(event)
|
63
|
+
def record_metrics(event) #THREAD_LOCAL_ACCESS
|
62
64
|
base = base_metric(event)
|
63
|
-
NewRelic::Agent.instance.stats_engine.record_metrics(base,
|
64
|
-
Helper.milliseconds_to_seconds(event.duration),
|
65
|
-
:scoped => true)
|
66
65
|
|
67
66
|
other_metrics = ActiveRecordHelper.rollup_metrics_for(base)
|
68
|
-
|
69
67
|
if config = active_record_config_for_event(event)
|
70
68
|
other_metrics << ActiveRecordHelper.remote_service_metric(config[:adapter], config[:host])
|
71
69
|
end
|
70
|
+
other_metrics.compact!
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
72
|
+
NewRelic::Agent.instance.stats_engine.tl_record_scoped_and_unscoped_metrics(
|
73
|
+
base, other_metrics,
|
74
|
+
Helper.milliseconds_to_seconds(event.duration)
|
75
|
+
)
|
78
76
|
end
|
79
77
|
|
80
78
|
def base_metric(event)
|
@@ -45,6 +45,11 @@ module NewRelic
|
|
45
45
|
def perform_action_with_newrelic_trace(*args); yield; end
|
46
46
|
end
|
47
47
|
|
48
|
+
NR_DO_NOT_TRACE_KEY = 'do_not_trace'.freeze unless defined?(NR_DO_NOT_TRACE_KEY)
|
49
|
+
NR_IGNORE_APDEX_KEY = 'ignore_apdex'.freeze unless defined?(NR_IGNORE_APDEX_KEY)
|
50
|
+
NR_IGNORE_ENDUSER_KEY = 'ignore_enduser'.freeze unless defined?(NR_IGNORE_ENDUSER_KEY)
|
51
|
+
NR_DEFAULT_OPTIONS = {}.freeze unless defined?(NR_DEFAULT_OPTIONS)
|
52
|
+
|
48
53
|
# @api public
|
49
54
|
module ClassMethods
|
50
55
|
# Have NewRelic ignore actions in this controller. Specify the actions as hash options
|
@@ -53,7 +58,7 @@ module NewRelic
|
|
53
58
|
# @api public
|
54
59
|
#
|
55
60
|
def newrelic_ignore(specifiers={})
|
56
|
-
newrelic_ignore_aspect(
|
61
|
+
newrelic_ignore_aspect(NR_DO_NOT_TRACE_KEY, specifiers)
|
57
62
|
end
|
58
63
|
# Have NewRelic omit apdex measurements on the given actions. Typically used for
|
59
64
|
# actions that are not user facing or that skew your overall apdex measurement.
|
@@ -62,12 +67,12 @@ module NewRelic
|
|
62
67
|
# @api public
|
63
68
|
#
|
64
69
|
def newrelic_ignore_apdex(specifiers={})
|
65
|
-
newrelic_ignore_aspect(
|
70
|
+
newrelic_ignore_aspect(NR_IGNORE_APDEX_KEY, specifiers)
|
66
71
|
end
|
67
72
|
|
68
73
|
# @api public
|
69
74
|
def newrelic_ignore_enduser(specifiers={})
|
70
|
-
newrelic_ignore_aspect(
|
75
|
+
newrelic_ignore_aspect(NR_IGNORE_ENDUSER_KEY, specifiers)
|
71
76
|
end
|
72
77
|
|
73
78
|
def newrelic_ignore_aspect(property, specifiers={}) # :nodoc:
|
@@ -207,52 +212,47 @@ module NewRelic
|
|
207
212
|
end
|
208
213
|
|
209
214
|
class TransactionNamer
|
210
|
-
def self.
|
211
|
-
|
212
|
-
case type
|
213
|
-
when :controller, nil then 'Controller'
|
214
|
-
when :task then 'OtherTransaction/Background'
|
215
|
-
when :rack then 'Controller/Rack'
|
216
|
-
when :uri then 'Controller'
|
217
|
-
when :sinatra then 'Controller/Sinatra'
|
218
|
-
# for internal use only
|
219
|
-
else type.to_s
|
220
|
-
end
|
215
|
+
def self.name(txn, traced_obj, category, options={})
|
216
|
+
"#{prefix_for_category(txn, category)}#{path_name(traced_obj, options)}"
|
221
217
|
end
|
222
218
|
|
223
|
-
def
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
219
|
+
def self.prefix_for_category(txn, category = nil)
|
220
|
+
category ||= (txn && txn.best_category)
|
221
|
+
case category
|
222
|
+
when :controller then ::NewRelic::Agent::Transaction::CONTROLLER_PREFIX
|
223
|
+
when :task then ::NewRelic::Agent::Transaction::TASK_PREFIX
|
224
|
+
when :rack then ::NewRelic::Agent::Transaction::RACK_PREFIX
|
225
|
+
when :uri then ::NewRelic::Agent::Transaction::CONTROLLER_PREFIX
|
226
|
+
when :sinatra then ::NewRelic::Agent::Transaction::SINATRA_PREFIX
|
227
|
+
when :middleware then ::NewRelic::Agent::Transaction::MIDDLEWARE_PREFIX
|
228
|
+
else "#{category.to_s}/" # for internal use only
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
-
def
|
233
|
-
|
234
|
-
end
|
232
|
+
def self.path_name(traced_obj, options={})
|
233
|
+
return options[:path] if options[:path]
|
235
234
|
|
236
|
-
|
237
|
-
# if we have the path, use the path
|
238
|
-
path = options[:path]
|
239
|
-
|
240
|
-
class_name = options[:class_name] || @traced_class_name
|
241
|
-
|
242
|
-
# if we have an explicit action name option, use that
|
235
|
+
class_name = class_name(traced_obj, options)
|
243
236
|
if options[:name]
|
244
|
-
|
237
|
+
if class_name
|
238
|
+
"#{class_name}/#{options[:name]}"
|
239
|
+
else
|
240
|
+
options[:name]
|
241
|
+
end
|
242
|
+
elsif traced_obj.respond_to?(:newrelic_metric_path)
|
243
|
+
traced_obj.newrelic_metric_path
|
244
|
+
else
|
245
|
+
class_name
|
245
246
|
end
|
247
|
+
end
|
246
248
|
|
247
|
-
|
248
|
-
if
|
249
|
-
|
249
|
+
def self.class_name(traced_obj, options={})
|
250
|
+
return options[:class_name] if options[:class_name]
|
251
|
+
if (traced_obj.is_a?(Class) || traced_obj.is_a?(Module))
|
252
|
+
traced_obj.name
|
253
|
+
else
|
254
|
+
traced_obj.class.name
|
250
255
|
end
|
251
|
-
|
252
|
-
# fall back on just the traced class name
|
253
|
-
path ||= class_name
|
254
|
-
|
255
|
-
return path
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
@@ -298,7 +298,7 @@ module NewRelic
|
|
298
298
|
# * <tt>:category => :task</tt> indicates that this is a
|
299
299
|
# background task and will show up in New Relic with other background
|
300
300
|
# tasks instead of in the controllers list
|
301
|
-
# * <tt>:category => :
|
301
|
+
# * <tt>:category => :middleware</tt> if you are instrumenting a rack
|
302
302
|
# middleware call. The <tt>:name</tt> is optional, useful if you
|
303
303
|
# have more than one potential transaction in the #call.
|
304
304
|
# * <tt>:category => :uri</tt> indicates that this is a
|
@@ -323,34 +323,41 @@ module NewRelic
|
|
323
323
|
# * <tt>:request => Rack::Request#new(env)</tt> is used to pass in a
|
324
324
|
# request object that may respond to uri and referer.
|
325
325
|
#
|
326
|
-
# If a single argument is passed in, it is treated as a metric
|
327
|
-
# path. This form is deprecated.
|
328
|
-
#
|
329
326
|
# @api public
|
330
327
|
#
|
331
|
-
def perform_action_with_newrelic_trace(*args, &block)
|
332
|
-
NewRelic::Agent::TransactionState.
|
328
|
+
def perform_action_with_newrelic_trace(*args, &block) #THREAD_LOCAL_ACCESS
|
329
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
330
|
+
state.request = newrelic_request(args)
|
333
331
|
|
334
332
|
# Skip instrumentation based on the value of 'do_not_trace' and if
|
335
333
|
# we aren't calling directly with a block.
|
336
334
|
if !block_given? && do_not_trace?
|
337
|
-
|
335
|
+
state.current_transaction.ignore! if state.current_transaction
|
338
336
|
NewRelic::Agent.disable_all_tracing do
|
339
337
|
return perform_action_without_newrelic_trace(*args)
|
340
338
|
end
|
341
339
|
end
|
342
340
|
|
341
|
+
return yield unless state.is_execution_traced?
|
342
|
+
|
343
343
|
# If a block was passed in, then the arguments represent options for
|
344
344
|
# the instrumentation, not app method arguments.
|
345
|
-
|
346
|
-
|
345
|
+
trace_options = NR_DEFAULT_OPTIONS
|
346
|
+
|
347
|
+
if block_given?
|
348
|
+
trace_options = args.last if args.last.is_a?(Hash)
|
349
|
+
available_params = trace_options[:params]
|
350
|
+
else
|
351
|
+
available_params = respond_to?(:params) && params
|
352
|
+
end
|
347
353
|
|
348
|
-
|
349
|
-
txn_options
|
354
|
+
category = trace_options[:category] || :controller
|
355
|
+
txn_options = create_transaction_options(trace_options, available_params)
|
356
|
+
txn_options[:transaction_name] = TransactionNamer.name(nil, self, category, trace_options)
|
357
|
+
txn_options[:apdex_start_time] = detect_queue_start_time(state)
|
350
358
|
|
351
359
|
begin
|
352
|
-
txn = Transaction.start(
|
353
|
-
_record_queue_length
|
360
|
+
txn = Transaction.start(state, category, txn_options)
|
354
361
|
|
355
362
|
begin
|
356
363
|
if block_given?
|
@@ -364,9 +371,11 @@ module NewRelic
|
|
364
371
|
end
|
365
372
|
|
366
373
|
ensure
|
367
|
-
|
368
|
-
|
369
|
-
|
374
|
+
if txn
|
375
|
+
txn.ignore_apdex! if ignore_apdex?
|
376
|
+
txn.ignore_enduser! if ignore_enduser?
|
377
|
+
end
|
378
|
+
Transaction.stop(state)
|
370
379
|
end
|
371
380
|
end
|
372
381
|
|
@@ -377,10 +386,6 @@ module NewRelic
|
|
377
386
|
# passed as a parameter to add_transaction_tracer
|
378
387
|
if opts.respond_to?(:keys) && opts.respond_to?(:[]) && opts[:request]
|
379
388
|
opts[:request]
|
380
|
-
# in a Rack app
|
381
|
-
elsif opts.respond_to?(:keys) && opts.respond_to?(:[]) &&
|
382
|
-
opts['rack.version']
|
383
|
-
Rack::Request.new(args)
|
384
389
|
# in a Rails app
|
385
390
|
elsif self.respond_to?(:request)
|
386
391
|
self.request
|
@@ -390,8 +395,8 @@ module NewRelic
|
|
390
395
|
# Should be implemented in the dispatcher class
|
391
396
|
def newrelic_response_code; end
|
392
397
|
|
393
|
-
def newrelic_request_headers
|
394
|
-
request =
|
398
|
+
def newrelic_request_headers(state)
|
399
|
+
request = state.request
|
395
400
|
if request
|
396
401
|
if request.respond_to?(:headers)
|
397
402
|
request.headers
|
@@ -405,7 +410,7 @@ module NewRelic
|
|
405
410
|
# or not - you may override this in your controller and supply
|
406
411
|
# your own logic for ignoring transactions.
|
407
412
|
def do_not_trace?
|
408
|
-
_is_filtered?(
|
413
|
+
_is_filtered?(NR_DO_NOT_TRACE_KEY)
|
409
414
|
end
|
410
415
|
|
411
416
|
# overrideable method to determine whether to trace an action
|
@@ -413,29 +418,23 @@ module NewRelic
|
|
413
418
|
# ignore things like api calls or other fast non-user-facing
|
414
419
|
# actions
|
415
420
|
def ignore_apdex?
|
416
|
-
_is_filtered?(
|
421
|
+
_is_filtered?(NR_IGNORE_APDEX_KEY)
|
417
422
|
end
|
418
423
|
|
419
424
|
def ignore_enduser?
|
420
|
-
_is_filtered?(
|
425
|
+
_is_filtered?(NR_IGNORE_ENDUSER_KEY)
|
421
426
|
end
|
422
427
|
|
423
428
|
private
|
424
429
|
|
425
|
-
def create_transaction_options(
|
430
|
+
def create_transaction_options(trace_options, available_params)
|
426
431
|
txn_options = {}
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
available_params = txn_options[:params] || {}
|
432
|
-
txn_options[:name] ||= txn_args.first
|
433
|
-
else
|
434
|
-
available_params = self.respond_to?(:params) ? self.params : {}
|
432
|
+
txn_options[:request] = trace_options[:request] || (respond_to?(:request) && request)
|
433
|
+
|
434
|
+
if available_params
|
435
|
+
txn_options[:filtered_params] = (respond_to?(:filter_parameters)) ? filter_parameters(available_params) : available_params
|
435
436
|
end
|
436
437
|
|
437
|
-
txn_options[:request] ||= self.request if self.respond_to? :request
|
438
|
-
txn_options[:filtered_params] = (respond_to? :filter_parameters) ? filter_parameters(available_params) : available_params
|
439
438
|
txn_options
|
440
439
|
end
|
441
440
|
|
@@ -446,31 +445,18 @@ module NewRelic
|
|
446
445
|
case ignore_actions
|
447
446
|
when nil; false
|
448
447
|
when Hash
|
449
|
-
only_actions
|
448
|
+
only_actions = Array(ignore_actions[:only])
|
450
449
|
except_actions = Array(ignore_actions[:except])
|
451
450
|
only_actions.include?(action_name.to_sym) || (except_actions.any? && !except_actions.include?(action_name.to_sym))
|
452
451
|
else
|
453
452
|
true
|
454
453
|
end
|
455
454
|
end
|
456
|
-
# Take a guess at a measure representing the number of requests waiting in mongrel
|
457
|
-
# or heroku.
|
458
|
-
def _record_queue_length
|
459
|
-
if newrelic_request_headers
|
460
|
-
if queue_depth = newrelic_request_headers['HTTP_X_HEROKU_QUEUE_DEPTH']
|
461
|
-
queue_depth = queue_depth.to_i rescue nil
|
462
|
-
elsif mongrel = NewRelic::Control.instance.local_env.mongrel
|
463
|
-
# Always subtrace 1 for the active mongrel
|
464
|
-
queue_depth = [mongrel.workers.list.length.to_i - 1, 0].max rescue nil
|
465
|
-
end
|
466
|
-
NewRelic::Agent.record_metric('Mongrel/Queue Length', queue_depth) if queue_depth
|
467
|
-
end
|
468
|
-
end
|
469
455
|
|
470
|
-
def detect_queue_start_time
|
471
|
-
|
472
|
-
|
473
|
-
|
456
|
+
def detect_queue_start_time(state)
|
457
|
+
headers = newrelic_request_headers(state)
|
458
|
+
|
459
|
+
QueueTime.parse_frontend_timestamp(headers) if headers
|
474
460
|
end
|
475
461
|
end
|
476
462
|
end
|
@@ -92,9 +92,9 @@ DependencyDetection.defer do
|
|
92
92
|
include NewRelic::Agent::MethodTracer
|
93
93
|
|
94
94
|
# Add CAT with callbacks if the request is serial
|
95
|
-
def add_with_newrelic(
|
96
|
-
if curl.respond_to?(
|
97
|
-
hook_pending_request(
|
95
|
+
def add_with_newrelic(curl) #THREAD_LOCAL_ACCESS
|
96
|
+
if curl.respond_to?(:_nr_serial) && curl._nr_serial
|
97
|
+
hook_pending_request(curl) if NewRelic::Agent.tl_is_execution_traced?
|
98
98
|
end
|
99
99
|
|
100
100
|
return add_without_newrelic( curl )
|
@@ -191,8 +191,9 @@ module NewRelic
|
|
191
191
|
# We rely on the assumption that all possible entry points have been
|
192
192
|
# hooked with tracers, ensuring that notice_sql attaches this SQL to
|
193
193
|
# the proper call scope.
|
194
|
-
def log(msg)
|
195
|
-
|
194
|
+
def log(msg) #THREAD_LOCAL_ACCESS
|
195
|
+
state = NewRelic::Agent::TransactionState.tl_get
|
196
|
+
return unless state.is_execution_traced?
|
196
197
|
return unless operation = case NewRelic::Helper.correctly_encoded(msg.query)
|
197
198
|
when /^\s*select/i then 'find'
|
198
199
|
when /^\s*(update|insert)/i then 'save'
|
@@ -204,13 +205,13 @@ module NewRelic
|
|
204
205
|
duration = msg.duration / 1000000.0
|
205
206
|
|
206
207
|
# Attach SQL to current segment/scope.
|
207
|
-
NewRelic::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration)
|
208
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration, state)
|
208
209
|
|
209
210
|
# Record query duration associated with each of the desired metrics.
|
210
211
|
metric = "ActiveRecord/#{operation}"
|
211
212
|
rollup_metrics = ActiveRecordHelper.rollup_metrics_for(metric)
|
212
213
|
metrics = [metric] + rollup_metrics
|
213
|
-
NewRelic::Agent.instance.stats_engine.
|
214
|
+
NewRelic::Agent.instance.stats_engine.tl_record_unscoped_metrics(metrics, duration)
|
214
215
|
ensure
|
215
216
|
super
|
216
217
|
end
|