newrelic_rpm 3.9.7.266 → 3.9.8.273
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 +44 -1
- data/lib/new_relic/agent.rb +31 -0
- data/lib/new_relic/agent/agent.rb +34 -5
- data/lib/new_relic/agent/configuration/default_source.rb +25 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
- data/lib/new_relic/agent/cross_app_monitor.rb +1 -1
- data/lib/new_relic/agent/custom_event_aggregator.rb +2 -4
- data/lib/new_relic/agent/error_collector.rb +17 -12
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +9 -8
- data/lib/new_relic/agent/instrumentation/grape.rb +67 -0
- data/lib/new_relic/agent/new_relic_service.rb +93 -43
- data/lib/new_relic/agent/pipe_service.rb +4 -0
- data/lib/new_relic/agent/synthetics_event_buffer.rb +42 -0
- data/lib/new_relic/agent/system_info.rb +44 -18
- data/lib/new_relic/agent/transaction_event_aggregator.rb +9 -2
- data/lib/new_relic/agent/utilization_data.rb +77 -0
- data/lib/new_relic/agent/vm/mri_vm.rb +3 -3
- data/lib/new_relic/rack/agent_hooks.rb +15 -15
- data/lib/new_relic/recipes/capistrano3.rb +2 -2
- data/lib/new_relic/version.rb +1 -1
- data/newrelic_rpm.gemspec +0 -1
- data/test/agent_helper.rb +13 -3
- data/test/environments/lib/environments/runner.rb +3 -19
- data/test/environments/rails42/Gemfile +5 -1
- data/test/fixtures/cross_agent_tests/README.md +1 -1
- data/test/fixtures/cross_agent_tests/cat_map.json +154 -88
- data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +30 -6
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-lxc-driver.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-native-driver-fs.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-native-driver-systemd.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/heroku.txt +1 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/ubuntu-14.04-lxc-container.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/{lxc-containers-without-docker.txt → ubuntu-14.04-no-container.txt} +0 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/ubuntu-14.10-no-container.txt +10 -0
- data/test/multiverse/lib/multiverse/runner.rb +1 -0
- data/test/multiverse/lib/multiverse/suite.rb +6 -2
- data/test/multiverse/suites/active_record/.gitignore +1 -0
- data/test/multiverse/suites/active_record/Envfile +25 -7
- data/test/multiverse/suites/active_record/Rakefile +9 -0
- data/test/{new_relic/agent/instrumentation → multiverse/suites/active_record}/active_record_test.rb +82 -88
- data/test/multiverse/suites/active_record/app/models/models.rb +27 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +5 -46
- data/test/multiverse/suites/active_record/before_suite.rb +23 -0
- data/test/multiverse/suites/active_record/config/database.rb +79 -0
- data/test/multiverse/suites/active_record/config/database.yml +19 -0
- data/test/multiverse/suites/active_record/db/migrate/20141105131800_create_users_and_aliases.rb +21 -0
- data/test/multiverse/suites/active_record/db/migrate/20141106082200_create_orders_and_shipments.rb +25 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +4 -1
- data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +53 -0
- data/test/multiverse/suites/agent_only/keepalive_test.rb +3 -7
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +170 -0
- data/test/multiverse/suites/grape/Envfile +15 -0
- data/test/multiverse/suites/grape/config/newrelic.yml +18 -0
- data/test/multiverse/suites/grape/grape_test.rb +60 -0
- data/test/multiverse/suites/grape/grape_test_api.rb +43 -0
- data/test/multiverse/suites/grape/unsupported_version_test.rb +31 -0
- data/test/multiverse/suites/json/Envfile +3 -1
- data/test/multiverse/suites/rack/rack_env_mutation_test.rb +54 -0
- data/test/multiverse/suites/rails/Envfile +1 -1
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +2 -1
- data/test/multiverse/suites/resque/resque_marshalling_test.rb +54 -0
- data/test/multiverse/suites/typhoeus/Envfile +4 -4
- data/test/new_relic/agent/agent_test.rb +37 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +14 -0
- data/test/new_relic/agent/custom_event_aggregator_test.rb +3 -3
- data/test/new_relic/agent/error_collector/notice_error_test.rb +4 -4
- data/test/new_relic/agent/error_collector_test.rb +27 -4
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +23 -0
- data/test/new_relic/agent/new_relic_service_test.rb +208 -103
- data/test/new_relic/agent/pipe_service_test.rb +7 -0
- data/test/new_relic/agent/synthetics_event_buffer_test.rb +54 -0
- data/test/new_relic/agent/synthetics_monitor_test.rb +0 -3
- data/test/new_relic/agent/system_info_test.rb +6 -6
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +43 -2
- data/test/new_relic/agent/utilization_data_test.rb +18 -0
- data/test/new_relic/collection_helper_test.rb +0 -1
- data/test/new_relic/data_container_tests.rb +11 -7
- data/test/new_relic/fake_collector.rb +23 -0
- data/test/new_relic/fake_instance_metadata_service.rb +45 -0
- data/test/new_relic/license_test.rb +2 -0
- data/test/new_relic/marshalling_test_cases.rb +89 -4
- data/test/new_relic/transaction_sample_test.rb +1 -0
- data/test/test_helper.rb +1 -0
- metadata +33 -6
- metadata.gz.sig +1 -2
- data/test/active_record_fixtures.rb +0 -79
- data/test/new_relic/rack/all_test.rb +0 -14
@@ -77,6 +77,13 @@ class PipeServiceTest < Minitest::Test
|
|
77
77
|
assert_equal ['events'], received_data[:analytic_event_data]
|
78
78
|
end
|
79
79
|
|
80
|
+
def test_custom_event_data
|
81
|
+
received_data = data_from_forked_process do
|
82
|
+
@service.custom_event_data(['events'])
|
83
|
+
end
|
84
|
+
assert_equal ['events'], received_data[:custom_event_data]
|
85
|
+
end
|
86
|
+
|
80
87
|
def test_transaction_sample_data_with_newlines
|
81
88
|
payload_with_newline = "foo\n\nbar"
|
82
89
|
received_data = data_from_forked_process do
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
6
|
+
require 'test/new_relic/agent/event_buffer_test_cases'
|
7
|
+
require 'new_relic/agent/synthetics_event_buffer'
|
8
|
+
|
9
|
+
module NewRelic::Agent
|
10
|
+
class SyntheticsEventBufferTest < Minitest::Test
|
11
|
+
include EventBufferTestCases
|
12
|
+
|
13
|
+
def buffer_class
|
14
|
+
SyntheticsEventBuffer
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_event(timestamp)
|
18
|
+
[{"timestamp" => timestamp}, {}]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_append_with_reject_returns_rejected_item
|
22
|
+
buffer = buffer_class.new(5)
|
23
|
+
|
24
|
+
5.times do |i|
|
25
|
+
result, reject = buffer.append_with_reject(create_event(i))
|
26
|
+
refute_nil(result)
|
27
|
+
assert_nil(reject)
|
28
|
+
end
|
29
|
+
|
30
|
+
event = create_event(10)
|
31
|
+
result, reject = buffer.append_with_reject(event)
|
32
|
+
|
33
|
+
assert_nil result
|
34
|
+
assert_equal event, reject
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_append_with_reject_bases_removal_on_timestamp
|
38
|
+
buffer = buffer_class.new(5)
|
39
|
+
|
40
|
+
last_event = nil
|
41
|
+
5.times do |i|
|
42
|
+
last_event = create_event(i + 10)
|
43
|
+
result = buffer.append(last_event)
|
44
|
+
assert(result)
|
45
|
+
end
|
46
|
+
|
47
|
+
event = create_event(1)
|
48
|
+
result, reject = buffer.append_with_reject(event)
|
49
|
+
|
50
|
+
assert_equal event, result
|
51
|
+
assert_equal last_event, reject
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -37,9 +37,6 @@ module NewRelic::Agent
|
|
37
37
|
|
38
38
|
def test_doesnt_record_synthetics_state_without_header
|
39
39
|
in_transaction do
|
40
|
-
# Make sure we're not just erroring in the event notification handler
|
41
|
-
expects_no_logging(:debug)
|
42
|
-
|
43
40
|
@events.notify(:before_call, {})
|
44
41
|
assert_no_synthetics_payload
|
45
42
|
end
|
@@ -41,20 +41,20 @@ class NewRelic::Agent::SystemInfoTest < Minitest::Test
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
container_id_test_dir = File.join(cross_agent_tests_dir, 'docker_container_id')
|
45
|
+
container_id_test_cases = load_cross_agent_test(File.join('docker_container_id', 'cases'))
|
46
46
|
|
47
|
-
|
47
|
+
container_id_test_cases.each do |test_case|
|
48
48
|
filename = test_case['filename']
|
49
49
|
basename = File.basename(filename, '.txt')
|
50
|
-
test_name = "
|
50
|
+
test_name = "test_container_id_#{basename}"
|
51
51
|
|
52
52
|
define_method(test_name) do
|
53
|
-
input = File.read(File.join(
|
53
|
+
input = File.read(File.join(container_id_test_dir, filename))
|
54
54
|
container_id = @sysinfo.parse_docker_container_id(input)
|
55
55
|
|
56
56
|
message = "Parsed incorrect Docker container ID from #{filename}"
|
57
|
-
assert_equal(test_case['
|
57
|
+
assert_equal(test_case['containerId'], container_id, message)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -244,15 +244,55 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
|
|
244
244
|
end
|
245
245
|
|
246
246
|
def test_synthetics_aggregation_limits
|
247
|
+
with_sampler_config(:'synthetics.events_limit' => 10,
|
248
|
+
:'analytics_events.max_samples_stored' => 0) do
|
249
|
+
20.times do
|
250
|
+
generate_request('synthetic', :synthetics_resource_id => 100)
|
251
|
+
end
|
252
|
+
|
253
|
+
assert_equal 10, @sampler.samples.size
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_synthetics_events_overflow_to_transaction_buffer
|
247
258
|
with_sampler_config(:'synthetics.events_limit' => 10) do
|
248
259
|
20.times do
|
249
260
|
generate_request('synthetic', :synthetics_resource_id => 100)
|
250
261
|
end
|
251
262
|
|
263
|
+
assert_equal 20, @sampler.samples.size
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_synthetics_events_kept_by_timestamp
|
268
|
+
with_sampler_config(:'synthetics.events_limit' => 10,
|
269
|
+
:'analytics_events.max_samples_stored' => 0) do
|
270
|
+
10.times do |i|
|
271
|
+
generate_request('synthetic', :timestamp => i + 10, :synthetics_resource_id => 100)
|
272
|
+
end
|
273
|
+
|
274
|
+
generate_request('synthetic', :timestamp => 1, :synthetics_resource_id => 100)
|
275
|
+
|
252
276
|
assert_equal 10, @sampler.samples.size
|
277
|
+
timestamps = @sampler.samples.map do |(main, _)|
|
278
|
+
main["timestamp"]
|
279
|
+
end.sort
|
280
|
+
|
281
|
+
assert_equal ([1] + (10..18).to_a), timestamps
|
253
282
|
end
|
254
283
|
end
|
255
284
|
|
285
|
+
def test_synthetics_events_timestamp_bumps_go_to_main_buffer
|
286
|
+
with_sampler_config(:'synthetics.events_limit' => 10) do
|
287
|
+
10.times do |i|
|
288
|
+
generate_request('synthetic', :timestamp => i + 10, :synthetics_resource_id => 100)
|
289
|
+
end
|
290
|
+
|
291
|
+
generate_request('synthetic', :timestamp => 1, :synthetics_resource_id => 100)
|
292
|
+
|
293
|
+
assert_equal 11, @sampler.samples.size
|
294
|
+
end
|
295
|
+
end
|
256
296
|
|
257
297
|
def test_merging_synthetics_still_applies_limit
|
258
298
|
samples = with_sampler_config(:'synthetics.events_limit' => 20) do
|
@@ -262,7 +302,8 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
|
|
262
302
|
@sampler.harvest!
|
263
303
|
end
|
264
304
|
|
265
|
-
with_sampler_config(:'synthetics.events_limit' => 10
|
305
|
+
with_sampler_config(:'synthetics.events_limit' => 10,
|
306
|
+
:'analytics_events.max_samples_stored' => 0) do
|
266
307
|
@sampler.merge!(samples)
|
267
308
|
assert_equal 10, @sampler.samples.size
|
268
309
|
end
|
@@ -302,7 +343,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
|
|
302
343
|
payload = {
|
303
344
|
:name => "Controller/#{name}",
|
304
345
|
:type => :controller,
|
305
|
-
:start_timestamp => Time.now.to_f,
|
346
|
+
:start_timestamp => options[:timestamp] || Time.now.to_f,
|
306
347
|
:duration => 0.1,
|
307
348
|
:custom_params => {}
|
308
349
|
}.merge(options)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','data_container_tests'))
|
7
|
+
|
8
|
+
module NewRelic::Agent
|
9
|
+
class UtilizationDataTest < Minitest::Test
|
10
|
+
# We don't behave like a normal container, but we need to match the
|
11
|
+
# interface at least!
|
12
|
+
include NewRelic::BasicDataContainerMethodTests
|
13
|
+
|
14
|
+
def create_container
|
15
|
+
UtilizationData.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -13,7 +13,18 @@
|
|
13
13
|
# populated with for the purposes of testing.
|
14
14
|
|
15
15
|
module NewRelic
|
16
|
+
module BasicDataContainerMethodTests
|
17
|
+
def test_should_respond_to_required_methods
|
18
|
+
c = create_container
|
19
|
+
assert c.respond_to?(:harvest!)
|
20
|
+
assert c.respond_to?(:reset!)
|
21
|
+
assert c.respond_to?(:merge!)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
module BasicDataContainerTests
|
26
|
+
include BasicDataContainerMethodTests
|
27
|
+
|
17
28
|
def num_data_items
|
18
29
|
self.respond_to?(:max_data_items) ? max_data_items : 5
|
19
30
|
end
|
@@ -42,13 +53,6 @@ module NewRelic
|
|
42
53
|
populate_container(c, num_data_items)
|
43
54
|
assert_equal(num_data_items, c.harvest!.size)
|
44
55
|
end
|
45
|
-
|
46
|
-
def test_should_respond_to_required_methods
|
47
|
-
c = create_container
|
48
|
-
assert c.respond_to?(:harvest!)
|
49
|
-
assert c.respond_to?(:reset!)
|
50
|
-
assert c.respond_to?(:merge!)
|
51
|
-
end
|
52
56
|
end
|
53
57
|
|
54
58
|
module DataContainerTests
|
@@ -53,6 +53,7 @@ module NewRelic
|
|
53
53
|
end
|
54
54
|
|
55
55
|
attr_accessor :agent_data, :mock
|
56
|
+
attr_reader :last_socket
|
56
57
|
|
57
58
|
def initialize
|
58
59
|
super(DEFAULT_PORT)
|
@@ -69,6 +70,8 @@ module NewRelic
|
|
69
70
|
'profile_data' => Response.new(200, {'return_value' => nil}),
|
70
71
|
'shutdown' => Response.new(200, {'return_value' => nil}),
|
71
72
|
'analytic_event_data' => Response.new(200, {'return_value' => nil}),
|
73
|
+
'custom_event_data' => Response.new(200, {'return_value' => nil}),
|
74
|
+
'utilization_data' => Response.new(200, {'return_value' => nil}),
|
72
75
|
}
|
73
76
|
reset
|
74
77
|
end
|
@@ -98,6 +101,8 @@ module NewRelic
|
|
98
101
|
end
|
99
102
|
|
100
103
|
def call(env)
|
104
|
+
@last_socket = Thread.current[:WEBrickSocket]
|
105
|
+
|
101
106
|
req = ::Rack::Request.new(env)
|
102
107
|
res = ::Rack::Response.new
|
103
108
|
uri = URI.parse(req.url)
|
@@ -198,8 +203,12 @@ module NewRelic
|
|
198
203
|
TransactionSampleDataPost.new(opts)
|
199
204
|
when 'analytic_event_data'
|
200
205
|
AnalyticEventDataPost.new(opts)
|
206
|
+
when 'custom_event_data'
|
207
|
+
AnalyticEventDataPost.new(opts)
|
201
208
|
when 'error_data'
|
202
209
|
ErrorDataPost.new(opts)
|
210
|
+
when 'utilization_data'
|
211
|
+
UtilizationDataPost.new(opts)
|
203
212
|
else
|
204
213
|
new(opts)
|
205
214
|
end
|
@@ -339,6 +348,20 @@ module NewRelic
|
|
339
348
|
end
|
340
349
|
end
|
341
350
|
|
351
|
+
class UtilizationDataPost < AgentPost
|
352
|
+
|
353
|
+
attr_reader :hostname, :container_id, :cpu_count, :instance_type
|
354
|
+
|
355
|
+
def initialize(opts={})
|
356
|
+
super
|
357
|
+
@hostname, @container_id, @cpu_count, @instance_type = body
|
358
|
+
end
|
359
|
+
|
360
|
+
def ==(other)
|
361
|
+
@body == other.body
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
342
365
|
class SubmittedError
|
343
366
|
|
344
367
|
attr_reader :timestamp, :path, :message, :exception_class_name, :params
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'rack'
|
6
|
+
require 'rack/request'
|
7
|
+
require 'fake_server'
|
8
|
+
|
9
|
+
module NewRelic
|
10
|
+
class FakeInstanceMetadataService < FakeServer
|
11
|
+
def initialize(*_)
|
12
|
+
super
|
13
|
+
reset
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_response_for_path(path, response)
|
17
|
+
@responses[path] = response
|
18
|
+
end
|
19
|
+
|
20
|
+
def response_for_path(path)
|
21
|
+
@responses[path]
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
req = ::Rack::Request.new(env)
|
26
|
+
path = req.path
|
27
|
+
rsp = response_for_path(path)
|
28
|
+
|
29
|
+
case rsp
|
30
|
+
when ::Rack::Response
|
31
|
+
rsp.to_a
|
32
|
+
when String
|
33
|
+
[200, {}, [rsp]]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset
|
38
|
+
@responses = {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def app
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -74,6 +74,8 @@ class LicenseTest < Minitest::Test
|
|
74
74
|
path =~ %r{/tags$}i ||
|
75
75
|
# skip multiverse auto-generated gemfiles
|
76
76
|
path =~ %r{/test/multiverse/suites/.*/Gemfile\.\d+(\.lock)?$} ||
|
77
|
+
# skip multiverse auto-generated db/schema
|
78
|
+
path =~ %r{/test/multiverse/suites/.*/db/schema.rb$} ||
|
77
79
|
# skip the artifacts directory
|
78
80
|
path =~ %r{/artifacts/}
|
79
81
|
)
|
@@ -7,7 +7,9 @@
|
|
7
7
|
module MarshallingTestCases
|
8
8
|
|
9
9
|
def test_sends_metrics
|
10
|
-
|
10
|
+
with_around_hook do
|
11
|
+
NewRelic::Agent.record_metric('Boo', 42)
|
12
|
+
end
|
11
13
|
|
12
14
|
transmit_data
|
13
15
|
|
@@ -17,7 +19,9 @@ module MarshallingTestCases
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_sends_errors
|
20
|
-
|
22
|
+
with_around_hook do
|
23
|
+
NewRelic::Agent.notice_error(StandardError.new("Boom"))
|
24
|
+
end
|
21
25
|
|
22
26
|
transmit_data
|
23
27
|
|
@@ -29,26 +33,107 @@ module MarshallingTestCases
|
|
29
33
|
|
30
34
|
def test_sends_transaction_traces
|
31
35
|
with_config(:'transaction_tracer.transaction_threshold' => -1.0) do
|
32
|
-
|
36
|
+
with_around_hook do
|
37
|
+
Transactioner.new.do_it
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
transmit_data
|
36
42
|
|
37
43
|
result = $collector.calls_for('transaction_sample_data')
|
38
44
|
assert_equal 1, result.length
|
39
|
-
assert_equal "
|
45
|
+
assert_equal "TestTransaction/do_it", result.first.metric_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_sends_transaction_events
|
49
|
+
t0 = freeze_time(Time.at(Time.now.to_i))
|
50
|
+
|
51
|
+
with_around_hook do
|
52
|
+
Transactioner.new.do_it
|
53
|
+
end
|
54
|
+
|
55
|
+
transmit_event_data
|
56
|
+
|
57
|
+
result = $collector.calls_for('analytic_event_data')
|
58
|
+
assert_equal 1, result.length
|
59
|
+
events = result.first.events
|
60
|
+
assert_equal 1, events.length
|
61
|
+
|
62
|
+
expected_event = [
|
63
|
+
{
|
64
|
+
"type" => "Transaction",
|
65
|
+
"timestamp" => t0.to_f,
|
66
|
+
"name" => "TestTransaction/do_it",
|
67
|
+
"duration" => 0.0,
|
68
|
+
},
|
69
|
+
{}
|
70
|
+
]
|
71
|
+
|
72
|
+
event = events.first
|
73
|
+
# this is only present on REE, and we don't really care - the point of this
|
74
|
+
# test is just to validate basic marshalling
|
75
|
+
event[0].delete("gcCumulative")
|
76
|
+
|
77
|
+
assert_equal(expected_event, event)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_sends_custom_events
|
81
|
+
t0 = freeze_time
|
82
|
+
|
83
|
+
with_around_hook do
|
84
|
+
NewRelic::Agent.record_custom_event("CustomEventType", :foo => 'bar', :baz => 'qux')
|
85
|
+
end
|
86
|
+
|
87
|
+
transmit_event_data
|
88
|
+
|
89
|
+
result = $collector.calls_for('custom_event_data')
|
90
|
+
assert_equal 1, result.length
|
91
|
+
events = result.first.events
|
92
|
+
assert_equal 1, events.length
|
93
|
+
|
94
|
+
expected_event = [
|
95
|
+
{
|
96
|
+
"type" => "CustomEventType",
|
97
|
+
"timestamp" => t0.to_i
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"foo" => "bar",
|
101
|
+
"baz" => "qux"
|
102
|
+
}
|
103
|
+
]
|
104
|
+
|
105
|
+
assert_equal(expected_event, events.first)
|
40
106
|
end
|
41
107
|
|
42
108
|
class Transactioner
|
43
109
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
44
110
|
|
45
111
|
def do_it
|
112
|
+
NewRelic::Agent.set_transaction_name("do_it", :category => "TestTransaction")
|
46
113
|
end
|
47
114
|
|
48
115
|
add_transaction_tracer :do_it
|
49
116
|
end
|
50
117
|
|
118
|
+
def with_around_hook(&blk)
|
119
|
+
if respond_to?(:around_each)
|
120
|
+
around_each do
|
121
|
+
blk.call
|
122
|
+
end
|
123
|
+
else
|
124
|
+
blk.call
|
125
|
+
end
|
126
|
+
|
127
|
+
if respond_to?(:after_each)
|
128
|
+
after_each
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
51
132
|
def transmit_data
|
52
133
|
NewRelic::Agent.instance.send(:transmit_data)
|
53
134
|
end
|
135
|
+
|
136
|
+
def transmit_event_data
|
137
|
+
NewRelic::Agent.instance.send(:transmit_event_data)
|
138
|
+
end
|
54
139
|
end
|