ghazel-newrelic_rpm 3.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +525 -0
- data/LICENSE +37 -0
- data/README.rdoc +179 -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/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 +423 -0
- data/lib/new_relic/agent/agent.rb +1040 -0
- data/lib/new_relic/agent/beacon_configuration.rb +61 -0
- data/lib/new_relic/agent/browser_monitoring.rb +83 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +203 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +21 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +62 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +13 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +413 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +232 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +44 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +56 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +36 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +23 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +326 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +84 -0
- data/lib/new_relic/agent/instrumentation/net.rb +23 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +34 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +83 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +36 -0
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +108 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +36 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +60 -0
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +112 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +31 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +54 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +23 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +16 -0
- data/lib/new_relic/agent/method_tracer.rb +422 -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_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +144 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/stats_engine.rb +24 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +182 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +89 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +184 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
- data/lib/new_relic/agent/transaction_sampler.rb +378 -0
- data/lib/new_relic/agent/worker_loop.rb +81 -0
- data/lib/new_relic/collection_helper.rb +69 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +91 -0
- data/lib/new_relic/control.rb +48 -0
- data/lib/new_relic/control/class_methods.rb +47 -0
- data/lib/new_relic/control/configuration.rb +157 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +30 -0
- data/lib/new_relic/control/frameworks/rails.rb +151 -0
- data/lib/new_relic/control/frameworks/rails3.rb +70 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +23 -0
- data/lib/new_relic/control/instance_methods.rb +154 -0
- data/lib/new_relic/control/instrumentation.rb +81 -0
- data/lib/new_relic/control/logging_methods.rb +88 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +104 -0
- data/lib/new_relic/data_serialization.rb +84 -0
- data/lib/new_relic/delayed_job_injection.rb +38 -0
- data/lib/new_relic/histogram.rb +91 -0
- data/lib/new_relic/local_environment.rb +391 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +46 -0
- data/lib/new_relic/metric_spec.rb +73 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/browser_monitoring.rb +68 -0
- data/lib/new_relic/rack/developer_mode.rb +267 -0
- data/lib/new_relic/rack/metric_app.rb +65 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +28 -0
- data/lib/new_relic/rack/newrelic.yml +27 -0
- data/lib/new_relic/rack_app.rb +6 -0
- data/lib/new_relic/recipes.rb +73 -0
- data/lib/new_relic/stats.rb +378 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +76 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -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 +251 -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 +55 -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 +19 -0
- data/newrelic.yml +265 -0
- data/newrelic_rpm.gemspec +330 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/new_relic/agent/agent/connect_test.rb +316 -0
- data/test/new_relic/agent/agent/start_test.rb +340 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +155 -0
- data/test/new_relic/agent/agent_test.rb +173 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +366 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +104 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +274 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +168 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +522 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +179 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +387 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +107 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +81 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +185 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +945 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/collection_helper_test.rb +127 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/logging_methods_test.rb +157 -0
- data/test/new_relic/control_test.rb +195 -0
- data/test/new_relic/data_serialization_test.rb +70 -0
- data/test/new_relic/local_environment_test.rb +72 -0
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -0
- data/test/new_relic/rack/developer_mode_test.rb +43 -0
- data/test/new_relic/stats_test.rb +426 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -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 +454 -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 +170 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +144 -0
- data/ui/helpers/developer_mode_helper.rb +351 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -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 +53 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +19 -0
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -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/LICENSE +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -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 +122 -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/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 +66 -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 +399 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
class BeaconConfiguration
|
4
|
+
attr_reader :browser_timing_header
|
5
|
+
attr_reader :browser_timing_static_footer
|
6
|
+
attr_reader :application_id
|
7
|
+
attr_reader :browser_monitoring_key
|
8
|
+
attr_reader :beacon
|
9
|
+
attr_reader :rum_enabled
|
10
|
+
attr_reader :license_bytes
|
11
|
+
|
12
|
+
JS_HEADER = "<script type=\"text/javascript\">var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
|
13
|
+
|
14
|
+
def initialize(connect_data)
|
15
|
+
@browser_monitoring_key = connect_data['browser_key']
|
16
|
+
@application_id = connect_data['application_id']
|
17
|
+
@beacon = connect_data['beacon']
|
18
|
+
@rum_enabled = connect_data['rum.enabled']
|
19
|
+
@rum_enabled = true if @rum_enabled.nil?
|
20
|
+
NewRelic::Control.instance.log.warn("Real User Monitoring is disabled for this agent. Edit your configuration to change this.") unless @rum_enabled
|
21
|
+
@browser_timing_header = build_browser_timing_header
|
22
|
+
NewRelic::Control.instance.log.debug("Browser timing header: #{@browser_timing_header.inspect}")
|
23
|
+
@browser_timing_static_footer = build_load_file_js(connect_data)
|
24
|
+
NewRelic::Control.instance.log.debug("Browser timing static footer: #{@browser_timing_static_footer.inspect}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def license_bytes
|
28
|
+
if @license_bytes.nil?
|
29
|
+
@license_bytes = []
|
30
|
+
NewRelic::Control.instance.license_key.each_byte {|byte| @license_bytes << byte}
|
31
|
+
end
|
32
|
+
@license_bytes
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_load_file_js(connect_data)
|
36
|
+
return "" unless connect_data.fetch('rum.load_episodes_file', true)
|
37
|
+
|
38
|
+
episodes_url = connect_data.fetch('episodes_url', '')
|
39
|
+
"(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"#{episodes_url}\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();"
|
40
|
+
end
|
41
|
+
|
42
|
+
def javascript_header
|
43
|
+
JS_HEADER.dup
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_browser_timing_header
|
47
|
+
return "" if !@rum_enabled
|
48
|
+
return "" if @browser_monitoring_key.nil?
|
49
|
+
|
50
|
+
value = javascript_header
|
51
|
+
if value.respond_to?(:html_safe)
|
52
|
+
value.html_safe
|
53
|
+
else
|
54
|
+
value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'new_relic/agent/beacon_configuration'
|
3
|
+
module NewRelic
|
4
|
+
module Agent
|
5
|
+
module BrowserMonitoring
|
6
|
+
|
7
|
+
def browser_timing_header
|
8
|
+
return "" if NewRelic::Agent.instance.beacon_configuration.nil?
|
9
|
+
return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
10
|
+
|
11
|
+
NewRelic::Agent.instance.beacon_configuration.browser_timing_header
|
12
|
+
end
|
13
|
+
|
14
|
+
def browser_timing_footer
|
15
|
+
config = NewRelic::Agent.instance.beacon_configuration
|
16
|
+
return "" if config.nil? || !config.rum_enabled || config.browser_monitoring_key.nil?
|
17
|
+
return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
|
18
|
+
generate_footer_js
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def generate_footer_js
|
24
|
+
if browser_monitoring_start_time
|
25
|
+
config = NewRelic::Agent.instance.beacon_configuration
|
26
|
+
application_id = config.application_id
|
27
|
+
beacon = config.beacon
|
28
|
+
license_key = config.browser_monitoring_key
|
29
|
+
|
30
|
+
footer_js_string(beacon, license_key, application_id)
|
31
|
+
else
|
32
|
+
''
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def browser_monitoring_transaction_name
|
37
|
+
Thread.current[:newrelic_most_recent_transaction] || "<unknown>"
|
38
|
+
end
|
39
|
+
|
40
|
+
def browser_monitoring_start_time
|
41
|
+
Thread.current[:newrelic_start_time]
|
42
|
+
end
|
43
|
+
|
44
|
+
def clamp_to_positive(value)
|
45
|
+
return 0.0 if value < 0
|
46
|
+
value
|
47
|
+
end
|
48
|
+
|
49
|
+
def browser_monitoring_app_time
|
50
|
+
clamp_to_positive(((Time.now - browser_monitoring_start_time).to_f * 1000.0).round)
|
51
|
+
end
|
52
|
+
|
53
|
+
def browser_monitoring_queue_time
|
54
|
+
clamp_to_positive((Thread.current[:newrelic_queue_time].to_f * 1000.0).round)
|
55
|
+
end
|
56
|
+
|
57
|
+
def footer_js_string(beacon, license_key, application_id)
|
58
|
+
obfuscated_transaction_name = obfuscate(browser_monitoring_transaction_name)
|
59
|
+
html_safe_if_needed("<script type=\"text/javascript\">#{NewRelic::Agent.instance.beacon_configuration.browser_timing_static_footer}NREUMQ.push([\"nrf2\",\"#{beacon}\",\"#{license_key}\",#{application_id},\"#{obfuscated_transaction_name}\",#{browser_monitoring_queue_time},#{browser_monitoring_app_time},new Date().getTime()])</script>")
|
60
|
+
end
|
61
|
+
|
62
|
+
def html_safe_if_needed(string)
|
63
|
+
if string.respond_to?(:html_safe)
|
64
|
+
string.html_safe
|
65
|
+
else
|
66
|
+
string
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def obfuscate(text)
|
71
|
+
obfuscated = ""
|
72
|
+
key_bytes = NewRelic::Agent.instance.beacon_configuration.license_bytes
|
73
|
+
index = 0
|
74
|
+
text.each_byte{|byte|
|
75
|
+
obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
|
76
|
+
index+=1
|
77
|
+
}
|
78
|
+
|
79
|
+
[obfuscated].pack("m0").gsub("\n", '')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
# This module supports calculation of actual time spent processing requests over the course of
|
4
|
+
# one harvest period. It's similar to what you would get if you just added up all the
|
5
|
+
# execution times of controller calls, however that will be inaccurate when requests
|
6
|
+
# span the minute boundaries. This module manages accounting of requests not yet
|
7
|
+
# completed.
|
8
|
+
#
|
9
|
+
# Calls are re-entrant. All start calls must be paired with finish
|
10
|
+
# calls, or a reset call.
|
11
|
+
module BusyCalculator
|
12
|
+
|
13
|
+
extend self
|
14
|
+
|
15
|
+
# For testability, add accessors:
|
16
|
+
attr_reader :harvest_start, :accumulator
|
17
|
+
|
18
|
+
def dispatcher_start(time)
|
19
|
+
Thread.current[:busy_entries] ||= 0
|
20
|
+
callers = Thread.current[:busy_entries] += 1
|
21
|
+
return if callers > 1
|
22
|
+
@lock.synchronize do
|
23
|
+
@entrypoint_stack.push time
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def dispatcher_finish(end_time = Time.now)
|
28
|
+
callers = Thread.current[:busy_entries] -= 1
|
29
|
+
# Ignore nested calls
|
30
|
+
return if callers > 0
|
31
|
+
@lock.synchronize do
|
32
|
+
if @entrypoint_stack.empty?
|
33
|
+
NewRelic::Agent.logger.error("Stack underflow tracking dispatcher entry and exit!\n #{caller.join(" \n")}")
|
34
|
+
else
|
35
|
+
@accumulator += (end_time - @entrypoint_stack.pop).to_f
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def busy_count
|
41
|
+
@entrypoint_stack.size
|
42
|
+
end
|
43
|
+
|
44
|
+
# Reset the state of the information accumulated by all threads,
|
45
|
+
# but only reset the recursion counter for this thread.
|
46
|
+
def reset
|
47
|
+
@entrypoint_stack = []
|
48
|
+
Thread.current[:busy_entries] = 0
|
49
|
+
@lock ||= Mutex.new
|
50
|
+
@accumulator = 0
|
51
|
+
@harvest_start = Time.now
|
52
|
+
end
|
53
|
+
|
54
|
+
self.reset
|
55
|
+
|
56
|
+
# Called before uploading to to the server to collect current busy stats.
|
57
|
+
def harvest_busy
|
58
|
+
busy = 0
|
59
|
+
t0 = Time.now
|
60
|
+
@lock.synchronize do
|
61
|
+
busy = accumulator
|
62
|
+
@accumulator = 0
|
63
|
+
|
64
|
+
# Walk through the stack and capture all times up to
|
65
|
+
# now for entrypoints
|
66
|
+
@entrypoint_stack.size.times do |frame|
|
67
|
+
busy += (t0 - @entrypoint_stack[frame]).to_f
|
68
|
+
@entrypoint_stack[frame] = t0
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
busy = 0.0 if busy < 0.0 # don't go below 0%
|
74
|
+
|
75
|
+
time_window = (t0 - harvest_start).to_f
|
76
|
+
time_window = 1.0 if time_window == 0.0 # protect against divide by zero
|
77
|
+
|
78
|
+
busy = busy / time_window
|
79
|
+
|
80
|
+
instance_busy_stats.record_data_point busy
|
81
|
+
@harvest_start = t0
|
82
|
+
end
|
83
|
+
private
|
84
|
+
def instance_busy_stats
|
85
|
+
# Late binding on the Instance/busy stats
|
86
|
+
NewRelic::Agent.agent.stats_engine.get_stats_no_scope 'Instance/Busy'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
|
2
|
+
module NewRelic
|
3
|
+
module Agent
|
4
|
+
class ErrorCollector
|
5
|
+
include NewRelic::CollectionHelper
|
6
|
+
|
7
|
+
# Defined the methods that need to be stubbed out when the
|
8
|
+
# agent is disabled
|
9
|
+
module Shim #:nodoc:
|
10
|
+
def notice_error(*args); end
|
11
|
+
end
|
12
|
+
|
13
|
+
MAX_ERROR_QUEUE_LENGTH = 20 unless defined? MAX_ERROR_QUEUE_LENGTH
|
14
|
+
|
15
|
+
attr_accessor :enabled
|
16
|
+
attr_reader :config_enabled
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@errors = []
|
20
|
+
# lookup of exception class names to ignore. Hash for fast access
|
21
|
+
@ignore = {}
|
22
|
+
@ignore_filter = nil
|
23
|
+
|
24
|
+
config = NewRelic::Control.instance.fetch('error_collector', {})
|
25
|
+
|
26
|
+
@enabled = @config_enabled = config.fetch('enabled', true)
|
27
|
+
@capture_source = config.fetch('capture_source', true)
|
28
|
+
|
29
|
+
ignore_errors = config.fetch('ignore_errors', "")
|
30
|
+
ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
|
31
|
+
ignore_errors.each { |error| error.strip! }
|
32
|
+
ignore(ignore_errors)
|
33
|
+
@lock = Mutex.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def control
|
37
|
+
NewRelic::Control.instance
|
38
|
+
end
|
39
|
+
|
40
|
+
def ignore_error_filter(&block)
|
41
|
+
if block
|
42
|
+
@ignore_filter = block
|
43
|
+
else
|
44
|
+
@ignore_filter
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# errors is an array of Exception Class Names
|
49
|
+
#
|
50
|
+
def ignore(errors)
|
51
|
+
errors.each { |error| @ignore[error] = true; log.debug("Ignoring errors of type '#{error}'") }
|
52
|
+
end
|
53
|
+
|
54
|
+
module NoticeError
|
55
|
+
def disabled?
|
56
|
+
!@enabled
|
57
|
+
end
|
58
|
+
|
59
|
+
def filtered_by_error_filter?(error)
|
60
|
+
return unless @ignore_filter
|
61
|
+
!@ignore_filter.call(error)
|
62
|
+
end
|
63
|
+
|
64
|
+
def filtered_error?(error)
|
65
|
+
@ignore[error.class.name] || filtered_by_error_filter?(error)
|
66
|
+
end
|
67
|
+
|
68
|
+
def error_is_ignored?(error)
|
69
|
+
error && filtered_error?(error)
|
70
|
+
end
|
71
|
+
|
72
|
+
def increment_error_count!
|
73
|
+
NewRelic::Agent.get_stats("Errors/all").increment_count
|
74
|
+
end
|
75
|
+
|
76
|
+
def should_exit_notice_error?(exception)
|
77
|
+
if @enabled
|
78
|
+
if !error_is_ignored?(exception)
|
79
|
+
increment_error_count!
|
80
|
+
return exception.nil?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
# disabled or an ignored error, per above
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch_from_options(options, key, default=nil)
|
88
|
+
options.delete(key) || default
|
89
|
+
end
|
90
|
+
|
91
|
+
def uri_ref_and_root(options)
|
92
|
+
{
|
93
|
+
:request_uri => fetch_from_options(options, :uri, ''),
|
94
|
+
:request_referer => fetch_from_options(options, :referer, ''),
|
95
|
+
:rails_root => control.root
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def custom_params_from_opts(options)
|
100
|
+
# If anything else is left over, treat it like a custom param:
|
101
|
+
fetch_from_options(options, :custom_params, {}).merge(options)
|
102
|
+
end
|
103
|
+
|
104
|
+
def request_params_from_opts(options)
|
105
|
+
value = options.delete(:request_params)
|
106
|
+
if control.capture_params
|
107
|
+
value
|
108
|
+
else
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def normalized_request_and_custom_params(options)
|
114
|
+
{
|
115
|
+
:request_params => normalize_params(request_params_from_opts(options)),
|
116
|
+
:custom_params => normalize_params(custom_params_from_opts(options))
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def error_params_from_options(options)
|
121
|
+
uri_ref_and_root(options).merge(normalized_request_and_custom_params(options))
|
122
|
+
end
|
123
|
+
|
124
|
+
def sense_method(object, method)
|
125
|
+
object.send(method) if object.respond_to?(method)
|
126
|
+
end
|
127
|
+
|
128
|
+
def extract_source(exception)
|
129
|
+
sense_method(exception, 'source_extract') if @capture_source
|
130
|
+
end
|
131
|
+
|
132
|
+
def extract_stack_trace(exception)
|
133
|
+
actual_exception = sense_method(exception, 'original_exception') || exception
|
134
|
+
sense_method(actual_exception, 'backtrace') || '<no stack trace>'
|
135
|
+
end
|
136
|
+
|
137
|
+
def exception_info(exception)
|
138
|
+
{
|
139
|
+
:file_name => sense_method(exception, 'file_name'),
|
140
|
+
:line_number => sense_method(exception, 'line_number'),
|
141
|
+
:source => extract_source(exception),
|
142
|
+
:stack_trace => extract_stack_trace(exception)
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
def over_queue_limit?(message)
|
147
|
+
over_limit = (@errors.length >= MAX_ERROR_QUEUE_LENGTH)
|
148
|
+
log.warn("The error reporting queue has reached #{MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: #{message}") if over_limit
|
149
|
+
over_limit
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def add_to_error_queue(noticed_error)
|
154
|
+
@lock.synchronize do
|
155
|
+
@errors << noticed_error unless over_queue_limit?(noticed_error.message)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
include NoticeError
|
161
|
+
|
162
|
+
# Notice the error with the given available options:
|
163
|
+
#
|
164
|
+
# * <tt>:uri</tt> => The request path, minus any request params or query string.
|
165
|
+
# * <tt>:referer</tt> => The URI of the referer
|
166
|
+
# * <tt>:metric</tt> => The metric name associated with the transaction
|
167
|
+
# * <tt>:request_params</tt> => Request parameters, already filtered if necessary
|
168
|
+
# * <tt>:custom_params</tt> => Custom parameters
|
169
|
+
#
|
170
|
+
# If anything is left over, it's added to custom params
|
171
|
+
# If exception is nil, the error count is bumped and no traced error is recorded
|
172
|
+
def notice_error(exception, options={})
|
173
|
+
return if should_exit_notice_error?(exception)
|
174
|
+
action_path = fetch_from_options(options, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || ''))
|
175
|
+
exception_options = error_params_from_options(options).merge(exception_info(exception))
|
176
|
+
add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
|
177
|
+
exception
|
178
|
+
rescue Exception => e
|
179
|
+
log.error("Error capturing an error, yodawg. #{e}")
|
180
|
+
end
|
181
|
+
|
182
|
+
# Get the errors currently queued up. Unsent errors are left
|
183
|
+
# over from a previous unsuccessful attempt to send them to the server.
|
184
|
+
def harvest_errors(unsent_errors)
|
185
|
+
@lock.synchronize do
|
186
|
+
errors = @errors
|
187
|
+
@errors = []
|
188
|
+
|
189
|
+
if unsent_errors && !unsent_errors.empty?
|
190
|
+
errors = unsent_errors + errors
|
191
|
+
end
|
192
|
+
|
193
|
+
errors
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
def log
|
199
|
+
NewRelic::Agent.logger
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|