newrelic_rpm 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -5,6 +5,7 @@ v3.0.0
5
5
  setting the path and name of the agent log file
6
6
  * Improve reliability of statistics calculations
7
7
  * Remove some previously deprecated methods
8
+ * Remove Sequel instrumentation pending more work
8
9
 
9
10
  v2.14.1
10
11
  * Avoid overriding methods named 'log' when including the MethodTracer module
@@ -431,9 +431,9 @@ module NewRelic
431
431
  def create_and_run_worker_loop
432
432
  @worker_loop = WorkerLoop.new
433
433
  @worker_loop.run(@report_period) do
434
- harvest_and_send_timeslice_data
435
434
  harvest_and_send_slowest_sample if @should_send_samples
436
435
  harvest_and_send_errors if error_collector.enabled
436
+ harvest_and_send_timeslice_data
437
437
  end
438
438
  end
439
439
 
@@ -720,6 +720,8 @@ module NewRelic
720
720
  NewRelic::Agent::BusyCalculator.harvest_busy
721
721
 
722
722
  now = Time.now
723
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote').record_data_point(0.0)
724
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote/metric_data').record_data_point(0.0)
723
725
 
724
726
  @unsent_timeslice_data ||= {}
725
727
  @unsent_timeslice_data = @stats_engine.harvest_timeslice_data(@unsent_timeslice_data, @metric_ids)
@@ -897,6 +899,7 @@ module NewRelic
897
899
 
898
900
  # send a message via post
899
901
  def invoke_remote(method, *args)
902
+ now = Time.now
900
903
  #determines whether to zip the data or send plain
901
904
  post_data, encoding = compress_data(args)
902
905
 
@@ -910,6 +913,9 @@ module NewRelic
910
913
  rescue SystemCallError, SocketError => e
911
914
  # These include Errno connection errors
912
915
  raise NewRelic::Agent::ServerConnectionException, "Recoverable error connecting to the server: #{e}"
916
+ ensure
917
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote').record_data_point((Time.now - now).to_f)
918
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope('Supportability/invoke_remote/' + method.to_s).record_data_point((Time.now - now).to_f)
913
919
  end
914
920
 
915
921
  def graceful_disconnect
@@ -0,0 +1,54 @@
1
+ module NewRelic
2
+ module Agent
3
+ class BeaconConfiguration
4
+ attr_reader :browser_timing_header
5
+ attr_reader :application_id
6
+ attr_reader :browser_monitoring_key
7
+ attr_reader :beacon
8
+ attr_reader :rum_enabled
9
+ attr_reader :license_bytes
10
+
11
+ def initialize(connect_data)
12
+ @browser_monitoring_key = connect_data['browser_key']
13
+ @application_id = connect_data['application_id']
14
+ @beacon = connect_data['beacon']
15
+ @rum_enabled = connect_data['rum.enabled']
16
+ @rum_enabled = true if @rum_enabled.nil?
17
+ @browser_timing_header = build_browser_timing_header(connect_data)
18
+ end
19
+
20
+ def license_bytes
21
+ if @license_bytes.nil?
22
+ @license_bytes = []
23
+ NewRelic::Control.instance.license_key.each_byte {|byte| @license_bytes << byte}
24
+ end
25
+ @license_bytes
26
+ end
27
+
28
+ def load_file_js(connect_data)
29
+ return "" unless connect_data.fetch('rum.load_episodes_file', true)
30
+
31
+ episodes_url = connect_data.fetch('episodes_url', '')
32
+ "(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"#{episodes_url}\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()"
33
+ end
34
+
35
+ def basic_javascript(connect_data)
36
+ "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);#{load_file_js(connect_data)}</script>"
37
+ end
38
+
39
+ def build_browser_timing_header(connect_data)
40
+ return "" if !@rum_enabled
41
+ return "" if @browser_monitoring_key.nil?
42
+
43
+ value = basic_javascript(connect_data)
44
+ if value.respond_to?(:html_safe)
45
+ value.html_safe
46
+ else
47
+ value
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+
@@ -1,100 +1,72 @@
1
1
  require 'base64'
2
-
2
+ require 'new_relic/agent/beacon_configuration'
3
3
  module NewRelic
4
4
  module Agent
5
- class BeaconConfiguration
6
- attr_reader :browser_timing_header
7
- attr_reader :application_id
8
- attr_reader :browser_monitoring_key
9
- attr_reader :beacon
10
- attr_reader :rum_enabled
11
- attr_reader :license_bytes
12
-
13
- def initialize(connect_data)
14
- @browser_monitoring_key = connect_data['browser_key']
15
- @application_id = connect_data['application_id']
16
- @beacon = connect_data['beacon']
17
- @rum_enabled = connect_data['rum.enabled']
18
- @rum_enabled = true if @rum_enabled.nil?
19
- @browser_timing_header = build_browser_timing_header(connect_data)
20
- end
21
-
22
- def license_bytes
23
- if @license_bytes.nil?
24
- @license_bytes = []
25
- NewRelic::Control.instance.license_key.each_byte {|byte| @license_bytes << byte}
26
- else
27
- @license_bytes
28
- end
29
- end
30
-
31
- def build_browser_timing_header(connect_data)
32
- return "" if !@rum_enabled
33
- return "" if @browser_monitoring_key.nil?
34
-
35
- episodes_url = connect_data['episodes_url']
36
- load_episodes_file = connect_data['rum.load_episodes_file']
37
- load_episodes_file = true if load_episodes_file.nil?
38
-
39
- load_js = load_episodes_file ? "(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"#{episodes_url}\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()" : ""
40
-
41
- value = "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);#{load_js}</script>"
42
- if value.respond_to?(:html_safe)
43
- value.html_safe
44
- else
45
- value
46
- end
47
- end
48
- end
49
-
50
5
  module BrowserMonitoring
51
6
 
52
7
  def browser_timing_header
53
8
  return "" if NewRelic::Agent.instance.beacon_configuration.nil?
54
-
55
9
  return "" if !NewRelic::Agent.is_transaction_traced? || !NewRelic::Agent.is_execution_traced?
56
-
10
+
57
11
  NewRelic::Agent.instance.beacon_configuration.browser_timing_header
58
12
  end
59
-
13
+
60
14
  def browser_timing_footer
61
15
  config = NewRelic::Agent.instance.beacon_configuration
62
- return "" if config.nil? || !config.rum_enabled
63
-
64
- license_key = config.browser_monitoring_key
65
- return "" if license_key.nil?
66
-
16
+ return "" if config.nil? || !config.rum_enabled || config.browser_monitoring_key.nil?
67
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
68
29
 
69
- application_id = config.application_id
70
- beacon = config.beacon
30
+ footer_js_string(beacon, license_key, application_id)
31
+ else
32
+ ''
33
+ end
34
+ end
71
35
 
72
- transaction_name = Thread.current[:newrelic_most_recent_transaction] || "<unknown>"
73
- start_time = Thread.current[:newrelic_start_time]
74
- queue_time = (Thread.current[:newrelic_queue_time].to_f * 1000.0).round
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
75
43
 
76
- value = ''
77
- if start_time
44
+ def clamp_to_positive(value)
45
+ return 0.0 if value < 0
46
+ value
47
+ end
78
48
 
79
- obf = obfuscate(transaction_name)
80
- app_time = ((Time.now - start_time).to_f * 1000.0).round
49
+ def browser_monitoring_app_time
50
+ clamp_to_positive(((Time.now - browser_monitoring_start_time).to_f * 1000.0).round)
51
+ end
81
52
 
82
- queue_time = 0.0 if queue_time < 0
83
- app_time = 0.0 if app_time < 0
53
+ def browser_monitoring_queue_time
54
+ clamp_to_positive((Thread.current[:newrelic_queue_time].to_f * 1000.0).round)
55
+ end
84
56
 
85
- value = <<-eos
86
- <script type="text/javascript" charset="utf-8">NREUMQ.push(["nrf2","#{beacon}","#{license_key}",#{application_id},"#{obf}",#{queue_time},#{app_time}])</script>
87
- eos
88
- end
89
- if value.respond_to?(:html_safe)
90
- value.html_safe
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\" charset=\"utf-8\">NREUMQ.push([\"nrf2\",\"#{beacon}\",\"#{license_key}\",#{application_id},\"#{obfuscated_transaction_name}\",#{browser_monitoring_queue_time},#{browser_monitoring_app_time}])</script>")
60
+ end
61
+
62
+ def html_safe_if_needed(string)
63
+ if string.respond_to?(:html_safe)
64
+ string.html_safe
91
65
  else
92
- value
66
+ string
93
67
  end
94
68
  end
95
-
96
- private
97
-
69
+
98
70
  def obfuscate(text)
99
71
  obfuscated = ""
100
72
  key_bytes = NewRelic::Agent.instance.beacon_configuration.license_bytes
@@ -102,9 +102,9 @@ module Agent
102
102
  #
103
103
  def end_transaction
104
104
  stack = scope_stack
105
-
105
+
106
106
  if stack && stack.empty?
107
- Thread.current[:newrelic_most_recent_transaction] = Thread.current[:newrelic_scope_name]
107
+ Thread::current[:newrelic_most_recent_transaction] = Thread::current[:newrelic_scope_name]
108
108
  Thread::current[:newrelic_scope_stack] = nil
109
109
  Thread::current[:newrelic_scope_name] = nil
110
110
  end
@@ -25,7 +25,7 @@ module NewRelic
25
25
  # that runs this worker loop. This will run the task immediately.
26
26
  def run(period=nil, &block)
27
27
  @period = period if period
28
- @next_invocation_time = Time.now
28
+ @next_invocation_time = (Time.now + period)
29
29
  @task = block
30
30
  while keep_running do
31
31
  now = Time.now
@@ -389,28 +389,17 @@ module NewRelic
389
389
  agent.record_transaction(response_sec, options)
390
390
  end
391
391
 
392
- # PRE-RELEASE
393
392
  # Returns a Javascript string which should be injected into the very top of the response body
394
393
  #
395
394
  def browser_timing_header
396
395
  agent.browser_timing_header
397
396
  end
398
397
 
399
- # PRE-RELEASE
400
398
  # Returns a Javascript string which should be injected into the very bottom of the response body
401
399
  #
402
400
  def browser_timing_footer
403
401
  agent.browser_timing_footer
404
402
  end
405
403
 
406
- # FOR BACKWARD COMPATIBILITY (REMOVE BEFORE GA)
407
- def browser_instrumentation_header(options={})
408
- agent.browser_timing_header
409
- end
410
-
411
- # FOR BACKWARD COMPATIBILITY (REMOVE BEFORE GA)
412
- def browser_instrumentation_footer(options={})
413
- agent.browser_timing_footer
414
- end
415
404
  end
416
405
  end
@@ -30,11 +30,16 @@ module NewRelic
30
30
  end
31
31
 
32
32
  def install_browser_monitoring(config)
33
+ return if @browser_monitoring_installed
34
+ @browser_monitoring_installed = true
33
35
  return if config.nil? || !config.respond_to?(:middleware) || !browser_monitoring_auto_instrument?
34
-
35
- require 'new_relic/rack/browser_monitoring'
36
- config.middleware.use NewRelic::Rack::BrowserMonitoring
37
- ::RAILS_DEFAULT_LOGGER.info "Installed browser monitoring middleware"
36
+ begin
37
+ require 'new_relic/rack/browser_monitoring'
38
+ config.middleware.use NewRelic::Rack::BrowserMonitoring
39
+ log!("Installed New Relic Browser Monitoring middleware", :info)
40
+ rescue Exception => e
41
+ log!("Error installing New Relic Browser Monitoring middleware: #{e.inspect}", :error)
42
+ end
38
43
  end
39
44
 
40
45
  def install_developer_mode(rails_config)
@@ -183,7 +183,7 @@ module NewRelic
183
183
  end
184
184
 
185
185
  def working_jruby?
186
- !(defined?(::JRuby) && Jruby.respond_to?(:runtime) && !JRuby.runtime.is_object_space_enabled)
186
+ !(defined?(::JRuby) && JRuby.respond_to?(:runtime) && !JRuby.runtime.is_object_space_enabled)
187
187
  end
188
188
 
189
189
  def find_class_in_object_space(klass)
@@ -4,7 +4,7 @@
4
4
  # require 'new_relic/recipes'
5
5
  # to your deploy.rb
6
6
  #
7
- # Defined deploy:notify_rpm which will send information about the deploy to RPM.
7
+ # Defined deploy:notify_rpm which will send information about the deploy to New Relic.
8
8
  # The task will run on app servers except where no_release is true.
9
9
  # If it fails, it will not affect the task execution or do a rollback.
10
10
  #
@@ -12,8 +12,8 @@ make_notify_task = Proc.new do
12
12
 
13
13
  namespace :newrelic do
14
14
 
15
- # on all deployments, notify RPM
16
- desc "Record a deployment in New Relic RPM (rpm.newrelic.com)"
15
+ # on all deployments, notify New Relic
16
+ desc "Record a deployment in New Relic (rpm.newrelic.com)"
17
17
  task :notice_deployment, :roles => :app, :except => {:no_release => true } do
18
18
  rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
19
19
  require File.join(File.dirname(__FILE__), 'command.rb')
@@ -4,7 +4,7 @@ module NewRelic
4
4
  MAJOR = 3
5
5
  MINOR = 0
6
6
  TINY = 0
7
- BUILD = 'beta1' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
7
+ BUILD = 'beta2' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/newrelic_rpm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{newrelic_rpm}
8
- s.version = "3.0.0.beta1"
8
+ s.version = "3.0.0.beta2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Kayser", "Justin George"]
12
- s.date = %q{2011-04-29}
12
+ s.date = %q{2011-05-06}
13
13
  s.description = %q{New Relic RPM is a Ruby performance management system, developed by
14
14
  New Relic, Inc (http://www.newrelic.com). RPM provides you with deep
15
15
  information about the performance of your Ruby on Rails or Merb
@@ -40,6 +40,7 @@ http://github.com/newrelic/rpm/tree/master.
40
40
  "lib/conditional_vendored_metric_parser.rb",
41
41
  "lib/new_relic/agent.rb",
42
42
  "lib/new_relic/agent/agent.rb",
43
+ "lib/new_relic/agent/beacon_configuration.rb",
43
44
  "lib/new_relic/agent/browser_monitoring.rb",
44
45
  "lib/new_relic/agent/busy_calculator.rb",
45
46
  "lib/new_relic/agent/chained_call.rb",
@@ -138,6 +139,7 @@ http://github.com/newrelic/rpm/tree/master.
138
139
  "test/new_relic/agent/agent_test_controller.rb",
139
140
  "test/new_relic/agent/agent_test_controller_test.rb",
140
141
  "test/new_relic/agent/apdex_from_server_test.rb",
142
+ "test/new_relic/agent/beacon_configuration_test.rb",
141
143
  "test/new_relic/agent/browser_monitoring_test.rb",
142
144
  "test/new_relic/agent/busy_calculator_test.rb",
143
145
  "test/new_relic/agent/error_collector/notice_error_test.rb",
@@ -0,0 +1,121 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require "new_relic/agent/beacon_configuration"
3
+ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
4
+ def test_initialize_basic
5
+ connect_data = {}
6
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
7
+ assert_equal true, bc.rum_enabled
8
+ assert_equal '', bc.browser_timing_header
9
+ %w[application_id browser_monitoring_key beacon].each do |method|
10
+ value = bc.send(method.to_sym)
11
+ assert_equal nil, value, "Expected #{method} to be nil, but was #{value.inspect}"
12
+ end
13
+ end
14
+
15
+ def test_initialize_with_real_data
16
+ connect_data = {'browser_key' => 'a browser monitoring key', 'application_id' => 'an application id', 'beacon' => 'a beacon', 'rum_enabled' => true}
17
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
18
+ assert_equal true, bc.rum_enabled
19
+ assert_equal 'a browser monitoring key', bc.browser_monitoring_key
20
+ assert_equal 'an application id', bc.application_id
21
+ assert_equal 'a beacon', bc.beacon
22
+ assert_equal 269, bc.browser_timing_header.size
23
+ end
24
+
25
+ def test_license_bytes_nil
26
+ connect_data = {}
27
+ NewRelic::Control.instance.expects(:license_key).returns('a' * 40).once
28
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
29
+ assert_equal([97] * 40, bc.license_bytes, 'should return the bytes of the license key')
30
+ end
31
+
32
+ def test_license_bytes_existing_bytes
33
+ connect_data = {}
34
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
35
+ bc.instance_eval { @license_bytes = [97] * 40 }
36
+ NewRelic::Control.instance.expects(:license_key).never
37
+ assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
38
+ end
39
+
40
+ def test_license_bytes_should_set_instance_cache
41
+ connect_data = {}
42
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
43
+ NewRelic::Control.instance.expects(:license_key).returns('a' * 40)
44
+ bc.instance_eval { @license_bytes = nil }
45
+ bc.license_bytes
46
+ assert_equal([97] * 40, bc.instance_variable_get('@license_bytes'), "should cache the license bytes for later")
47
+ end
48
+
49
+ def test_build_browser_timing_header_disabled
50
+ connect_data = {}
51
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
52
+ bc.instance_eval { @rum_enabled = false }
53
+ assert_equal '', bc.build_browser_timing_header(connect_data), "should not return a header when rum enabled is false"
54
+ end
55
+
56
+ def test_build_browser_timing_header_enabled_but_no_key
57
+ connect_data = {}
58
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
59
+ bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = nil }
60
+ assert_equal '', bc.build_browser_timing_header(connect_data), "should not return a header when browser_monitoring_key is nil"
61
+ end
62
+
63
+ def test_build_browser_timing_header_enabled_checking_for_episodes_url
64
+ connect_data = {'episodes_url' => 'an episodes url'}
65
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
66
+ bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = 'a' * 40 }
67
+ assert(bc.build_browser_timing_header(connect_data).include?('an episodes url'), "should include the episodes url in the javascript")
68
+ end
69
+
70
+ def test_build_browser_timing_header_enabled_with_key
71
+ connect_data = {}
72
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
73
+ bc.instance_eval { @browser_monitoring_key = 'a browser monitoring key' }
74
+ bc.expects(:load_file_js).with({}).returns('load file js')
75
+ assert(bc.build_browser_timing_header(connect_data).include?('load file js'), "header should be generated when rum is enabled and browser monitoring key is set")
76
+ end
77
+
78
+ def test_basic_javascript
79
+ connect_data = {}
80
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
81
+ mock_data = mock('connect data')
82
+ bc.expects(:load_file_js).with(mock_data)
83
+ # should just pass through the data
84
+ bc.basic_javascript(mock_data)
85
+ end
86
+
87
+ def test_build_browser_timing_header_should_html_safe_header
88
+ mock_javascript = mock('javascript')
89
+ connect_data = {'browser_key' => 'a' * 40}
90
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
91
+ assert_equal('a' * 40, bc.instance_variable_get('@browser_monitoring_key'), "should save the key from the config")
92
+ bc.expects(:basic_javascript).with(connect_data).returns(mock_javascript)
93
+ mock_javascript.expects(:respond_to?).with(:html_safe).returns(true)
94
+ mock_javascript.expects(:html_safe)
95
+ bc.build_browser_timing_header(connect_data)
96
+ end
97
+
98
+ def test_load_file_js_load_episodes_file_false
99
+ connect_data = {'rum.load_episodes_file' => false}
100
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
101
+ assert_equal '', bc.load_file_js(connect_data), "should be empty when load episodes file is false"
102
+ end
103
+
104
+ def test_load_file_js_load_episodes_file_missing
105
+ connect_data = {}
106
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
107
+ assert_equal(183, bc.load_file_js(connect_data).size, "should output the javascript when there is no configuration")
108
+ end
109
+
110
+ def test_load_file_js_load_episodes_file_present
111
+ connect_data = {'rum.load_episodes_file' => true}
112
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
113
+ assert_equal(183, bc.load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
114
+ end
115
+
116
+ def test_load_file_js_load_episodes_file_with_episodes_url
117
+ connect_data = {'episodes_url' => 'an episodes url'}
118
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
119
+ assert(bc.load_file_js(connect_data).include?('an episodes url'), "should include the episodes url by default")
120
+ end
121
+ end
@@ -12,25 +12,27 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
12
12
  NewRelic::Agent.instance.instance_eval do
13
13
  @beacon_configuration = NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"})
14
14
  end
15
+ Thread.current[:newrelic_most_recent_transaction] = "MyCoolTransaction"
15
16
  end
16
17
 
17
18
  def teardown
18
19
  mocha_teardown
19
20
  Thread.current[:newrelic_start_time] = nil
20
21
  Thread.current[:newrelic_metric_frame] = nil
22
+ Thread.current[:newrelic_most_recent_transaction] = nil
21
23
  end
22
24
 
23
25
  def test_browser_timing_header_with_no_beacon_configuration
24
26
  NewRelic::Agent.instance.expects(:beacon_configuration).returns( nil)
25
27
  header = browser_timing_header
26
28
  assert_equal "", header
27
- end
29
+ end
28
30
 
29
31
  def test_browser_timing_header
30
32
  header = browser_timing_header
31
33
  assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"this_is_my_file\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()</script>", header
32
34
  end
33
-
35
+
34
36
  def test_browser_timing_header_with_rum_enabled_not_specified
35
37
  NewRelic::Agent.instance.expects(:beacon_configuration).at_least_once.returns( NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
36
38
  header = browser_timing_header
@@ -44,12 +46,12 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
44
46
  end
45
47
 
46
48
  def test_browser_timing_header_disable_all_tracing
47
- header = nil
48
- NewRelic::Agent.disable_all_tracing do
49
- header = browser_timing_header
50
- end
51
- assert_equal "", header
52
- end
49
+ header = nil
50
+ NewRelic::Agent.disable_all_tracing do
51
+ header = browser_timing_header
52
+ end
53
+ assert_equal "", header
54
+ end
53
55
 
54
56
  def test_browser_timing_header_disable_transaction_tracing
55
57
  header = nil
@@ -60,6 +62,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
60
62
  end
61
63
 
62
64
  def test_browser_timing_footer
65
+ browser_timing_header
63
66
  NewRelic::Control.instance.expects(:license_key).returns("a" * 13)
64
67
 
65
68
  Thread.current[:newrelic_start_time] = Time.now
@@ -67,20 +70,28 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
67
70
  footer = browser_timing_footer
68
71
  assert footer.include?("<script type=\"text/javascript\" charset=\"utf-8\">NREUMQ.push([\"nrf2\",")
69
72
  end
70
-
73
+
74
+ def test_browser_timing_footer_without_calling_header
75
+ footer = browser_timing_footer
76
+ assert_equal "", footer
77
+ end
78
+
71
79
  def test_browser_timing_footer_with_no_browser_key_rum_enabled
80
+ browser_timing_header
72
81
  NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
73
82
  footer = browser_timing_footer
74
83
  assert_equal "", footer
75
84
  end
76
85
 
77
86
  def test_browser_timing_footer_with_no_browser_key_rum_disabled
78
- NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => false, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
79
- footer = browser_timing_footer
80
- assert_equal "", footer
81
- end
87
+ browser_timing_header
88
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => false, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
89
+ footer = browser_timing_footer
90
+ assert_equal "", footer
91
+ end
82
92
 
83
93
  def test_browser_timing_footer_with_rum_enabled_not_specified
94
+ browser_timing_header
84
95
  Thread.current[:newrelic_start_time] = Time.now
85
96
 
86
97
  license_bytes = [];
@@ -90,15 +101,18 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
90
101
  NewRelic::Agent.instance.expects(:beacon_configuration).returns(config).at_least_once
91
102
  footer = browser_timing_footer
92
103
  assert footer.include?("<script type=\"text/javascript\" charset=\"utf-8\">NREUMQ.push([\"nrf2\",")
104
+ assert footer.include?("])</script>")
93
105
  end
94
106
 
95
107
  def test_browser_timing_footer_with_no_beacon_configuration
108
+ browser_timing_header
96
109
  NewRelic::Agent.instance.expects(:beacon_configuration).returns( nil)
97
110
  footer = browser_timing_footer
98
111
  assert_equal "", footer
99
112
  end
100
113
 
101
114
  def test_browser_timing_footer_with_no_start_time
115
+ browser_timing_header
102
116
  Thread.current[:newrelic_start_time] = nil
103
117
  NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
104
118
  footer = browser_timing_footer
@@ -107,6 +121,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
107
121
 
108
122
 
109
123
  def test_browser_timing_footer_disable_all_tracing
124
+ browser_timing_header
110
125
  footer = nil
111
126
  NewRelic::Agent.disable_all_tracing do
112
127
  footer = browser_timing_footer
@@ -115,10 +130,134 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
115
130
  end
116
131
 
117
132
  def test_browser_timing_footer_disable_transaction_tracing
133
+ browser_timing_header
118
134
  footer = nil
119
135
  NewRelic::Agent.disable_transaction_tracing do
120
136
  footer = browser_timing_footer
121
137
  end
122
138
  assert_equal "", footer
123
139
  end
140
+
141
+ def test_browser_timing_footer_browser_monitoring_key_missing
142
+ fake_config = mock('beacon configuration')
143
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns(fake_config)
144
+ fake_config.expects(:nil?).returns(false)
145
+ fake_config.expects(:rum_enabled).returns(true)
146
+ fake_config.expects(:browser_monitoring_key).returns(nil)
147
+ self.expects(:generate_footer_js).never
148
+ assert_equal('', browser_timing_footer, "should not return a footer when there is no key")
149
+ end
150
+
151
+ def test_generate_footer_js_null_case
152
+ self.expects(:browser_monitoring_start_time).returns(nil)
153
+ assert_equal('', generate_footer_js, "should not send javascript when there is no start time")
154
+ end
155
+
156
+ def test_generate_footer_js_with_start_time
157
+ self.expects(:browser_monitoring_start_time).returns(Time.at(100))
158
+ fake_bc = mock('beacon configuration')
159
+ fake_bc.expects(:application_id).returns(1)
160
+ fake_bc.expects(:beacon).returns('beacon')
161
+ fake_bc.expects(:browser_monitoring_key).returns('a' * 40)
162
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns(fake_bc)
163
+ self.expects(:footer_js_string).with('beacon', 'a' * 40, 1).returns('footer js')
164
+ assert_equal('footer js', generate_footer_js, 'should generate and return the footer JS when there is a start time')
165
+ end
166
+
167
+ def test_browser_monitoring_transaction_name_basic
168
+ Thread.current[:newrelic_most_recent_transaction] = 'a transaction name'
169
+ assert_equal('a transaction name', browser_monitoring_transaction_name, "should take the value from the thread local")
170
+ end
171
+
172
+ def test_browser_monitoring_transaction_name_empty
173
+ Thread.current[:newrelic_most_recent_transaction] = ''
174
+ assert_equal('', browser_monitoring_transaction_name, "should take the value even when it is empty")
175
+ end
176
+
177
+ def test_browser_monitoring_transaction_name_nil
178
+ Thread.current[:newrelic_most_recent_transaction] = nil
179
+ assert_equal('<unknown>', browser_monitoring_transaction_name, "should fill in a default when it is nil")
180
+ end
181
+
182
+ def test_browser_monitoring_start_time
183
+ Thread.current[:newrelic_start_time] = Time.at(100)
184
+ assert_equal(Time.at(100), browser_monitoring_start_time, "should take the value from the thread local")
185
+ end
186
+
187
+ def test_clamp_to_positive
188
+ assert_equal(0.0, clamp_to_positive(-1), "should clamp a negative value to zero")
189
+ assert_equal(1232, clamp_to_positive(1232), "should pass through the value when it is positive")
190
+ assert_equal(0, clamp_to_positive(0), "should not mess with zero when passing it through")
191
+ end
192
+
193
+ def test_browser_monitoring_app_time_nonzero
194
+ start = Time.now
195
+ self.expects(:browser_monitoring_start_time).returns(start - 1)
196
+ Time.expects(:now).returns(start)
197
+ assert_equal(1000, browser_monitoring_app_time, 'should return a rounded time')
198
+ end
199
+
200
+ def test_browser_monitoring_queue_time_nil
201
+ Thread.current[:newrelic_queue_time] = nil
202
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is no queue time')
203
+ end
204
+
205
+ def test_browser_monitoring_queue_time_zero
206
+ Thread.current[:newrelic_queue_time] = 0.0
207
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is zero queue time')
208
+ end
209
+
210
+ def test_browser_monitoring_queue_time_ducks
211
+ Thread.current[:newrelic_queue_time] = 'a duck'
212
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is an incorrect queue time')
213
+ end
214
+
215
+ def test_browser_monitoring_queue_time_nonzero
216
+ Thread.current[:newrelic_queue_time] = 3.00002
217
+ assert_equal(3000, browser_monitoring_queue_time, 'should return a rounded time')
218
+ end
219
+
220
+ def test_footer_js_string_basic
221
+ beacon = ''
222
+ license_key = ''
223
+ application_id = 1
224
+
225
+ Thread.current[:newrelic_queue_time] = nil
226
+ # mocking this because JRuby thinks that Time.now - Time.now
227
+ # always takes at least 1ms
228
+ self.expects(:browser_monitoring_app_time).returns(0)
229
+ Thread.current[:newrelic_most_recent_transaction] = 'most recent transaction'
230
+
231
+ self.expects(:obfuscate).with('most recent transaction').returns('most recent transaction')
232
+
233
+ value = footer_js_string(beacon, license_key, application_id)
234
+ assert_equal('<script type="text/javascript" charset="utf-8">NREUMQ.push(["nrf2","","",1,"most recent transaction",0,0])</script>', value, "should return the javascript given some default values")
235
+ end
236
+
237
+ def test_html_safe_if_needed_unsafed
238
+ string = mock('string')
239
+ # here to handle 1.9 encoding - we stub this out because it should
240
+ # be handled automatically and is outside the scope of this test
241
+ string.stubs(:respond_to?).with(:encoding).returns(false)
242
+ string.expects(:respond_to?).with(:html_safe).returns(false)
243
+ assert_equal(string, html_safe_if_needed(string))
244
+ end
245
+
246
+ def test_html_safe_if_needed_safed
247
+ string = mock('string')
248
+ string.expects(:respond_to?).with(:html_safe).returns(true)
249
+ string.expects(:html_safe).returns(string)
250
+ # here to handle 1.9 encoding - we stub this out because it should
251
+ # be handled automatically and is outside the scope of this test
252
+ string.stubs(:respond_to?).with(:encoding).returns(false)
253
+ assert_equal(string, html_safe_if_needed(string))
254
+ end
255
+
256
+ def test_obfuscate_basic
257
+ text = 'a happy piece of small text'
258
+ key = (1..40).to_a
259
+ NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
260
+ output = obfuscate(text)
261
+ assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1', output, "should output obfuscated text")
262
+ end
124
263
  end
@@ -68,7 +68,7 @@ class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
68
68
 
69
69
  assert_equal 1, @instance_busy.call_count
70
70
  # 3 + 6 = 9, or 90%
71
- assert_in_delta 0.90, @instance_busy.total_call_time, 0.025
71
+ assert_in_delta 0.90, @instance_busy.total_call_time, 0.1
72
72
 
73
73
  end
74
74
  def test_dont_ignore_zero_counts
@@ -735,21 +735,24 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
735
735
 
736
736
  run_sample_trace
737
737
  run_sample_trace
738
- run_sample_trace { sleep 0.06 }
738
+ run_sample_trace { sleep 0.1 }
739
739
  run_sample_trace
740
740
  run_sample_trace
741
741
 
742
742
  slowest = @sampler.harvest(nil, 0)[0]
743
- assert slowest.duration >= 0.06, "sample duration: #{slowest.duration}"
743
+ assert((slowest.duration >= 0.1), "expected sample duration >= 0.1, but was: #{slowest.duration.inspect}")
744
+ # this assert is here to make sure the test remains valid
745
+ assert((slowest.duration <= 0.15), "expected sample duration <= 0.15, but was: #{slowest.duration.inspect}")
746
+
744
747
 
745
- run_sample_trace { sleep 0.001 }
748
+ run_sample_trace { sleep 0.0001 }
746
749
  not_as_slow = @sampler.harvest(slowest, 0)[0]
747
- assert not_as_slow == slowest
750
+ assert((not_as_slow == slowest), "Should re-harvest the same transaction since it should be slower than the new transaction - expected #{slowest.inspect} but got #{not_as_slow.inspect}")
748
751
 
749
- run_sample_trace { sleep 0.07 }
752
+ run_sample_trace { sleep 0.15 }
750
753
  new_slowest = @sampler.harvest(slowest, 0)[0]
751
- assert new_slowest != slowest
752
- assert new_slowest.duration >= 0.06, "Slowest duration must be > 0.06: #{new_slowest.duration}"
754
+ assert((new_slowest != slowest), "Should not harvest the same trace since the new one should be slower")
755
+ assert((new_slowest.duration >= 0.15), "Slowest duration must be >= 0.15, but was: #{new_slowest.duration.inspect}")
753
756
  end
754
757
 
755
758
 
@@ -87,8 +87,7 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
87
87
 
88
88
  explanations.each do |explanation|
89
89
  assert_kind_of Array, explanation
90
- assert_kind_of Array, explanation[0]
91
- assert_equal "QUERY RESULT", explanation[0][0]
90
+ assert_equal "QUERY RESULT", explanation.join('')
92
91
  explain_count += 1
93
92
  end
94
93
  end
@@ -2,7 +2,7 @@
2
2
  xml:lang="en" lang="en">
3
3
  <head>
4
4
  <script type="text/javascript" src="/newrelic/file/javascript/jquery-1.4.2.js"></script>
5
- <title>New Relic RPM Developer Mode</title>
5
+ <title>New Relic Developer Mode</title>
6
6
  <link href="/newrelic/file/stylesheets/style.css"
7
7
  media="screen" rel="stylesheet" type="text/css" />
8
8
  </head>
@@ -12,7 +12,7 @@
12
12
  <table width="100%" height="60">
13
13
  <tr>
14
14
  <td valign="middle">
15
- <a href='/newrelic'><img src="/newrelic/file/images/new_relic_rpm_desktop.gif" hspace="10" alt="New Relic RPM"/></a>
15
+ <a href='/newrelic'><img src="/newrelic/file/images/new_relic_rpm_desktop.gif" hspace="10" alt="New Relic"/></a>
16
16
  </td>
17
17
  <td class="top_nav" valign="bottom">
18
18
  <ul id="navlist">
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230019
5
- prerelease: true
4
+ hash: 62196423
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
- - beta1
11
- version: 3.0.0.beta1
10
+ - beta
11
+ - 2
12
+ version: 3.0.0.beta2
12
13
  platform: ruby
13
14
  authors:
14
15
  - Bill Kayser
@@ -17,7 +18,7 @@ autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2011-04-29 00:00:00 -07:00
21
+ date: 2011-05-06 00:00:00 -07:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency
@@ -97,6 +98,7 @@ files:
97
98
  - lib/conditional_vendored_metric_parser.rb
98
99
  - lib/new_relic/agent.rb
99
100
  - lib/new_relic/agent/agent.rb
101
+ - lib/new_relic/agent/beacon_configuration.rb
100
102
  - lib/new_relic/agent/browser_monitoring.rb
101
103
  - lib/new_relic/agent/busy_calculator.rb
102
104
  - lib/new_relic/agent/chained_call.rb
@@ -195,6 +197,7 @@ files:
195
197
  - test/new_relic/agent/agent_test_controller.rb
196
198
  - test/new_relic/agent/agent_test_controller_test.rb
197
199
  - test/new_relic/agent/apdex_from_server_test.rb
200
+ - test/new_relic/agent/beacon_configuration_test.rb
198
201
  - test/new_relic/agent/browser_monitoring_test.rb
199
202
  - test/new_relic/agent/busy_calculator_test.rb
200
203
  - test/new_relic/agent/error_collector/notice_error_test.rb
@@ -368,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
368
371
  requirements: []
369
372
 
370
373
  rubyforge_project:
371
- rubygems_version: 1.3.7
374
+ rubygems_version: 1.5.2
372
375
  signing_key:
373
376
  specification_version: 3
374
377
  summary: New Relic Ruby Performance Monitoring Agent