newrelic_rpm 3.6.9.171 → 3.7.0.174.beta
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +9 -0
- data/lib/new_relic/agent.rb +15 -21
- data/lib/new_relic/agent/beacon_configuration.rb +1 -81
- data/lib/new_relic/agent/browser_monitoring.rb +82 -49
- data/lib/new_relic/agent/configuration/default_source.rb +31 -12
- data/lib/new_relic/agent/request_sampler.rb +17 -10
- data/lib/new_relic/agent/transaction.rb +10 -17
- data/lib/new_relic/coerce.rb +26 -0
- data/lib/new_relic/rack/browser_monitoring.rb +43 -39
- data/lib/new_relic/version.rb +2 -2
- data/lib/tasks/install.rake +1 -0
- data/test/agent_helper.rb +2 -2
- data/test/environments/rails40/Gemfile +1 -1
- data/test/multiverse/lib/multiverse/suite.rb +11 -1
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +19 -12
- data/test/multiverse/suites/rails/Envfile +1 -5
- data/test/multiverse/suites/rails/queue_time_test.rb +3 -2
- data/test/multiverse/suites/rails/request_statistics_test.rb +29 -0
- data/test/multiverse/suites/sidekiq/Envfile +10 -1
- data/test/multiverse/suites/sinatra/Envfile +3 -7
- data/test/new_relic/agent/beacon_configuration_test.rb +9 -76
- data/test/new_relic/agent/browser_monitoring_test.rb +204 -96
- data/test/new_relic/agent/request_sampler_test.rb +41 -1
- data/test/new_relic/agent/transaction_test.rb +47 -0
- data/test/new_relic/coerce_test.rb +24 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +38 -6
- data/test/performance/suites/rum_autoinsertion.rb +0 -1
- data/test/rum/basic.result.html +2 -2
- data/test/rum/comments1.result.html +2 -2
- data/test/rum/comments2.result.html +2 -2
- data/test/rum/gt_in_quotes1.result.html +2 -2
- data/test/rum/gt_in_quotes2.result.html +2 -2
- data/test/rum/gt_in_quotes_mismatch.result.html +2 -2
- data/test/rum/gt_in_single_quotes1.result.html +2 -2
- data/test/rum/gt_in_single_quotes_mismatch.result.html +2 -2
- data/test/rum/incomplete_non_meta_tags.result.html +2 -2
- data/test/rum/no_header.result.html +2 -2
- data/test/rum/no_html_and_no_header.result.html +2 -2
- data/test/rum/no_start_header.result.html +2 -2
- data/test/rum/script1.result.html +2 -2
- data/test/rum/script2.result.html +2 -2
- data/test/rum/x_ua_meta_tag.result.html +2 -2
- data/test/rum/x_ua_meta_tag_multiline.result.html +2 -2
- data/test/rum/x_ua_meta_tag_with_others.result.html +2 -2
- data/test/rum/x_ua_meta_tag_with_spaces.result.html +2 -2
- metadata +8 -24
- metadata.gz.sig +0 -0
@@ -215,7 +215,8 @@ module NewRelic
|
|
215
215
|
:type => @type,
|
216
216
|
:start_timestamp => start_time.to_f,
|
217
217
|
:duration => end_time.to_f - start_time.to_f,
|
218
|
-
:overview_metrics => overview_metrics
|
218
|
+
:overview_metrics => overview_metrics,
|
219
|
+
:custom_params => custom_parameters
|
219
220
|
}
|
220
221
|
agent.events.notify(:transaction_finished, payload)
|
221
222
|
end
|
@@ -295,12 +296,9 @@ module NewRelic
|
|
295
296
|
(current && current.custom_parameters) ? current.custom_parameters : {}
|
296
297
|
end
|
297
298
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
def self.user_attributes
|
303
|
-
(current) ? current.user_attributes : {}
|
299
|
+
class << self
|
300
|
+
alias_method :user_attributes, :custom_parameters
|
301
|
+
alias_method :set_user_attributes, :add_custom_parameters
|
304
302
|
end
|
305
303
|
|
306
304
|
APDEX_METRIC_SPEC = NewRelic::MetricSpec.new('Apdex').freeze
|
@@ -357,20 +355,15 @@ module NewRelic
|
|
357
355
|
@custom_parameters ||= {}
|
358
356
|
end
|
359
357
|
|
360
|
-
def user_attributes
|
361
|
-
@user_atrributes ||= {}
|
362
|
-
end
|
363
|
-
|
364
|
-
def queue_time
|
365
|
-
@apdex_start ? @start_time - @apdex_start : 0
|
366
|
-
end
|
367
|
-
|
368
358
|
def add_custom_parameters(p)
|
369
359
|
custom_parameters.merge!(p)
|
370
360
|
end
|
371
361
|
|
372
|
-
|
373
|
-
|
362
|
+
alias_method :user_attributes, :custom_parameters
|
363
|
+
alias_method :set_user_attributes, :add_custom_parameters
|
364
|
+
|
365
|
+
def queue_time
|
366
|
+
@apdex_start ? @start_time - @apdex_start : 0
|
374
367
|
end
|
375
368
|
|
376
369
|
# Returns truthy if the current in-progress transaction is considered a
|
data/lib/new_relic/coerce.rb
CHANGED
@@ -42,6 +42,32 @@ module NewRelic
|
|
42
42
|
""
|
43
43
|
end
|
44
44
|
|
45
|
+
# Convert a hash into a format acceptable to be included with Transaction
|
46
|
+
# event data.
|
47
|
+
#
|
48
|
+
# We accept a hash and will return a new hash where all of the keys
|
49
|
+
# have been converted to strings. As values we only allow Strings,
|
50
|
+
# Floats, Integers. Symbols are also allowed but are converted to strings.
|
51
|
+
# Any values of other type (e.g. Hash, Array, any other class) are
|
52
|
+
# discarded. Their keys are also removed from the results hash.
|
53
|
+
def event_params(value, context=nil)
|
54
|
+
unless value.is_a? Hash
|
55
|
+
raise ArgumentError, "Expected Hash but got #{value.class}"
|
56
|
+
end
|
57
|
+
value.inject({}) do |memo, (key, val)|
|
58
|
+
case val
|
59
|
+
when String, Float, Integer
|
60
|
+
memo[key.to_s] = val
|
61
|
+
when Symbol
|
62
|
+
memo[key.to_s] = val.to_s
|
63
|
+
end
|
64
|
+
memo
|
65
|
+
end
|
66
|
+
rescue => error
|
67
|
+
log_failure(value.class, 'valid event params', context, error)
|
68
|
+
{}
|
69
|
+
end
|
70
|
+
|
45
71
|
def log_failure(value, type, context, error)
|
46
72
|
msg = "Unable to convert '#{value}' to #{type}"
|
47
73
|
msg += " in context '#{context}'" if context
|
@@ -49,52 +49,28 @@ module NewRelic::Rack
|
|
49
49
|
X_UA_COMPATIBLE_RE = /<\s*meta[^>]+http-equiv=['"]x-ua-compatible['"][^>]*>/im.freeze
|
50
50
|
|
51
51
|
def autoinstrument_source(response, headers)
|
52
|
-
source =
|
53
|
-
response
|
52
|
+
source = gather_source(response)
|
53
|
+
close_old_response(response)
|
54
54
|
return nil unless source
|
55
55
|
|
56
|
-
|
57
56
|
# Only scan the first 50k (roughly) then give up.
|
58
57
|
beginning_of_source = source[0..50_000]
|
59
|
-
# Don't scan for body close unless we find body start
|
60
|
-
if (body_start = beginning_of_source.index("<body")) && (body_close = source.rindex("</body>"))
|
61
|
-
|
62
|
-
footer = NewRelic::Agent.browser_timing_footer
|
63
|
-
header = NewRelic::Agent.browser_timing_header
|
64
|
-
|
65
|
-
match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
|
66
|
-
x_ua_compatible_position = match.end(0) if match
|
67
|
-
|
68
|
-
head_pos = if x_ua_compatible_position
|
69
|
-
# put after X-UA-Compatible meta tag if found
|
70
|
-
::NewRelic::Agent.logger.debug "Detected X-UA-Compatible meta tag. Attempting to insert RUM header after meta tag."
|
71
|
-
x_ua_compatible_position
|
72
|
-
elsif head_open = beginning_of_source.index("<head")
|
73
|
-
::NewRelic::Agent.logger.debug "Attempting to insert RUM header at beginning of head."
|
74
|
-
# put at the beginning of the header
|
75
|
-
beginning_of_source.index(">", head_open) + 1
|
76
|
-
else
|
77
|
-
::NewRelic::Agent.logger.debug "Failed to detect head tag. Attempting to insert RUM header at above body tag."
|
78
|
-
# otherwise put the header right above body start
|
79
|
-
body_start
|
80
|
-
end
|
81
58
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
footer
|
90
|
-
|
59
|
+
if body_start = find_body_start(beginning_of_source)
|
60
|
+
insertion_index = find_x_ua_compatible_position(beginning_of_source) ||
|
61
|
+
find_end_of_head_open(beginning_of_source) ||
|
62
|
+
body_start
|
63
|
+
|
64
|
+
if insertion_index
|
65
|
+
source = source[0...insertion_index] <<
|
66
|
+
NewRelic::Agent.browser_timing_footer << # sic, footer is now considered "config". Rename soon?
|
67
|
+
NewRelic::Agent.browser_timing_header <<
|
68
|
+
source[insertion_index..-1]
|
91
69
|
else
|
92
|
-
|
93
|
-
::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Failed to detect head tags."
|
94
|
-
else
|
95
|
-
::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Detected head is after detected body close."
|
96
|
-
end
|
70
|
+
NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Could not properly determine location to inject script."
|
97
71
|
end
|
72
|
+
else
|
73
|
+
NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Unable to find <body> tag in document."
|
98
74
|
end
|
99
75
|
|
100
76
|
if headers['Content-Length']
|
@@ -104,6 +80,34 @@ module NewRelic::Rack
|
|
104
80
|
source
|
105
81
|
end
|
106
82
|
|
83
|
+
def gather_source(response)
|
84
|
+
source = nil
|
85
|
+
response.each {|fragment| source ? (source << fragment.to_s) : (source = fragment.to_s)}
|
86
|
+
source
|
87
|
+
end
|
88
|
+
|
89
|
+
# Per "The Response > The Body" section of Rack spec, we should close
|
90
|
+
# if our response is able. http://rack.rubyforge.org/doc/SPEC.html
|
91
|
+
def close_old_response(response)
|
92
|
+
if response.respond_to?(:close)
|
93
|
+
response.close
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def find_body_start(beginning_of_source)
|
98
|
+
beginning_of_source.index("<body")
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_x_ua_compatible_position(beginning_of_source)
|
102
|
+
match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
|
103
|
+
match.end(0) if match
|
104
|
+
end
|
105
|
+
|
106
|
+
def find_end_of_head_open(beginning_of_source)
|
107
|
+
head_open = beginning_of_source.index("<head")
|
108
|
+
beginning_of_source.index(">", head_open) + 1 if head_open
|
109
|
+
end
|
110
|
+
|
107
111
|
# String does not respond to 'bytesize' in 1.8.6. Fortunately String#length
|
108
112
|
# returns bytes rather than characters in 1.8.6 so we can use that instead.
|
109
113
|
def calculate_content_length(source)
|
data/lib/new_relic/version.rb
CHANGED
data/lib/tasks/install.rake
CHANGED
data/test/agent_helper.rb
CHANGED
@@ -326,7 +326,7 @@ end
|
|
326
326
|
|
327
327
|
def wait_for_backtrace_service_poll(opts={})
|
328
328
|
defaults = {
|
329
|
-
:timeout =>
|
329
|
+
:timeout => 10.0,
|
330
330
|
:service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
|
331
331
|
:iterations => 1
|
332
332
|
}
|
@@ -335,7 +335,7 @@ def wait_for_backtrace_service_poll(opts={})
|
|
335
335
|
until opts[:service].worker_loop.iterations > opts[:iterations]
|
336
336
|
sleep(0.01)
|
337
337
|
if Time.now > deadline
|
338
|
-
raise "Timed out waiting #{timeout} s for backtrace service poll"
|
338
|
+
raise "Timed out waiting #{opts[:timeout]} s for backtrace service poll"
|
339
339
|
end
|
340
340
|
end
|
341
341
|
end
|
@@ -207,7 +207,17 @@ module Multiverse
|
|
207
207
|
options << "-v" if verbose?
|
208
208
|
options << "--seed=#{seed}" unless seed == ""
|
209
209
|
options << "--name=/#{names.map {|n| n + ".*"}.join("|")}/" unless names == []
|
210
|
-
|
210
|
+
|
211
|
+
original_options = options.dup
|
212
|
+
test_run = ::MiniTest::Unit.new.run(options)
|
213
|
+
|
214
|
+
if test_run
|
215
|
+
exit(test_run)
|
216
|
+
else
|
217
|
+
puts "No tests found with those options."
|
218
|
+
puts "options: #{original_options}"
|
219
|
+
exit(1)
|
220
|
+
end
|
211
221
|
end
|
212
222
|
|
213
223
|
def configure_before_bundling
|
@@ -14,8 +14,13 @@ class RumAutoTest < MiniTest::Unit::TestCase
|
|
14
14
|
include Rack::Test::Methods
|
15
15
|
include MultiverseHelpers
|
16
16
|
|
17
|
+
JS_AGENT_LOADER = "JS_AGENT_LOADER"
|
18
|
+
|
19
|
+
LOADER_REGEX = "\n<script.*>JS_AGENT_LOADER</script>"
|
20
|
+
CONFIG_REGEX = "\n<script.*>.*NREUM.info=.*</script>"
|
21
|
+
|
17
22
|
setup_and_teardown_agent(:browser_key => 'browserKey', :application_id => 'appId',
|
18
|
-
:beacon => 'beacon', :
|
23
|
+
:beacon => 'beacon', :js_agent_loader => JS_AGENT_LOADER)
|
19
24
|
|
20
25
|
def after_setup
|
21
26
|
@inner_app = TestingApp.new
|
@@ -25,36 +30,31 @@ class RumAutoTest < MiniTest::Unit::TestCase
|
|
25
30
|
def test_autoinstrumentation_is_active
|
26
31
|
@inner_app.response = "<html><head><title>W00t!</title></head><body><p>Hello World</p></body></html>"
|
27
32
|
get '/'
|
28
|
-
|
29
|
-
assert(last_response.body =~ %r|NREUMQ|, "response body should include RUM auto instrumentation js:\n #{last_response.body}")
|
33
|
+
assert_response_includes("<script", JS_AGENT_LOADER, "NREUM")
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_autoinstrumentation_with_basic_page_puts_header_at_beginning_of_head
|
33
37
|
@inner_app.response = "<html><head><title>foo</title></head><body><p>Hello World</p></body></html>"
|
34
|
-
NewRelic::Agent.logger.debug("================================")
|
35
38
|
get '/'
|
36
|
-
|
37
|
-
assert(last_response.body.include?('<html><head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script><title>foo</title></head><body>'))
|
39
|
+
assert_response_includes(%Q[<html><head>#{CONFIG_REGEX}#{LOADER_REGEX}<title>foo</title></head>])
|
38
40
|
end
|
39
41
|
|
40
42
|
def test_autoinstrumentation_with_body_only_puts_header_before_body
|
41
43
|
@inner_app.response = "<html><body><p>Hello World</p></body></html>"
|
42
44
|
get '/'
|
43
|
-
|
45
|
+
assert_response_includes %Q[<html>#{CONFIG_REGEX}#{LOADER_REGEX}<body>]
|
44
46
|
end
|
45
47
|
|
46
48
|
def test_autoinstrumentation_with_X_UA_Compatible_puts_header_after_meta_tag
|
47
|
-
@inner_app.response = '<html><head><meta http-equiv="X-UA-Compatible"
|
49
|
+
@inner_app.response = '<html><head><meta http-equiv="X-UA-Compatible"/></head><body><p>Hello World</p></body></html>'
|
48
50
|
get '/'
|
49
|
-
|
50
|
-
'<html><head><meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" /><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script></head><body>'
|
51
|
-
))
|
51
|
+
assert_response_includes(%Q[<html><head><meta http-equiv="X-UA-Compatible"/>#{CONFIG_REGEX}#{LOADER_REGEX}</head><body>])
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_autoinstrumentation_doesnt_run_for_crazy_shit_like_this
|
55
55
|
@inner_app.response = '<html><head <body </body>'
|
56
56
|
get '/'
|
57
|
-
|
57
|
+
assert_response_includes('<html><head <body </body>')
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_content_length_is_correctly_set_if_present
|
@@ -73,4 +73,11 @@ class RumAutoTest < MiniTest::Unit::TestCase
|
|
73
73
|
get '/'
|
74
74
|
assert_equal(last_response.body, body)
|
75
75
|
end
|
76
|
+
|
77
|
+
def assert_response_includes(*texts)
|
78
|
+
texts.each do |text|
|
79
|
+
assert_match(Regexp.new(text), last_response.body,
|
80
|
+
"Response missing #{text} for JS Agent instrumentation:\n #{last_response.body}")
|
81
|
+
end
|
82
|
+
end
|
76
83
|
end
|
@@ -22,7 +22,7 @@ class QueueTimeTest < ActionDispatch::IntegrationTest
|
|
22
22
|
|
23
23
|
include MultiverseHelpers
|
24
24
|
|
25
|
-
setup_and_teardown_agent(:beacon => "beacon", :browser_key => "key")
|
25
|
+
setup_and_teardown_agent(:beacon => "beacon", :browser_key => "key", :js_agent_loader => "loader")
|
26
26
|
|
27
27
|
def test_should_track_queue_time_metric
|
28
28
|
get_queued
|
@@ -43,7 +43,8 @@ class QueueTimeTest < ActionDispatch::IntegrationTest
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def extract_queue_time_from_response
|
46
|
-
@response.body =~
|
46
|
+
@response.body =~ /\"queueTime\":(\d+.*)/
|
47
|
+
refute_nil $1, "Should have found queue time in #{@response.body.inspect}"
|
47
48
|
$1.to_i
|
48
49
|
end
|
49
50
|
end
|
@@ -16,6 +16,11 @@ class RequestStatsController < ApplicationController
|
|
16
16
|
sleep 0.01
|
17
17
|
render :text => 'some stuff'
|
18
18
|
end
|
19
|
+
|
20
|
+
def stats_action_with_custom_params
|
21
|
+
::NewRelic::Agent.add_custom_parameters('color' => 'blue', 1 => :bar, 'bad' => {})
|
22
|
+
render :text => 'some stuff'
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
class RequestStatsTest < ActionController::TestCase
|
@@ -62,6 +67,30 @@ class RequestStatsTest < ActionController::TestCase
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
70
|
+
def test_custom_params_should_be_reported_with_events_and_coerced_to_safe_types
|
71
|
+
with_config( :'analytics_events.enabled' => true ) do
|
72
|
+
20.times { get :stats_action_with_custom_params }
|
73
|
+
|
74
|
+
NewRelic::Agent.agent.send(:harvest_and_send_analytic_event_data)
|
75
|
+
|
76
|
+
post = $collector.calls_for('analytic_event_data').first
|
77
|
+
|
78
|
+
refute_nil( post )
|
79
|
+
assert_kind_of Array, post.body
|
80
|
+
assert_kind_of Array, post.body.first
|
81
|
+
|
82
|
+
sample = post.body.first.first
|
83
|
+
assert_kind_of Hash, sample
|
84
|
+
|
85
|
+
assert_equal 'Controller/request_stats/stats_action_with_custom_params', sample['name']
|
86
|
+
assert_encoding 'utf-8', sample['name']
|
87
|
+
assert_equal 'Transaction', sample['type']
|
88
|
+
assert_equal 'blue', sample['color']
|
89
|
+
assert_equal 'bar', sample['1']
|
90
|
+
assert_false sample.has_key?('bad')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
65
94
|
def test_request_samples_should_be_preserved_upon_failure
|
66
95
|
with_config(:'analytics_events.enabled' => true) do
|
67
96
|
5.times { get :stats_action }
|
@@ -3,7 +3,16 @@ suite_condition("SideKiq requires MRI 1.9.3 or JRuby 1.6 in 1.9 mode") do
|
|
3
3
|
end
|
4
4
|
|
5
5
|
gemfile <<-RB
|
6
|
+
# Latest version
|
6
7
|
gem 'json'
|
7
|
-
gem 'sidekiq'
|
8
|
+
gem 'sidekiq', '~> 2.16.1'
|
9
|
+
gem 'rack'
|
10
|
+
RB
|
11
|
+
|
12
|
+
gemfile <<-RB
|
13
|
+
# Almost oldest supported version
|
14
|
+
# Having rbx issues on 2.8.0, 2.9.0 seems fine.
|
15
|
+
gem 'json'
|
16
|
+
gem 'sidekiq', '~> 2.9.0'
|
8
17
|
gem 'rack'
|
9
18
|
RB
|
@@ -1,18 +1,14 @@
|
|
1
|
-
suite_condition("Sinatra not compatible with 1.8.6") do
|
2
|
-
RUBY_VERSION != '1.8.6'
|
3
|
-
end
|
4
|
-
|
5
1
|
gemfile <<-RB
|
6
|
-
gem 'sinatra', '~> 1.4.
|
2
|
+
gem 'sinatra', '~> 1.4.4'
|
7
3
|
gem 'rack-test', :require => 'rack/test'
|
8
4
|
RB
|
9
5
|
|
10
6
|
gemfile <<-RB
|
11
|
-
gem 'sinatra', '~> 1.3.
|
7
|
+
gem 'sinatra', '~> 1.3.6'
|
12
8
|
gem 'rack-test', :require => 'rack/test'
|
13
9
|
RB
|
14
10
|
|
15
11
|
gemfile <<-RB
|
16
|
-
gem 'sinatra', '~> 1.2.
|
12
|
+
gem 'sinatra', '~> 1.2.9'
|
17
13
|
gem 'rack-test', :require => 'rack/test'
|
18
14
|
RB
|
@@ -4,13 +4,13 @@
|
|
4
4
|
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
6
6
|
require "new_relic/agent/beacon_configuration"
|
7
|
+
|
7
8
|
class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
8
9
|
def test_initialize_basic
|
9
10
|
with_config(:application_id => 'an application id',
|
10
11
|
:beacon => 'beacon', :'rum.enabled' => true) do
|
11
12
|
bc = NewRelic::Agent::BeaconConfiguration.new
|
12
13
|
assert_equal true, bc.enabled?
|
13
|
-
assert_equal '', bc.browser_timing_header
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -19,93 +19,26 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
19
19
|
:beacon => 'beacon', :'rum.enabled' => true) do
|
20
20
|
bc = NewRelic::Agent::BeaconConfiguration.new
|
21
21
|
assert bc.enabled?
|
22
|
-
s = "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
|
23
|
-
assert_equal(s, bc.browser_timing_header)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
|
28
|
-
with_config(:license_key => 'a' * 40) do
|
29
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
30
|
-
assert_equal([97] * 40, bc.license_bytes, 'should return the bytes of the license key')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_license_bytes_existing_bytes
|
35
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
36
|
-
bc.instance_eval { @license_bytes = [97] * 40 }
|
37
|
-
NewRelic::Agent.config.expects(:[]).with('license_key').never
|
38
|
-
assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
|
39
|
-
end
|
25
|
+
ARRAY_OF_A = [97] * 40
|
40
26
|
|
41
|
-
def
|
27
|
+
def test_license_bytes
|
42
28
|
with_config(:license_key => 'a' * 40) do
|
43
29
|
bc = NewRelic::Agent::BeaconConfiguration.new
|
44
|
-
bc.
|
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
|
-
end
|
49
|
-
|
50
|
-
def test_build_browser_timing_header_disabled
|
51
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
52
|
-
bc.instance_eval { @rum_enabled = false }
|
53
|
-
assert_equal '', bc.build_browser_timing_header, "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
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
58
|
-
bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = nil }
|
59
|
-
assert_equal '', bc.build_browser_timing_header, "should not return a header when browser_monitoring_key is nil"
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_build_browser_timing_header_enabled_with_key
|
63
|
-
with_config(:browser_key => 'a browser monitoring key', :beacon => 'beacon') do
|
64
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
65
|
-
assert(bc.build_browser_timing_header.include?('NREUMQ'),
|
66
|
-
"header should be generated when rum is enabled and browser monitoring key is set")
|
30
|
+
assert_equal(ARRAY_OF_A, bc.license_bytes)
|
67
31
|
end
|
68
32
|
end
|
69
33
|
|
70
|
-
def
|
71
|
-
with_config(:
|
72
|
-
mock_javascript = mock('javascript')
|
73
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
74
|
-
bc.expects(:javascript_header).returns(mock_javascript)
|
75
|
-
mock_javascript.expects(:respond_to?).with(:html_safe).returns(true)
|
76
|
-
mock_javascript.expects(:html_safe)
|
77
|
-
bc.build_browser_timing_header
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_build_load_file_js_load_episodes_file_false
|
82
|
-
with_config(:'rum.load_episodes_file' => false) do
|
34
|
+
def test_license_bytes_are_memoized
|
35
|
+
with_config(:license_key => 'a' * 40) do
|
83
36
|
bc = NewRelic::Agent::BeaconConfiguration.new
|
84
|
-
|
85
|
-
assert_equal(s, bc.build_load_file_js)
|
86
|
-
end
|
87
|
-
end
|
37
|
+
assert_equal(ARRAY_OF_A, bc.license_bytes)
|
88
38
|
|
89
|
-
|
90
|
-
|
91
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
92
|
-
s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
|
93
|
-
assert_equal(s, bc.build_load_file_js)
|
39
|
+
NewRelic::Agent.config.apply_config(:license_key => 'b' * 40)
|
40
|
+
assert_equal(ARRAY_OF_A, bc.license_bytes)
|
94
41
|
end
|
95
42
|
end
|
96
43
|
|
97
|
-
def test_build_load_file_js_load_episodes_file_present
|
98
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
99
|
-
# s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";e.async=true;e.src=\"\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
|
100
|
-
s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";\ne.src=((\"http:\"===document.location.protocol)?\"http:\":\"https:\") + \"//\" +\n \"\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
|
101
|
-
assert_equal(s, bc.build_load_file_js)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_build_load_file_js_load_episodes_file_with_episodes_file
|
105
|
-
with_config(:episodes_file => 'an episodes url') do
|
106
|
-
bc = NewRelic::Agent::BeaconConfiguration.new
|
107
|
-
assert(bc.build_load_file_js.include?('an episodes url'),
|
108
|
-
"should include the episodes url by default")
|
109
|
-
end
|
110
|
-
end
|
111
44
|
end
|