sundawg_newrelic_rpm 3.5.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +969 -0
- data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
- data/Gemfile +20 -0
- data/LICENSE +87 -0
- data/README.md +195 -0
- data/Rakefile +58 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/gem-public_cert.pem +20 -0
- data/init.rb +31 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent.rb +488 -0
- data/lib/new_relic/agent/agent.rb +1069 -0
- data/lib/new_relic/agent/agent_logger.rb +173 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +107 -0
- data/lib/new_relic/agent/browser_monitoring.rb +195 -0
- data/lib/new_relic/agent/busy_calculator.rb +112 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/configuration.rb +74 -0
- data/lib/new_relic/agent/configuration/defaults.rb +132 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
- data/lib/new_relic/agent/configuration/manager.rb +148 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +11 -0
- data/lib/new_relic/agent/configuration/server_source.rb +31 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +67 -0
- data/lib/new_relic/agent/cross_app_monitor.rb +239 -0
- data/lib/new_relic/agent/cross_app_tracing.rb +281 -0
- data/lib/new_relic/agent/database.rb +254 -0
- data/lib/new_relic/agent/error_collector.rb +266 -0
- data/lib/new_relic/agent/event_listener.rb +43 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +134 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +51 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +485 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +230 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +356 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +31 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +23 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +68 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +41 -0
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +145 -0
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +45 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +107 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +22 -0
- data/lib/new_relic/agent/method_tracer.rb +530 -0
- data/lib/new_relic/agent/new_relic_service.rb +513 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
- data/lib/new_relic/agent/pipe_service.rb +63 -0
- data/lib/new_relic/agent/rules_engine.rb +72 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +141 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +28 -0
- data/lib/new_relic/agent/sql_sampler.rb +251 -0
- data/lib/new_relic/agent/stats.rb +149 -0
- data/lib/new_relic/agent/stats_engine.rb +30 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +116 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +161 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +97 -0
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +58 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +145 -0
- data/lib/new_relic/agent/thread.rb +32 -0
- data/lib/new_relic/agent/thread_profiler.rb +319 -0
- data/lib/new_relic/agent/transaction_info.rb +119 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +126 -0
- data/lib/new_relic/agent/transaction_sampler.rb +459 -0
- data/lib/new_relic/agent/worker_loop.rb +96 -0
- data/lib/new_relic/coerce.rb +37 -0
- data/lib/new_relic/collection_helper.rb +77 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +114 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +44 -0
- data/lib/new_relic/control/class_methods.rb +58 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +25 -0
- data/lib/new_relic/control/frameworks/rails.rb +173 -0
- data/lib/new_relic/control/frameworks/rails3.rb +71 -0
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +21 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +145 -0
- data/lib/new_relic/control/instrumentation.rb +95 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +80 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/helper.rb +66 -0
- data/lib/new_relic/language_support.rb +92 -0
- data/lib/new_relic/latest_changes.rb +31 -0
- data/lib/new_relic/local_environment.rb +385 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +70 -0
- data/lib/new_relic/metric_spec.rb +80 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +59 -0
- data/lib/new_relic/okjson.rb +599 -0
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/agent_hooks.rb +20 -0
- data/lib/new_relic/rack/browser_monitoring.rb +85 -0
- data/lib/new_relic/rack/developer_mode.rb +271 -0
- data/lib/new_relic/rack/error_collector.rb +66 -0
- data/lib/new_relic/recipes.rb +99 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_sample.rb +272 -0
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +205 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +66 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +17 -0
- data/newrelic.yml +227 -0
- data/newrelic_rpm.gemspec +50 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +49 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +11 -0
- data/test/multiverse/README.md +85 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +164 -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 +9 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +97 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +23 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +56 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +66 -0
- data/test/multiverse/suites/agent_only/logging_test.rb +163 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +96 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/no_dns_resolv.rb +17 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +57 -0
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +81 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +32 -0
- data/test/multiverse/suites/agent_only/ssl_test.rb +22 -0
- data/test/multiverse/suites/agent_only/start_up_test.rb +21 -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/testing_app.rb +17 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +92 -0
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/rails/Envfile +18 -0
- data/test/multiverse/suites/rails/app.rb +49 -0
- data/test/multiverse/suites/rails/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails/app/views/views/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails/app/views/views/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails/app/views/views/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails/app/views/views/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails/app/views/views/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails/app/views/views/index.html.erb +4 -0
- data/test/multiverse/suites/rails/config/newrelic.yml +32 -0
- data/test/multiverse/suites/rails/error_tracing_test.rb +211 -0
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +79 -0
- data/test/multiverse/suites/rails/queue_time_test.rb +55 -0
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +205 -0
- data/test/multiverse/suites/resque/Envfile +24 -0
- data/test/multiverse/suites/resque/Rakefile +8 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +151 -0
- data/test/multiverse/suites/resque/resque_setup.rb +15 -0
- data/test/multiverse/suites/sinatra/Envfile +15 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +38 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +139 -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 +295 -0
- data/test/new_relic/agent/agent/start_test.rb +205 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +88 -0
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +301 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +381 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +107 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +395 -0
- data/test/new_relic/agent/busy_calculator_test.rb +96 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
- data/test/new_relic/agent/configuration/manager_test.rb +232 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +50 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +85 -0
- data/test/new_relic/agent/cross_app_monitor_test.rb +237 -0
- data/test/new_relic/agent/database_test.rb +194 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +268 -0
- data/test/new_relic/agent/error_collector_test.rb +246 -0
- data/test/new_relic/agent/event_listener_test.rb +67 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +606 -0
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +66 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +107 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +151 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +461 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +97 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +182 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +158 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +222 -0
- data/test/new_relic/agent/method_tracer_test.rb +389 -0
- data/test/new_relic/agent/mock_scope_listener.rb +26 -0
- data/test/new_relic/agent/new_relic_service_test.rb +571 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
- data/test/new_relic/agent/pipe_service_test.rb +133 -0
- data/test/new_relic/agent/rpm_agent_test.rb +115 -0
- data/test/new_relic/agent/rules_engine_test.rb +82 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +16 -0
- data/test/new_relic/agent/sql_sampler_test.rb +244 -0
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +85 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +180 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/stats_hash_test.rb +93 -0
- data/test/new_relic/agent/stats_test.rb +197 -0
- data/test/new_relic/agent/thread_profiler_test.rb +582 -0
- data/test/new_relic/agent/thread_test.rb +89 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_info_test.rb +106 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +227 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +968 -0
- data/test/new_relic/agent/worker_loop_test.rb +84 -0
- data/test/new_relic/agent_test.rb +296 -0
- data/test/new_relic/coerce_test.rb +65 -0
- data/test/new_relic/collection_helper_test.rb +148 -0
- data/test/new_relic/command/deployments_test.rb +84 -0
- data/test/new_relic/control/class_methods_test.rb +44 -0
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control_test.rb +194 -0
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +389 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/helper_test.rb +24 -0
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +183 -0
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/noticed_error_test.rb +32 -0
- data/test/new_relic/rack/agent_hooks_test.rb +30 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +152 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +80 -0
- data/test/new_relic/rack/error_collector_test.rb +90 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +415 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +250 -0
- data/test/new_relic/version_number_test.rb +97 -0
- data/test/script/build_test_gem.sh +57 -0
- data/test/script/ci.sh +168 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +30 -0
- data/test/test_helper.rb +240 -0
- data/ui/helpers/developer_mode_helper.rb +367 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/views/layouts/newrelic_default.rhtml +48 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +45 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- metadata +494 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
@name = :resque
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(::Resque::Job) && !NewRelic::Agent.config[:disable_resque] &&
|
6
|
+
!NewRelic::LanguageSupport.using_version?('1.9.1')
|
7
|
+
end
|
8
|
+
|
9
|
+
executes do
|
10
|
+
::NewRelic::Agent.logger.info 'Installing Resque instrumentation'
|
11
|
+
end
|
12
|
+
|
13
|
+
executes do
|
14
|
+
# == Resque Instrumentation
|
15
|
+
#
|
16
|
+
# Installs a hook to ensure the agent starts manually when the worker
|
17
|
+
# starts and also adds the tracer to the process method which executes
|
18
|
+
# in the forked task.
|
19
|
+
|
20
|
+
module Resque
|
21
|
+
module Plugins
|
22
|
+
module NewRelicInstrumentation
|
23
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
24
|
+
|
25
|
+
def around_perform_with_monitoring(*args)
|
26
|
+
begin
|
27
|
+
perform_action_with_newrelic_trace(:name => 'perform',
|
28
|
+
:class_name => self.name,
|
29
|
+
:category => 'OtherTransaction/ResqueJob') do
|
30
|
+
yield(*args)
|
31
|
+
end
|
32
|
+
ensure
|
33
|
+
NewRelic::Agent.shutdown if NewRelic::LanguageSupport.can_fork?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module NewRelic
|
41
|
+
module Agent
|
42
|
+
module Instrumentation
|
43
|
+
module ResqueInstrumentationInstaller
|
44
|
+
def payload_class
|
45
|
+
klass = super
|
46
|
+
klass.instance_eval do
|
47
|
+
extend ::Resque::Plugins::NewRelicInstrumentation
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
::Resque::Job.class_eval do
|
56
|
+
def self.new(*args)
|
57
|
+
super(*args).extend NewRelic::Agent::Instrumentation::ResqueInstrumentationInstaller
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if NewRelic::LanguageSupport.can_fork?
|
62
|
+
::Resque.before_first_fork do
|
63
|
+
NewRelic::Agent.manual_start(:dispatcher => :resque,
|
64
|
+
:sync_startup => true,
|
65
|
+
:start_channel_listener => true,
|
66
|
+
:report_instance_busy => false)
|
67
|
+
end
|
68
|
+
|
69
|
+
::Resque.before_fork do |job|
|
70
|
+
NewRelic::Agent.register_report_channel(job.object_id)
|
71
|
+
end
|
72
|
+
|
73
|
+
::Resque.after_fork do |job|
|
74
|
+
NewRelic::Agent.after_fork(:report_to_channel => job.object_id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# call this now so it is memoized before potentially forking worker processes
|
81
|
+
NewRelic::LanguageSupport.can_fork?
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
2
|
+
|
3
|
+
DependencyDetection.defer do
|
4
|
+
@name = :sinatra
|
5
|
+
|
6
|
+
depends_on do
|
7
|
+
defined?(::Sinatra) && defined?(::Sinatra::Base) &&
|
8
|
+
Sinatra::Base.private_method_defined?(:dispatch!) &&
|
9
|
+
Sinatra::Base.private_method_defined?(:process_route)
|
10
|
+
end
|
11
|
+
|
12
|
+
executes do
|
13
|
+
::NewRelic::Agent.logger.info 'Installing Sinatra instrumentation'
|
14
|
+
end
|
15
|
+
|
16
|
+
executes do
|
17
|
+
::Sinatra::Base.class_eval do
|
18
|
+
include NewRelic::Agent::Instrumentation::Sinatra
|
19
|
+
alias dispatch_without_newrelic dispatch!
|
20
|
+
alias dispatch! dispatch_with_newrelic
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
module NewRelic
|
27
|
+
module Agent
|
28
|
+
module Instrumentation
|
29
|
+
# NewRelic instrumentation for Sinatra applications. Sinatra actions will
|
30
|
+
# appear in the UI similar to controller actions, and have breakdown charts
|
31
|
+
# and transaction traces.
|
32
|
+
#
|
33
|
+
# The actions in the UI will correspond to the pattern expression used
|
34
|
+
# to match them. HTTP operations are not distinguished. Multiple matches
|
35
|
+
# will all be tracked as separate actions.
|
36
|
+
module Sinatra
|
37
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
38
|
+
|
39
|
+
def dispatch_with_newrelic
|
40
|
+
# We're trying to determine the transaction name via Sinatra's
|
41
|
+
# process_route, but calling it here misses Sinatra's normal error handling.
|
42
|
+
#
|
43
|
+
# Relies on transaction_name to always safely return a value for us
|
44
|
+
txn_name = NewRelic.transaction_name(self.class.routes, @request) do |pattern, keys, conditions|
|
45
|
+
result = process_route(pattern, keys, conditions) do
|
46
|
+
pattern.source
|
47
|
+
end
|
48
|
+
result if result.class == String
|
49
|
+
end
|
50
|
+
|
51
|
+
perform_action_with_newrelic_trace(:category => :sinatra,
|
52
|
+
:name => txn_name,
|
53
|
+
:params => @request.params) do
|
54
|
+
dispatch_and_notice_errors_with_newrelic
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def dispatch_and_notice_errors_with_newrelic
|
59
|
+
dispatch_without_newrelic
|
60
|
+
ensure
|
61
|
+
# Will only see an error raised if :show_exceptions is true, but
|
62
|
+
# will always see them in the env hash if they occur
|
63
|
+
had_error = env.has_key?('sinatra.error')
|
64
|
+
::NewRelic::Agent.notice_error(env['sinatra.error']) if had_error
|
65
|
+
end
|
66
|
+
|
67
|
+
# Define Request Header accessor for Sinatra
|
68
|
+
def newrelic_request_headers
|
69
|
+
request.env
|
70
|
+
end
|
71
|
+
|
72
|
+
module NewRelic
|
73
|
+
extend self
|
74
|
+
|
75
|
+
def http_verb(request)
|
76
|
+
request.request_method if request.respond_to?(:request_method)
|
77
|
+
end
|
78
|
+
|
79
|
+
def transaction_name(routes, request)
|
80
|
+
name = '(unknown)'
|
81
|
+
verb = http_verb(request)
|
82
|
+
|
83
|
+
Array(routes[verb]).each do |pattern, keys, conditions, block|
|
84
|
+
if route = yield(pattern, keys, conditions)
|
85
|
+
name = route
|
86
|
+
# it's important we short circuit here. Otherwise we risk
|
87
|
+
# applying conditions from lower priority routes which can
|
88
|
+
# break the action.
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1')
|
94
|
+
if verb
|
95
|
+
name = verb + ' ' + name
|
96
|
+
end
|
97
|
+
|
98
|
+
name
|
99
|
+
rescue => e
|
100
|
+
::NewRelic::Agent.logger.debug("#{e.class} : #{e.message} - Error encountered trying to identify Sinatra transaction name")
|
101
|
+
'(unknown)'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
@name = :sunspot
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(::Sunspot)
|
6
|
+
end
|
7
|
+
|
8
|
+
executes do
|
9
|
+
::NewRelic::Agent.logger.info 'Installing Rails Sunspot instrumentation'
|
10
|
+
end
|
11
|
+
|
12
|
+
executes do
|
13
|
+
::Sunspot.module_eval do
|
14
|
+
class << self
|
15
|
+
%w(index index!).each do |method|
|
16
|
+
add_method_tracer method, 'SolrClient/Sunspot/index'
|
17
|
+
end
|
18
|
+
add_method_tracer :commit, 'SolrClient/Sunspot/commit'
|
19
|
+
|
20
|
+
%w[search more_like_this].each do |method|
|
21
|
+
add_method_tracer method, 'SolrClient/Sunspot/query'
|
22
|
+
end
|
23
|
+
%w[remove remove! remove_by_id remove_by_id! remove_all remove_all!].each do |method|
|
24
|
+
add_method_tracer method, 'SolrClient/Sunspot/delete'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
@name = :unicorn
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(::Unicorn) && defined?(::Unicorn::HttpServer)
|
6
|
+
end
|
7
|
+
|
8
|
+
executes do
|
9
|
+
::NewRelic::Agent.logger.info 'Installing Unicorn instrumentation'
|
10
|
+
::NewRelic::Agent.logger.info 'Detected Unicorn, please see additional documentation: https://newrelic.com/docs/troubleshooting/im-using-unicorn-and-i-dont-see-any-data'
|
11
|
+
end
|
12
|
+
|
13
|
+
executes do
|
14
|
+
Unicorn::HttpServer.class_eval do
|
15
|
+
old_worker_loop = instance_method(:worker_loop)
|
16
|
+
define_method(:worker_loop) do |worker|
|
17
|
+
NewRelic::Agent.after_fork(:force_reconnect => true)
|
18
|
+
old_worker_loop.bind(self).call(worker)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,530 @@
|
|
1
|
+
require 'new_relic/control'
|
2
|
+
module NewRelic
|
3
|
+
module Agent
|
4
|
+
# This module contains class methods added to support installing custom
|
5
|
+
# metric tracers and executing for individual metrics.
|
6
|
+
#
|
7
|
+
# == Examples
|
8
|
+
#
|
9
|
+
# When the agent initializes, it extends Module with these methods.
|
10
|
+
# However if you want to use the API in code that might get loaded
|
11
|
+
# before the agent is initialized you will need to require
|
12
|
+
# this file:
|
13
|
+
#
|
14
|
+
# require 'new_relic/agent/method_tracer'
|
15
|
+
# class A
|
16
|
+
# include NewRelic::Agent::MethodTracer
|
17
|
+
# def process
|
18
|
+
# ...
|
19
|
+
# end
|
20
|
+
# add_method_tracer :process
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# To instrument a class method:
|
24
|
+
#
|
25
|
+
# require 'new_relic/agent/method_tracer'
|
26
|
+
# class An
|
27
|
+
# def self.process
|
28
|
+
# ...
|
29
|
+
# end
|
30
|
+
# class << self
|
31
|
+
# include NewRelic::Agent::MethodTracer
|
32
|
+
# add_method_tracer :process
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
module MethodTracer
|
37
|
+
|
38
|
+
def self.included clazz #:nodoc:
|
39
|
+
clazz.extend ClassMethods
|
40
|
+
clazz.send :include, InstanceMethods
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.extended clazz #:nodoc:
|
44
|
+
clazz.extend ClassMethods
|
45
|
+
clazz.extend InstanceMethods
|
46
|
+
end
|
47
|
+
|
48
|
+
# Defines modules used at instrumentation runtime, to do the
|
49
|
+
# actual tracing of time spent
|
50
|
+
module InstanceMethods
|
51
|
+
# Deprecated: original method preserved for API backward compatibility.
|
52
|
+
# Use either #trace_execution_scoped or #trace_execution_unscoped
|
53
|
+
def trace_method_execution(metric_names, push_scope, produce_metric, deduct_call_time_from_parent, &block) #:nodoc:
|
54
|
+
if push_scope
|
55
|
+
trace_execution_scoped(metric_names, :metric => produce_metric,
|
56
|
+
:deduct_call_time_from_parent => deduct_call_time_from_parent, &block)
|
57
|
+
else
|
58
|
+
trace_execution_unscoped(metric_names, &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Trace a given block with stats assigned to the given metric_name. It does not
|
63
|
+
# provide scoped measurements, meaning whatever is being traced will not 'blame the
|
64
|
+
# Controller'--that is to say appear in the breakdown chart.
|
65
|
+
# This is code is inlined in #add_method_tracer.
|
66
|
+
# * <tt>metric_names</tt> is a single name or an array of names of metrics
|
67
|
+
# * <tt>:force => true</tt> will force the metric to be captured even when
|
68
|
+
# tracing is disabled with NewRelic::Agent#disable_all_tracing
|
69
|
+
#
|
70
|
+
def trace_execution_unscoped(metric_names, options={})
|
71
|
+
return yield unless NewRelic::Agent.is_execution_traced?
|
72
|
+
t0 = Time.now
|
73
|
+
stats = Array(metric_names).map do | metric_name |
|
74
|
+
NewRelic::Agent.instance.stats_engine.get_stats_no_scope metric_name
|
75
|
+
end
|
76
|
+
begin
|
77
|
+
NewRelic::Agent.instance.push_trace_execution_flag(true) if options[:force]
|
78
|
+
yield
|
79
|
+
ensure
|
80
|
+
NewRelic::Agent.instance.pop_trace_execution_flag if options[:force]
|
81
|
+
duration = (Time.now - t0).to_f # for some reason this is 3 usec faster than Time - Time
|
82
|
+
stats.each { |stat| stat.trace_call(duration) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Deprecated. Use #trace_execution_scoped, a version with an options hash.
|
87
|
+
def trace_method_execution_with_scope(metric_names, produce_metric, deduct_call_time_from_parent, scoped_metric_only=false, &block) #:nodoc:
|
88
|
+
trace_execution_scoped(metric_names,
|
89
|
+
:metric => produce_metric,
|
90
|
+
:deduct_call_time_from_parent => deduct_call_time_from_parent,
|
91
|
+
:scoped_metric_only => scoped_metric_only, &block)
|
92
|
+
end
|
93
|
+
|
94
|
+
alias trace_method_execution_no_scope trace_execution_unscoped #:nodoc:
|
95
|
+
|
96
|
+
# Refactored out of the previous trace_execution_scoped
|
97
|
+
# method, most methods in this module relate to code used in
|
98
|
+
# the #trace_execution_scoped method in this module
|
99
|
+
module TraceExecutionScoped
|
100
|
+
# Shorthand to return the NewRelic::Agent.instance
|
101
|
+
def agent_instance
|
102
|
+
NewRelic::Agent.instance
|
103
|
+
end
|
104
|
+
|
105
|
+
# Shorthand to return the status of tracing
|
106
|
+
def traced?
|
107
|
+
NewRelic::Agent.is_execution_traced?
|
108
|
+
end
|
109
|
+
|
110
|
+
# Tracing is disabled if we are not in a traced context and
|
111
|
+
# no force option is supplied
|
112
|
+
def trace_disabled?(options)
|
113
|
+
!(traced? || options[:force])
|
114
|
+
end
|
115
|
+
|
116
|
+
# Shorthand to return the current statistics engine
|
117
|
+
def stat_engine
|
118
|
+
agent_instance.stats_engine
|
119
|
+
end
|
120
|
+
|
121
|
+
# returns a scoped metric stat for the specified name
|
122
|
+
def get_stats_scoped(first_name, scoped_metric_only)
|
123
|
+
stat_engine.get_stats(first_name, true, scoped_metric_only)
|
124
|
+
end
|
125
|
+
# Shorthand method to get stats from the stat engine
|
126
|
+
def get_stats_unscoped(name)
|
127
|
+
stat_engine.get_stats_no_scope(name)
|
128
|
+
end
|
129
|
+
|
130
|
+
# the main statistic we should record in
|
131
|
+
# #trace_execution_scoped - a scoped metric provided by the
|
132
|
+
# first item in the metric array
|
133
|
+
def main_stat(metric, options)
|
134
|
+
get_stats_scoped(metric, options[:scoped_metric_only])
|
135
|
+
end
|
136
|
+
|
137
|
+
# returns an array containing the first metric, and an array
|
138
|
+
# of other unscoped statistics we should also record along
|
139
|
+
# side it
|
140
|
+
def get_metric_stats(metrics, options)
|
141
|
+
metrics = Array(metrics)
|
142
|
+
first_name = metrics.shift
|
143
|
+
stats = metrics.map do | name |
|
144
|
+
get_stats_unscoped(name)
|
145
|
+
end
|
146
|
+
stats.unshift(main_stat(first_name, options)) if options[:metric]
|
147
|
+
[first_name, stats]
|
148
|
+
end
|
149
|
+
|
150
|
+
# Helper for setting a hash key if the hash key is nil,
|
151
|
+
# instead of the default ||= behavior which sets if it is
|
152
|
+
# false as well
|
153
|
+
def set_if_nil(hash, key)
|
154
|
+
hash[key] = true if hash[key].nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
# delegates to #agent_instance to push a trace execution
|
158
|
+
# flag, only if execution of this metric is forced.
|
159
|
+
#
|
160
|
+
# This causes everything scoped inside this metric to be
|
161
|
+
# recorded, even if the parent transaction is generally not.
|
162
|
+
def push_flag!(forced)
|
163
|
+
agent_instance.push_trace_execution_flag(true) if forced
|
164
|
+
end
|
165
|
+
|
166
|
+
# delegates to #agent_instance to pop the trace execution
|
167
|
+
# flag, only if execution of this metric is
|
168
|
+
# forced. otherwise this is taken care of for us
|
169
|
+
# automatically.
|
170
|
+
#
|
171
|
+
# This ends the forced recording of metrics within the
|
172
|
+
# #trace_execution_scoped block
|
173
|
+
def pop_flag!(forced)
|
174
|
+
agent_instance.pop_trace_execution_flag if forced
|
175
|
+
end
|
176
|
+
|
177
|
+
# helper for logging errors to the newrelic_agent.log
|
178
|
+
# properly. Logs the error at error level
|
179
|
+
def log_errors(code_area, metric)
|
180
|
+
yield
|
181
|
+
rescue => e
|
182
|
+
::NewRelic::Agent.logger.error("Caught exception in #{code_area}. Metric name = #{metric}", e)
|
183
|
+
end
|
184
|
+
|
185
|
+
# provides the header for our traced execution scoped
|
186
|
+
# method - gets the initial time, sets the tracing flag if
|
187
|
+
# needed, and pushes the scope onto the metric stack
|
188
|
+
# logs any errors that occur and returns the start time and
|
189
|
+
# the scope so that we can check for it later, to maintain
|
190
|
+
# sanity. If the scope stack becomes unbalanced, this
|
191
|
+
# transaction loses meaning.
|
192
|
+
def trace_execution_scoped_header(metric, options, t0=Time.now.to_f)
|
193
|
+
scope = log_errors("trace_execution_scoped header", metric) do
|
194
|
+
push_flag!(options[:force])
|
195
|
+
scope = stat_engine.push_scope(metric, t0, options[:deduct_call_time_from_parent])
|
196
|
+
end
|
197
|
+
# needed in case we have an error, above, to always return
|
198
|
+
# the start time.
|
199
|
+
[t0, scope]
|
200
|
+
end
|
201
|
+
|
202
|
+
# Handles the end of the #trace_execution_scoped method -
|
203
|
+
# calculating the time taken, popping the tracing flag if
|
204
|
+
# needed, deducting time taken by children, and tracing the
|
205
|
+
# subsidiary unscoped metrics if any
|
206
|
+
#
|
207
|
+
# this method fails safely if the header does not manage to
|
208
|
+
# push the scope onto the stack - it simply does not trace
|
209
|
+
# any metrics.
|
210
|
+
def trace_execution_scoped_footer(t0, first_name, metric_stats, expected_scope, forced, t1=Time.now.to_f)
|
211
|
+
log_errors("trace_method_execution footer", first_name) do
|
212
|
+
duration = t1 - t0
|
213
|
+
|
214
|
+
pop_flag!(forced)
|
215
|
+
if expected_scope
|
216
|
+
scope = stat_engine.pop_scope(expected_scope, duration, t1)
|
217
|
+
exclusive = duration - scope.children_time
|
218
|
+
metric_stats.each { |stats| stats.trace_call(duration, exclusive) }
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Trace a given block with stats and keep track of the caller.
|
224
|
+
# See NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer for a description of the arguments.
|
225
|
+
# +metric_names+ is either a single name or an array of metric names.
|
226
|
+
# If more than one metric is passed, the +produce_metric+ option only applies to the first. The
|
227
|
+
# others are always recorded. Only the first metric is pushed onto the scope stack.
|
228
|
+
#
|
229
|
+
# Generally you pass an array of metric names if you want to record the metric under additional
|
230
|
+
# categories, but generally this *should never ever be done*. Most of the time you can aggregate
|
231
|
+
# on the server.
|
232
|
+
|
233
|
+
def trace_execution_scoped(metric_names, options={})
|
234
|
+
return yield if trace_disabled?(options)
|
235
|
+
set_if_nil(options, :metric)
|
236
|
+
set_if_nil(options, :deduct_call_time_from_parent)
|
237
|
+
first_name, metric_stats = get_metric_stats(metric_names, options)
|
238
|
+
start_time, expected_scope = trace_execution_scoped_header(first_name, options)
|
239
|
+
begin
|
240
|
+
yield
|
241
|
+
ensure
|
242
|
+
trace_execution_scoped_footer(start_time, first_name, metric_stats, expected_scope, options[:force])
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
include TraceExecutionScoped
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
# Defines methods used at the class level, for adding instrumentation
|
252
|
+
module ClassMethods
|
253
|
+
# contains methods refactored out of the #add_method_tracer method
|
254
|
+
module AddMethodTracer
|
255
|
+
ALLOWED_KEYS = [:force, :metric, :push_scope, :deduct_call_time_from_parent, :code_header, :code_footer, :scoped_metric_only].freeze
|
256
|
+
|
257
|
+
# used to verify that the keys passed to
|
258
|
+
# NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer
|
259
|
+
# are valid. Returns a list of keys that were unexpected
|
260
|
+
def unrecognized_keys(expected, given)
|
261
|
+
given.keys - expected
|
262
|
+
end
|
263
|
+
|
264
|
+
# used to verify that the keys passed to
|
265
|
+
# NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer
|
266
|
+
# are valid. checks the expected list against the list
|
267
|
+
# actually provided
|
268
|
+
def any_unrecognized_keys?(expected, given)
|
269
|
+
unrecognized_keys(expected, given).any?
|
270
|
+
end
|
271
|
+
|
272
|
+
# raises an error when the
|
273
|
+
# NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer
|
274
|
+
# method is called with improper keys. This aids in
|
275
|
+
# debugging new instrumentation by failing fast
|
276
|
+
def check_for_illegal_keys!(options)
|
277
|
+
if any_unrecognized_keys?(ALLOWED_KEYS, options)
|
278
|
+
raise "Unrecognized options in add_method_tracer_call: #{unrecognized_keys(ALLOWED_KEYS, options).join(', ')}"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# Sets the options for deducting call time from
|
283
|
+
# parents. This defaults to true if we are recording a metric, but
|
284
|
+
# can be overridden by the user if desired.
|
285
|
+
#
|
286
|
+
# has the effect of not allowing overlapping times, and
|
287
|
+
# should generally be true
|
288
|
+
def set_deduct_call_time_based_on_metric(options)
|
289
|
+
{:deduct_call_time_from_parent => !!options[:metric]}.merge(options)
|
290
|
+
end
|
291
|
+
|
292
|
+
# validity checking - add_method_tracer must receive either
|
293
|
+
# push scope or metric, or else it would record no
|
294
|
+
# data. Raises an error if this is the case
|
295
|
+
def check_for_push_scope_and_metric(options)
|
296
|
+
unless options[:push_scope] || options[:metric]
|
297
|
+
raise "Can't add a tracer where push_scope is false and metric is false"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :force => false, :code_header => "", :code_footer => "", :scoped_metric_only => false}.freeze
|
302
|
+
|
303
|
+
# Checks the provided options to make sure that they make
|
304
|
+
# sense. Raises an error if the options are incorrect to
|
305
|
+
# assist with debugging, so that errors occur at class
|
306
|
+
# construction time rather than instrumentation run time
|
307
|
+
def validate_options(options)
|
308
|
+
raise TypeError.new("provided options must be a Hash") unless options.is_a?(Hash)
|
309
|
+
check_for_illegal_keys!(options)
|
310
|
+
options = set_deduct_call_time_based_on_metric(DEFAULT_SETTINGS.merge(options))
|
311
|
+
check_for_push_scope_and_metric(options)
|
312
|
+
options
|
313
|
+
end
|
314
|
+
|
315
|
+
# Default to the class where the method is defined.
|
316
|
+
#
|
317
|
+
# Example:
|
318
|
+
# Foo.default_metric_name_code('bar') #=> "Custom/#{Foo.name}/bar"
|
319
|
+
def default_metric_name_code(method_name)
|
320
|
+
"Custom/#{self.name}/#{method_name.to_s}"
|
321
|
+
end
|
322
|
+
|
323
|
+
# Checks to see if the method we are attempting to trace
|
324
|
+
# actually exists or not. #add_method_tracer can't do
|
325
|
+
# anything if the method doesn't exist.
|
326
|
+
def newrelic_method_exists?(method_name)
|
327
|
+
exists = method_defined?(method_name) || private_method_defined?(method_name)
|
328
|
+
::NewRelic::Agent.logger.error("Did not trace #{self.name}##{method_name} because that method does not exist") unless exists
|
329
|
+
exists
|
330
|
+
end
|
331
|
+
|
332
|
+
# Checks to see if we have already traced a method with a
|
333
|
+
# given metric by checking to see if the traced method
|
334
|
+
# exists. Warns the user if methods are being double-traced
|
335
|
+
# to help with debugging custom instrumentation.
|
336
|
+
def traced_method_exists?(method_name, metric_name_code)
|
337
|
+
exists = method_defined?(_traced_method_name(method_name, metric_name_code))
|
338
|
+
::NewRelic::Agent.logger.error("Attempt to trace a method twice with the same metric: Method = #{method_name}, Metric Name = #{metric_name_code}") if exists
|
339
|
+
exists
|
340
|
+
end
|
341
|
+
|
342
|
+
# Returns a code snippet to be eval'd that skips tracing
|
343
|
+
# when the agent is not tracing execution. turns
|
344
|
+
# instrumentation into effectively one method call overhead
|
345
|
+
# when the agent is disabled
|
346
|
+
def assemble_code_header(method_name, metric_name_code, options)
|
347
|
+
unless options[:force]
|
348
|
+
"return #{_untraced_method_name(method_name, metric_name_code)}(*args, &block) unless NewRelic::Agent.is_execution_traced?\n"
|
349
|
+
end.to_s + options[:code_header].to_s
|
350
|
+
end
|
351
|
+
|
352
|
+
# returns an eval-able string that contains the traced
|
353
|
+
# method code used if the agent is not creating a scope for
|
354
|
+
# use in scoped metrics.
|
355
|
+
def method_without_push_scope(method_name, metric_name_code, options)
|
356
|
+
"def #{_traced_method_name(method_name, metric_name_code)}(*args, &block)
|
357
|
+
#{assemble_code_header(method_name, metric_name_code, options)}
|
358
|
+
t0 = Time.now
|
359
|
+
stats = NewRelic::Agent.instance.stats_engine.get_stats_no_scope \"#{metric_name_code}\"
|
360
|
+
begin
|
361
|
+
#{"NewRelic::Agent.instance.push_trace_execution_flag(true)\n" if options[:force]}
|
362
|
+
#{_untraced_method_name(method_name, metric_name_code)}(*args, &block)\n
|
363
|
+
ensure
|
364
|
+
#{"NewRelic::Agent.instance.pop_trace_execution_flag\n" if options[:force] }
|
365
|
+
duration = (Time.now - t0).to_f
|
366
|
+
stats.trace_call(duration)
|
367
|
+
#{options[:code_footer]}
|
368
|
+
end
|
369
|
+
end"
|
370
|
+
end
|
371
|
+
|
372
|
+
# returns an eval-able string that contains the tracing code
|
373
|
+
# for a fully traced metric including scoping
|
374
|
+
def method_with_push_scope(method_name, metric_name_code, options)
|
375
|
+
klass = (self === Module) ? "self" : "self.class"
|
376
|
+
|
377
|
+
"def #{_traced_method_name(method_name, metric_name_code)}(*args, &block)
|
378
|
+
#{options[:code_header]}
|
379
|
+
result = #{klass}.trace_execution_scoped(\"#{metric_name_code}\",
|
380
|
+
:metric => #{options[:metric]},
|
381
|
+
:forced => #{options[:force]},
|
382
|
+
:deduct_call_time_from_parent => #{options[:deduct_call_time_from_parent]},
|
383
|
+
:scoped_metric_only => #{options[:scoped_metric_only]}) do
|
384
|
+
#{_untraced_method_name(method_name, metric_name_code)}(*args, &block)
|
385
|
+
end
|
386
|
+
#{options[:code_footer]}
|
387
|
+
result
|
388
|
+
end"
|
389
|
+
end
|
390
|
+
|
391
|
+
# Decides which code snippet we should be eval'ing in this
|
392
|
+
# context, based on the options.
|
393
|
+
def code_to_eval(method_name, metric_name_code, options)
|
394
|
+
options = validate_options(options)
|
395
|
+
if options[:push_scope]
|
396
|
+
method_with_push_scope(method_name, metric_name_code, options)
|
397
|
+
else
|
398
|
+
method_without_push_scope(method_name, metric_name_code, options)
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
include AddMethodTracer
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
# Add a method tracer to the specified method.
|
407
|
+
#
|
408
|
+
# === Common Options
|
409
|
+
#
|
410
|
+
# * <tt>:push_scope => false</tt> specifies this method tracer should not
|
411
|
+
# keep track of the caller; it will not show up in controller breakdown
|
412
|
+
# pie charts.
|
413
|
+
# * <tt>:metric => false</tt> specifies that no metric will be recorded.
|
414
|
+
# Instead the call will show up in transaction traces as well as traces
|
415
|
+
# shown in Developer Mode.
|
416
|
+
#
|
417
|
+
# === Uncommon Options
|
418
|
+
#
|
419
|
+
# * <tt>:scoped_metric_only => true</tt> indicates that the unscoped metric
|
420
|
+
# should not be recorded. Normally two metrics are potentially created
|
421
|
+
# on every invocation: the aggregate method where statistics for all calls
|
422
|
+
# of that metric are stored, and the "scoped metric" which records the
|
423
|
+
# statistics for invocations in a particular scope--generally a controller
|
424
|
+
# action. This option indicates that only the second type should be recorded.
|
425
|
+
# The effect is similar to <tt>:metric => false</tt> but in addition you
|
426
|
+
# will also see the invocation in breakdown pie charts.
|
427
|
+
# * <tt>:deduct_call_time_from_parent => false</tt> indicates that the method invocation
|
428
|
+
# time should never be deducted from the time reported as 'exclusive' in the
|
429
|
+
# caller. You would want to use this if you are tracing a recursive method
|
430
|
+
# or a method that might be called inside another traced method.
|
431
|
+
# * <tt>:code_header</tt> and <tt>:code_footer</tt> specify ruby code that
|
432
|
+
# is inserted into the tracer before and after the call.
|
433
|
+
# * <tt>:force = true</tt> will ensure the metric is captured even if called inside
|
434
|
+
# an untraced execution call. (See NewRelic::Agent#disable_all_tracing)
|
435
|
+
#
|
436
|
+
# === Overriding the metric name
|
437
|
+
#
|
438
|
+
# +metric_name_code+ is a string that is eval'd to get the
|
439
|
+
# name of the metric associated with the call, so if you want to
|
440
|
+
# use interpolaion evaluated at call time, then single quote
|
441
|
+
# the value like this:
|
442
|
+
#
|
443
|
+
# add_method_tracer :foo, 'Custom/#{self.class.name}/foo'
|
444
|
+
#
|
445
|
+
# This would name the metric according to the class of the runtime
|
446
|
+
# intance, as opposed to the class where +foo+ is defined.
|
447
|
+
#
|
448
|
+
# If not provided, the metric name will be <tt>Custom/ClassName/method_name</tt>.
|
449
|
+
#
|
450
|
+
# === Examples
|
451
|
+
#
|
452
|
+
# Instrument +foo+ only for custom views--will not show up in transaction traces or caller breakdown graphs:
|
453
|
+
#
|
454
|
+
# add_method_tracer :foo, :push_scope => false
|
455
|
+
#
|
456
|
+
# Instrument +foo+ just for transaction traces only:
|
457
|
+
#
|
458
|
+
# add_method_tracer :foo, :metric => false
|
459
|
+
#
|
460
|
+
# Instrument +foo+ so it shows up in transaction traces and caller breakdown graphs
|
461
|
+
# for actions:
|
462
|
+
#
|
463
|
+
# add_method_tracer :foo
|
464
|
+
#
|
465
|
+
# which is equivalent to:
|
466
|
+
#
|
467
|
+
# add_method_tracer :foo, 'Custom/#{self.class.name}/foo', :push_scope => true, :metric => true
|
468
|
+
#
|
469
|
+
# Instrument the class method +foo+ with the metric name 'Custom/People/fetch':
|
470
|
+
#
|
471
|
+
# class << self
|
472
|
+
# add_method_tracer :foo, 'Custom/People/fetch'
|
473
|
+
# end
|
474
|
+
#
|
475
|
+
def add_method_tracer(method_name, metric_name_code=nil, options = {})
|
476
|
+
return unless newrelic_method_exists?(method_name)
|
477
|
+
metric_name_code ||= default_metric_name_code(method_name)
|
478
|
+
return if traced_method_exists?(method_name, metric_name_code)
|
479
|
+
|
480
|
+
traced_method = code_to_eval(method_name, metric_name_code, options)
|
481
|
+
|
482
|
+
visibility = NewRelic::Helper.instance_method_visibility self, method_name
|
483
|
+
|
484
|
+
class_eval traced_method, __FILE__, __LINE__
|
485
|
+
alias_method _untraced_method_name(method_name, metric_name_code), method_name
|
486
|
+
alias_method method_name, _traced_method_name(method_name, metric_name_code)
|
487
|
+
send visibility, method_name
|
488
|
+
send visibility, _traced_method_name(method_name, metric_name_code)
|
489
|
+
::NewRelic::Agent.logger.debug("Traced method: class = #{self.name},"+
|
490
|
+
"method = #{method_name}, "+
|
491
|
+
"metric = '#{metric_name_code}'")
|
492
|
+
end
|
493
|
+
|
494
|
+
# For tests only because tracers must be removed in reverse-order
|
495
|
+
# from when they were added, or else other tracers that were added to the same method
|
496
|
+
# may get removed as well.
|
497
|
+
def remove_method_tracer(method_name, metric_name_code) # :nodoc:
|
498
|
+
return unless Agent.config[:agent_enabled]
|
499
|
+
if method_defined? "#{_traced_method_name(method_name, metric_name_code)}"
|
500
|
+
alias_method method_name, "#{_untraced_method_name(method_name, metric_name_code)}"
|
501
|
+
undef_method "#{_traced_method_name(method_name, metric_name_code)}"
|
502
|
+
::NewRelic::Agent.logger.debug("removed method tracer #{method_name} #{metric_name_code}\n")
|
503
|
+
else
|
504
|
+
raise "No tracer for '#{metric_name_code}' on method '#{method_name}'"
|
505
|
+
end
|
506
|
+
end
|
507
|
+
private
|
508
|
+
|
509
|
+
# given a method and a metric, this method returns the
|
510
|
+
# untraced alias of the method name
|
511
|
+
def _untraced_method_name(method_name, metric_name)
|
512
|
+
"#{_sanitize_name(method_name)}_without_trace_#{_sanitize_name(metric_name)}"
|
513
|
+
end
|
514
|
+
|
515
|
+
# given a method and a metric, this method returns the traced
|
516
|
+
# alias of the method name
|
517
|
+
def _traced_method_name(method_name, metric_name)
|
518
|
+
"#{_sanitize_name(method_name)}_with_trace_#{_sanitize_name(metric_name)}"
|
519
|
+
end
|
520
|
+
|
521
|
+
# makes sure that method names do not contain characters that
|
522
|
+
# might break the interpreter, for example ! or ? characters
|
523
|
+
# that are not allowed in the middle of method names
|
524
|
+
def _sanitize_name(name)
|
525
|
+
name.to_s.tr_s('^a-zA-Z0-9', '_')
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|