newrelic_rpm 3.2.0.1 → 3.3.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +7 -3
- data/LICENSE +2 -29
- data/README.rdoc +2 -2
- data/lib/new_relic/agent.rb +14 -0
- data/lib/new_relic/agent/agent.rb +19 -9
- data/lib/new_relic/agent/beacon_configuration.rb +11 -0
- data/lib/new_relic/agent/browser_monitoring.rb +53 -13
- data/lib/new_relic/agent/database.rb +11 -1
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +3 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +23 -2
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +15 -12
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +11 -8
- data/lib/new_relic/agent/sql_sampler.rb +19 -7
- data/lib/new_relic/agent/stats_engine.rb +1 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +120 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -85
- data/lib/new_relic/agent/transaction_info.rb +49 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +2 -0
- data/lib/new_relic/agent/transaction_sampler.rb +65 -7
- data/lib/new_relic/rack/browser_monitoring.rb +38 -8
- data/lib/new_relic/transaction_sample.rb +8 -6
- data/lib/new_relic/version.rb +2 -2
- data/newrelic.yml +1 -1
- data/newrelic_rpm.gemspec +6 -3
- data/test/new_relic/agent/agent/connect_test.rb +4 -11
- data/test/new_relic/agent/beacon_configuration_test.rb +10 -7
- data/test/new_relic/agent/browser_monitoring_test.rb +69 -44
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +12 -8
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -1
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +3 -3
- data/test/new_relic/agent/sql_sampler_test.rb +25 -10
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_sampler_test.rb +22 -12
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +7 -1
- metadata +321 -337
@@ -10,18 +10,47 @@ module NewRelic::Rack
|
|
10
10
|
# method required by Rack interface
|
11
11
|
def call(env)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
req = Rack::Request.new(env)
|
14
|
+
|
15
|
+
# clear any previous transaction info
|
16
|
+
NewRelic::Agent::TransactionInfo.clear
|
17
|
+
|
18
|
+
agent_flag = req.cookies['NRAGENT']
|
19
|
+
|
20
|
+
if agent_flag
|
21
|
+
s = agent_flag.split("=")
|
22
|
+
if s.length == 2
|
23
|
+
if s[0] == "tk" && s[1]
|
24
|
+
NewRelic::Agent::TransactionInfo.get.token = s[1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Two experimental options for allowing TT capture based on http params
|
30
|
+
#
|
31
|
+
if req.params['nr_capture_deep_tt']
|
32
|
+
# NewRelic::Agent::TransactionInfo.get.force_persist = true
|
33
|
+
# NewRelic::Agent::TransactionInfo.get.capture_deep_tt = true
|
34
|
+
end
|
35
|
+
|
36
|
+
if req.params['nr_capture_tt']
|
37
|
+
# NewRelic::Agent::TransactionInfo.get.force_persist = true
|
38
|
+
end
|
17
39
|
|
18
40
|
result = @app.call(env) # [status, headers, response]
|
19
|
-
|
41
|
+
|
20
42
|
if (NewRelic::Agent.browser_timing_header != "") && should_instrument?(result[0], result[1])
|
21
43
|
response_string = autoinstrument_source(result[2], result[1])
|
22
44
|
|
23
|
-
if
|
24
|
-
Rack::Response.new(response_string, result[0], result[1])
|
45
|
+
if response_string
|
46
|
+
response = Rack::Response.new(response_string, result[0], result[1])
|
47
|
+
|
48
|
+
if NewRelic::Agent::TransactionInfo.get.token
|
49
|
+
# clear the cookie via expiration in the past
|
50
|
+
response.set_cookie("NRAGENT", {:value => "tk=", :path => "/", :expires => Time.now-(24* 60*60)})
|
51
|
+
end
|
52
|
+
|
53
|
+
response.finish
|
25
54
|
else
|
26
55
|
result
|
27
56
|
end
|
@@ -36,7 +65,7 @@ module NewRelic::Rack
|
|
36
65
|
|
37
66
|
def autoinstrument_source(response, headers)
|
38
67
|
source = nil
|
39
|
-
response.each {|fragment|
|
68
|
+
response.each {|fragment| source ? (source << fragment.to_s) : (source = fragment.to_s)}
|
40
69
|
return nil unless source
|
41
70
|
|
42
71
|
body_start = source.index("<body")
|
@@ -65,4 +94,5 @@ module NewRelic::Rack
|
|
65
94
|
source
|
66
95
|
end
|
67
96
|
end
|
97
|
+
|
68
98
|
end
|
@@ -9,11 +9,8 @@ module NewRelic
|
|
9
9
|
|
10
10
|
class TransactionSample
|
11
11
|
|
12
|
-
attr_accessor :params, :root_segment
|
13
|
-
|
14
|
-
attr_reader :root_segment
|
15
|
-
attr_reader :params
|
16
|
-
attr_reader :sample_id
|
12
|
+
attr_accessor :params, :root_segment, :profile, :force_persist, :guid
|
13
|
+
attr_reader :root_segment, :params, :sample_id
|
17
14
|
|
18
15
|
@@start_time = Time.now
|
19
16
|
|
@@ -25,12 +22,15 @@ module NewRelic
|
|
25
22
|
@root_segment = create_segment 0.0, "ROOT"
|
26
23
|
@params = {}
|
27
24
|
@params[:request_params] = {}
|
25
|
+
|
26
|
+
@guid = (0..15).to_a.map{|a| rand(16).to_s(16)}.join # a 64 bit random GUID
|
27
|
+
NewRelic::Agent::TransactionInfo.get.guid = @guid
|
28
28
|
end
|
29
29
|
|
30
30
|
def count_segments
|
31
31
|
@root_segment.count_segments - 1 # don't count the root segment
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Truncates the transaction sample to a maximum length determined
|
35
35
|
# by the passed-in parameter. Operates recursively on the entire
|
36
36
|
# tree of transaction segments in a depth-first manner
|
@@ -154,6 +154,8 @@ module NewRelic
|
|
154
154
|
sample = TransactionSample.new(@start_time, sample_id)
|
155
155
|
|
156
156
|
sample.params.merge! self.params
|
157
|
+
sample.guid = self.guid
|
158
|
+
sample.force_persist = self.force_persist if self.force_persist
|
157
159
|
|
158
160
|
begin
|
159
161
|
build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
|
data/lib/new_relic/version.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
module NewRelic
|
3
3
|
module VERSION #:nodoc:
|
4
4
|
MAJOR = 3
|
5
|
-
MINOR =
|
5
|
+
MINOR = 3
|
6
6
|
TINY = 0
|
7
|
-
BUILD =
|
7
|
+
BUILD = 'beta1' #'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.yml
CHANGED
@@ -96,7 +96,7 @@ common: &default_settings
|
|
96
96
|
# as Tolerating transactions; and more than four times the apdex_t
|
97
97
|
# value as Frustrating transactions.
|
98
98
|
# For more about the Apdex standard, see
|
99
|
-
# http://newrelic.com/
|
99
|
+
# http://support.newrelic.com/faqs/general/apdex
|
100
100
|
|
101
101
|
apdex_t: 0.5
|
102
102
|
|
data/newrelic_rpm.gemspec
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "3.
|
7
|
+
s.name = %q{newrelic_rpm}
|
8
|
+
s.version = "3.3.0.beta1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Bill Kayser}, %q{Jon Guymon}, %q{Justin George}, %q{Darin Swanson}]
|
@@ -81,9 +81,11 @@ http://github.com/newrelic/rpm/
|
|
81
81
|
"lib/new_relic/agent/shim_agent.rb",
|
82
82
|
"lib/new_relic/agent/sql_sampler.rb",
|
83
83
|
"lib/new_relic/agent/stats_engine.rb",
|
84
|
+
"lib/new_relic/agent/stats_engine/gc_profiler.rb",
|
84
85
|
"lib/new_relic/agent/stats_engine/metric_stats.rb",
|
85
86
|
"lib/new_relic/agent/stats_engine/samplers.rb",
|
86
87
|
"lib/new_relic/agent/stats_engine/transactions.rb",
|
88
|
+
"lib/new_relic/agent/transaction_info.rb",
|
87
89
|
"lib/new_relic/agent/transaction_sample_builder.rb",
|
88
90
|
"lib/new_relic/agent/transaction_sampler.rb",
|
89
91
|
"lib/new_relic/agent/worker_loop.rb",
|
@@ -188,6 +190,7 @@ http://github.com/newrelic/rpm/
|
|
188
190
|
"test/new_relic/delayed_job_injection_test.rb",
|
189
191
|
"test/new_relic/local_environment_test.rb",
|
190
192
|
"test/new_relic/metric_data_test.rb",
|
193
|
+
"test/new_relic/metric_parser/metric_parser_test.rb",
|
191
194
|
"test/new_relic/metric_spec_test.rb",
|
192
195
|
"test/new_relic/rack/all_test.rb",
|
193
196
|
"test/new_relic/rack/browser_monitoring_test.rb",
|
@@ -302,7 +305,7 @@ Refer to the README.md file for more information.
|
|
302
305
|
|
303
306
|
Please see http://github.com/newrelic/rpm/blob/master/CHANGELOG
|
304
307
|
for a complete description of the features and enhancements available
|
305
|
-
in version 3.
|
308
|
+
in version 3.3 of the Ruby Agent.
|
306
309
|
|
307
310
|
}
|
308
311
|
s.rubygems_version = %q{1.3.6}
|
@@ -230,18 +230,20 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
230
230
|
@config_should_send_samples = true
|
231
231
|
@should_send_random_samples = true
|
232
232
|
@slowest_transaction_threshold = 5
|
233
|
-
log.
|
233
|
+
log.stubs(:debug)
|
234
234
|
self.expects(:enable_random_samples!).with(10)
|
235
235
|
configure_transaction_tracer!(true, 10)
|
236
236
|
assert @should_send_samples
|
237
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
237
238
|
end
|
238
239
|
|
239
240
|
def test_configure_transaction_tracer_positive
|
240
241
|
@config_should_send_samples = true
|
241
242
|
@slowest_transaction_threshold = 5
|
242
|
-
log.
|
243
|
+
log.stubs(:debug)
|
243
244
|
configure_transaction_tracer!(true, 10)
|
244
245
|
assert @should_send_samples
|
246
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
245
247
|
end
|
246
248
|
|
247
249
|
def test_configure_transaction_tracer_negative
|
@@ -338,15 +340,6 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
338
340
|
assert_equal 'initial value', @collector, "should not modify collector value"
|
339
341
|
end
|
340
342
|
|
341
|
-
def test_configure_transaction_tracer_random_samples
|
342
|
-
@config_should_send_samples = true
|
343
|
-
@should_send_random_samples = true
|
344
|
-
self.expects(:enable_random_samples!).with(10)
|
345
|
-
log.expects(:debug)
|
346
|
-
configure_transaction_tracer!(true, 10)
|
347
|
-
assert @should_send_samples
|
348
|
-
end
|
349
|
-
|
350
343
|
def test_query_server_for_configuration
|
351
344
|
self.expects(:set_collector_host!)
|
352
345
|
self.expects(:connect_to_server).returns("so happy")
|
@@ -19,7 +19,8 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
19
19
|
assert_equal('a browser monitoring key', bc.browser_monitoring_key)
|
20
20
|
assert_equal('an application id', bc.application_id)
|
21
21
|
assert_equal('a beacon', bc.beacon)
|
22
|
-
|
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)
|
23
24
|
end
|
24
25
|
|
25
26
|
def test_license_bytes_nil
|
@@ -81,22 +82,24 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
81
82
|
def test_build_load_file_js_load_episodes_file_false
|
82
83
|
connect_data = {'rum.load_episodes_file' => false}
|
83
84
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
84
|
-
|
85
|
-
|
85
|
+
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"
|
86
|
+
assert_equal(s, bc.build_load_file_js(connect_data))
|
86
87
|
end
|
87
88
|
|
88
89
|
def test_build_load_file_js_load_episodes_file_missing
|
89
90
|
connect_data = {}
|
90
91
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
91
|
-
|
92
|
-
|
92
|
+
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"
|
93
|
+
|
94
|
+
assert_equal(s, bc.build_load_file_js(connect_data))
|
93
95
|
end
|
94
96
|
|
95
97
|
def test_build_load_file_js_load_episodes_file_present
|
96
98
|
connect_data = {'rum.load_episodes_file' => true}
|
97
99
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
98
|
-
|
99
|
-
|
100
|
+
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"
|
101
|
+
|
102
|
+
assert_equal(s, bc.build_load_file_js(connect_data))
|
100
103
|
end
|
101
104
|
|
102
105
|
def test_build_load_file_js_load_episodes_file_with_episodes_url
|
@@ -4,7 +4,8 @@ require "new_relic/agent/browser_monitoring"
|
|
4
4
|
|
5
5
|
class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
6
6
|
include NewRelic::Agent::BrowserMonitoring
|
7
|
-
|
7
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
8
|
+
|
8
9
|
def setup
|
9
10
|
NewRelic::Agent.manual_start
|
10
11
|
@browser_monitoring_key = "fred"
|
@@ -12,14 +13,12 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
12
13
|
NewRelic::Agent.instance.instance_eval do
|
13
14
|
@beacon_configuration = NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"})
|
14
15
|
end
|
15
|
-
Thread.current[:
|
16
|
+
Thread.current[:last_metric_frame] = nil
|
17
|
+
NewRelic::Agent::TransactionInfo.clear
|
16
18
|
end
|
17
19
|
|
18
20
|
def teardown
|
19
21
|
mocha_teardown
|
20
|
-
Thread.current[:newrelic_start_time] = nil
|
21
|
-
Thread.current[:newrelic_metric_frame] = nil
|
22
|
-
Thread.current[:newrelic_most_recent_transaction] = nil
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_browser_timing_header_with_no_beacon_configuration
|
@@ -65,8 +64,6 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
65
64
|
browser_timing_header
|
66
65
|
NewRelic::Control.instance.expects(:license_key).returns("a" * 13)
|
67
66
|
|
68
|
-
Thread.current[:newrelic_start_time] = Time.now
|
69
|
-
|
70
67
|
footer = browser_timing_footer
|
71
68
|
snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
|
72
69
|
NREUMQ.push(["load",new Date().getTime()]);
|
@@ -74,11 +71,6 @@ var e=document.createElement("script");'
|
|
74
71
|
assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
|
75
72
|
end
|
76
73
|
|
77
|
-
def test_browser_timing_footer_without_calling_header
|
78
|
-
Thread.current[:newrelic_start_time] = nil
|
79
|
-
assert_equal "", browser_timing_footer
|
80
|
-
end
|
81
|
-
|
82
74
|
def test_browser_timing_footer_with_no_browser_key_rum_enabled
|
83
75
|
browser_timing_header
|
84
76
|
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"}))
|
@@ -95,7 +87,6 @@ var e=document.createElement("script");'
|
|
95
87
|
|
96
88
|
def test_browser_timing_footer_with_rum_enabled_not_specified
|
97
89
|
browser_timing_header
|
98
|
-
Thread.current[:newrelic_start_time] = Time.now
|
99
90
|
|
100
91
|
license_bytes = [];
|
101
92
|
("a" * 13).each_byte {|byte| license_bytes << byte}
|
@@ -118,14 +109,6 @@ var e=document.createElement("script");'
|
|
118
109
|
assert_equal "", footer
|
119
110
|
end
|
120
111
|
|
121
|
-
def test_browser_timing_footer_with_no_start_time
|
122
|
-
browser_timing_header
|
123
|
-
Thread.current[:newrelic_start_time] = nil
|
124
|
-
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"}))
|
125
|
-
footer = browser_timing_footer
|
126
|
-
assert_equal('', footer)
|
127
|
-
end
|
128
|
-
|
129
112
|
|
130
113
|
def test_browser_timing_footer_disable_all_tracing
|
131
114
|
browser_timing_header
|
@@ -157,37 +140,62 @@ var e=document.createElement("script");'
|
|
157
140
|
|
158
141
|
def test_generate_footer_js_null_case
|
159
142
|
self.expects(:browser_monitoring_start_time).returns(nil)
|
160
|
-
assert_equal('', generate_footer_js, "should not send javascript when there is no start time")
|
143
|
+
assert_equal('', generate_footer_js(NewRelic::Agent.instance.beacon_configuration), "should not send javascript when there is no start time")
|
161
144
|
end
|
162
|
-
|
145
|
+
|
163
146
|
def test_generate_footer_js_with_start_time
|
164
147
|
self.expects(:browser_monitoring_start_time).returns(Time.at(100))
|
165
148
|
fake_bc = mock('beacon configuration')
|
166
149
|
fake_bc.expects(:application_id).returns(1)
|
167
150
|
fake_bc.expects(:beacon).returns('beacon')
|
168
151
|
fake_bc.expects(:browser_monitoring_key).returns('a' * 40)
|
169
|
-
NewRelic::Agent.instance.
|
170
|
-
self.expects(:footer_js_string).with('beacon', 'a' * 40, 1).returns('footer js')
|
171
|
-
assert_equal('footer js', generate_footer_js, 'should generate and return the footer JS when there is a start time')
|
152
|
+
NewRelic::Agent.instance.stubs(:beacon_configuration).returns(fake_bc)
|
153
|
+
self.expects(:footer_js_string).with(NewRelic::Agent.instance.beacon_configuration, 'beacon', 'a' * 40, 1).returns('footer js')
|
154
|
+
assert_equal('footer js', generate_footer_js(NewRelic::Agent.instance.beacon_configuration), 'should generate and return the footer JS when there is a start time')
|
172
155
|
end
|
173
156
|
|
174
157
|
def test_browser_monitoring_transaction_name_basic
|
175
|
-
|
158
|
+
mock = mock('transaction sample')
|
159
|
+
NewRelic::Agent::TransactionInfo.set(mock)
|
160
|
+
mock.stubs(:transaction_name).returns('a transaction name')
|
161
|
+
|
176
162
|
assert_equal('a transaction name', browser_monitoring_transaction_name, "should take the value from the thread local")
|
177
163
|
end
|
178
164
|
|
179
165
|
def test_browser_monitoring_transaction_name_empty
|
180
|
-
|
166
|
+
mock = mock('transaction sample')
|
167
|
+
NewRelic::Agent::TransactionInfo.set(mock)
|
168
|
+
|
169
|
+
mock.stubs(:transaction_name).returns('')
|
181
170
|
assert_equal('', browser_monitoring_transaction_name, "should take the value even when it is empty")
|
182
171
|
end
|
183
172
|
|
184
173
|
def test_browser_monitoring_transaction_name_nil
|
185
|
-
|
186
|
-
assert_equal('<unknown>', browser_monitoring_transaction_name, "should fill in a default when it is nil")
|
174
|
+
assert_equal('(unknown)', browser_monitoring_transaction_name, "should fill in a default when it is nil")
|
187
175
|
end
|
176
|
+
|
177
|
+
def test_browser_monitoring_transaction_name_when_tt_disabled
|
178
|
+
@sampler = NewRelic::Agent.instance.transaction_sampler
|
179
|
+
@sampler.disable
|
188
180
|
|
181
|
+
perform_action_with_newrelic_trace(:name => 'disabled_transactions') do
|
182
|
+
self.class.inspect
|
183
|
+
end
|
184
|
+
|
185
|
+
assert_match(/disabled_transactions/, browser_monitoring_transaction_name,
|
186
|
+
"should name transaction when transaction tracing disabled")
|
187
|
+
ensure
|
188
|
+
@sampler.enable
|
189
|
+
end
|
190
|
+
|
191
|
+
|
189
192
|
def test_browser_monitoring_start_time
|
190
|
-
|
193
|
+
mock = mock('transaction info')
|
194
|
+
|
195
|
+
NewRelic::Agent::TransactionInfo.set(mock)
|
196
|
+
|
197
|
+
mock.stubs(:start_time).returns(Time.at(100))
|
198
|
+
mock.stubs(:guid).returns('ABC')
|
191
199
|
assert_equal(Time.at(100), browser_monitoring_start_time, "should take the value from the thread local")
|
192
200
|
end
|
193
201
|
|
@@ -205,22 +213,24 @@ var e=document.createElement("script");'
|
|
205
213
|
end
|
206
214
|
|
207
215
|
def test_browser_monitoring_queue_time_nil
|
208
|
-
Thread.current[:newrelic_queue_time] = nil
|
209
216
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is no queue time')
|
210
217
|
end
|
211
218
|
|
212
219
|
def test_browser_monitoring_queue_time_zero
|
213
|
-
Thread.current[:
|
220
|
+
frame = Thread.current[:last_metric_frame] = mock('metric frame')
|
221
|
+
frame.expects(:queue_time).returns(0.0)
|
214
222
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is zero queue time')
|
215
223
|
end
|
216
224
|
|
217
225
|
def test_browser_monitoring_queue_time_ducks
|
218
|
-
Thread.current[:
|
226
|
+
frame = Thread.current[:last_metric_frame] = mock('metric frame')
|
227
|
+
frame.expects(:queue_time).returns('a duck')
|
219
228
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is an incorrect queue time')
|
220
229
|
end
|
221
230
|
|
222
231
|
def test_browser_monitoring_queue_time_nonzero
|
223
|
-
Thread.current[:
|
232
|
+
frame = Thread.current[:last_metric_frame] = mock('metric frame')
|
233
|
+
frame.expects(:queue_time).returns(3.00002)
|
224
234
|
assert_equal(3000, browser_monitoring_queue_time, 'should return a rounded time')
|
225
235
|
end
|
226
236
|
|
@@ -229,16 +239,31 @@ var e=document.createElement("script");'
|
|
229
239
|
license_key = ''
|
230
240
|
application_id = 1
|
231
241
|
|
232
|
-
Thread.current[:newrelic_queue_time] = nil
|
233
242
|
# mocking this because JRuby thinks that Time.now - Time.now
|
234
243
|
# always takes at least 1ms
|
235
244
|
self.expects(:browser_monitoring_app_time).returns(0)
|
236
|
-
Thread.current[:
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
245
|
+
frame = Thread.current[:last_metric_frame] = mock('metric frame')
|
246
|
+
user_attributes = {:user => "user", :account => "account", :product => "product"}
|
247
|
+
frame.expects(:user_attributes).returns(user_attributes).at_least_once
|
248
|
+
frame.expects(:queue_time).returns(0)
|
249
|
+
|
250
|
+
sample = mock('transaction info')
|
251
|
+
NewRelic::Agent::TransactionInfo.set(sample)
|
252
|
+
|
253
|
+
sample.stubs(:start_time).returns(Time.at(100))
|
254
|
+
sample.stubs(:guid).returns('ABC')
|
255
|
+
sample.stubs(:transaction_name).returns('most recent transaction')
|
256
|
+
sample.stubs(:include_guid?).returns(true)
|
257
|
+
sample.stubs(:duration).returns(12.0)
|
258
|
+
sample.stubs(:token).returns('0123456789ABCDEF')
|
259
|
+
|
260
|
+
self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'most recent transaction').returns('most recent transaction')
|
261
|
+
self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'user').returns('user')
|
262
|
+
self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'account').returns('account')
|
263
|
+
self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'product').returns('product')
|
264
|
+
|
265
|
+
value = footer_js_string(NewRelic::Agent.instance.beacon_configuration, beacon, license_key, application_id)
|
266
|
+
assert_equal("<script type=\"text/javascript\">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=\"this_is_my_file\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\nNREUMQ.push([\"nrfj\",\"\",\"\",1,\"most recent transaction\",0,0,new Date().getTime(),\"ABC\",\"0123456789ABCDEF\",\"user\",\"account\",\"product\"])</script>", value, "should return the javascript given some default values")
|
242
267
|
end
|
243
268
|
|
244
269
|
def test_html_safe_if_needed_unsafed
|
@@ -264,7 +289,7 @@ var e=document.createElement("script");'
|
|
264
289
|
text = 'a happy piece of small text'
|
265
290
|
key = (1..40).to_a
|
266
291
|
NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
|
267
|
-
output = obfuscate(text)
|
292
|
+
output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
|
268
293
|
assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1', output, "should output obfuscated text")
|
269
294
|
end
|
270
295
|
|
@@ -272,7 +297,7 @@ var e=document.createElement("script");'
|
|
272
297
|
text = 'a happy piece of small text' * 5
|
273
298
|
key = (1..40).to_a
|
274
299
|
NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
|
275
|
-
output = obfuscate(text)
|
300
|
+
output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
|
276
301
|
assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1YyNsZHZ3cSl6YmluZCJsYiV1amllZit4aHl2YiRtZ3d4cCp7ZWhiZyNrYyZ0ZWhmZyx5ZHp3ZSVuZnh5cyt8ZGRhZiRqYCd7ZGtnYC11Z3twZCZvaXl6cix9aGdgYSVpYSh6Z2pgYSF2Znxx', output, "should output obfuscated text")
|
277
302
|
end
|
278
303
|
end
|