newrelic_rpm 3.7.1.188 → 3.7.2.190.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data.tar.gz.sig +3 -2
  2. data/CHANGELOG +1 -1
  3. data/Guardfile +3 -3
  4. data/README.md +1 -1
  5. data/Rakefile +0 -2
  6. data/init.rb +2 -5
  7. data/lib/new_relic/agent.rb +3 -0
  8. data/lib/new_relic/agent/agent.rb +2 -0
  9. data/lib/new_relic/agent/configuration/default_source.rb +32 -14
  10. data/lib/new_relic/agent/configuration/environment_source.rb +1 -0
  11. data/lib/new_relic/agent/cross_app_monitor.rb +2 -2
  12. data/lib/new_relic/agent/cross_app_tracing.rb +2 -2
  13. data/lib/new_relic/agent/error_collector.rb +1 -1
  14. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -1
  15. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -8
  16. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -6
  17. data/lib/new_relic/agent/javascript_instrumentor.rb +27 -36
  18. data/lib/new_relic/agent/method_tracer.rb +20 -2
  19. data/lib/new_relic/agent/new_relic_service.rb +35 -27
  20. data/lib/new_relic/agent/request_sampler.rb +20 -13
  21. data/lib/new_relic/agent/sampler_collection.rb +4 -0
  22. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
  23. data/lib/new_relic/agent/system_info.rb +25 -15
  24. data/lib/new_relic/agent/transaction.rb +23 -4
  25. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  26. data/lib/new_relic/cli/install.rb +1 -1
  27. data/lib/new_relic/control.rb +1 -0
  28. data/lib/new_relic/helper.rb +1 -29
  29. data/lib/new_relic/json_wrapper.rb +92 -0
  30. data/lib/new_relic/language_support.rb +4 -0
  31. data/lib/new_relic/rack/agent_hooks.rb +4 -0
  32. data/lib/new_relic/rack/browser_monitoring.rb +4 -0
  33. data/lib/new_relic/rack/developer_mode.rb +4 -1
  34. data/lib/new_relic/rack/error_collector.rb +5 -0
  35. data/lib/new_relic/rack/transaction_reset.rb +20 -0
  36. data/lib/new_relic/version.rb +1 -1
  37. data/lib/tasks/install.rake +0 -1
  38. data/newrelic_rpm.gemspec +1 -1
  39. data/test/agent_helper.rb +7 -8
  40. data/test/environments/norails/Gemfile +2 -1
  41. data/test/environments/rails21/Gemfile +2 -2
  42. data/test/environments/rails21/config/environment.rb +1 -3
  43. data/test/environments/rails21/config/environments/development.rb +0 -6
  44. data/test/environments/rails22/Gemfile +2 -2
  45. data/test/environments/rails22/config/environment.rb +0 -2
  46. data/test/environments/rails22/config/environments/development.rb +0 -6
  47. data/test/environments/rails23/Gemfile +2 -3
  48. data/test/environments/rails23/config/environment.rb +0 -9
  49. data/test/environments/rails23/config/environments/development.rb +0 -5
  50. data/test/environments/rails30/Gemfile +2 -2
  51. data/test/environments/rails31/Gemfile +2 -2
  52. data/test/environments/rails32/Gemfile +2 -1
  53. data/test/environments/rails40/Gemfile +2 -1
  54. data/test/intentional_fail.rb +1 -2
  55. data/test/multiverse/lib/multiverse/envfile.rb +1 -5
  56. data/test/multiverse/lib/multiverse/suite.rb +10 -27
  57. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +49 -67
  58. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +128 -0
  59. data/test/multiverse/suites/agent_only/marshaling_test.rb +7 -9
  60. data/test/multiverse/suites/agent_only/script/loading.rb +20 -0
  61. data/test/multiverse/suites/agent_only/start_up_test.rb +7 -0
  62. data/test/multiverse/suites/bare/Envfile +3 -0
  63. data/test/multiverse/suites/bare/standalone_instrumentation_test.rb +43 -0
  64. data/test/multiverse/suites/rails/Envfile +0 -2
  65. data/test/multiverse/suites/rails/app/views/views/_a_partial.html.erb +1 -0
  66. data/test/multiverse/suites/rails/app/views/views/index.html.erb +1 -1
  67. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -1
  68. data/test/multiverse/suites/rails/request_statistics_test.rb +9 -4
  69. data/test/multiverse/suites/rails/view_instrumentation_test.rb +111 -106
  70. data/test/multiverse/suites/typhoeus/Envfile +1 -1
  71. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +16 -2
  72. data/test/multiverse/test/multiverse_test.rb +2 -2
  73. data/test/new_relic/agent/agent/connect_test.rb +1 -1
  74. data/test/new_relic/agent/agent/start_test.rb +1 -1
  75. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -1
  76. data/test/new_relic/agent/agent_logger_test.rb +3 -7
  77. data/test/new_relic/agent/agent_test.rb +33 -57
  78. data/test/new_relic/agent/apdex_from_server_test.rb +1 -1
  79. data/test/new_relic/agent/audit_logger_test.rb +5 -8
  80. data/test/new_relic/agent/autostart_test.rb +1 -1
  81. data/test/new_relic/agent/browser_token_test.rb +1 -1
  82. data/test/new_relic/agent/busy_calculator_test.rb +2 -4
  83. data/test/new_relic/agent/commands/agent_command_router_test.rb +5 -5
  84. data/test/new_relic/agent/commands/agent_command_test.rb +1 -1
  85. data/test/new_relic/agent/commands/thread_profiler_session_test.rb +6 -6
  86. data/test/new_relic/agent/commands/xray_session_collection_test.rb +10 -10
  87. data/test/new_relic/agent/commands/xray_session_test.rb +1 -1
  88. data/test/new_relic/agent/configuration/default_source_test.rb +4 -4
  89. data/test/new_relic/agent/configuration/environment_source_test.rb +14 -2
  90. data/test/new_relic/agent/configuration/manager_test.rb +3 -3
  91. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +1 -1
  92. data/test/new_relic/agent/configuration/server_source_test.rb +1 -1
  93. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  94. data/test/new_relic/agent/cpu_sampler_test.rb +1 -1
  95. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -3
  96. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -4
  97. data/test/new_relic/agent/database_test.rb +1 -1
  98. data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +1 -1
  99. data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +1 -1
  100. data/test/new_relic/agent/datastores/mongo/obfuscator_test.rb +1 -1
  101. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +2 -2
  102. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -1
  103. data/test/new_relic/agent/error_collector_test.rb +5 -3
  104. data/test/new_relic/agent/event_listener_test.rb +1 -1
  105. data/test/new_relic/agent/harvester_test.rb +1 -1
  106. data/test/new_relic/agent/http_clients/uri_util_test.rb +1 -1
  107. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  108. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +1 -1
  109. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +1 -1
  110. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +495 -495
  111. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +2 -2
  112. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +1 -1
  113. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  114. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +1 -1
  115. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +4 -6
  116. data/test/new_relic/agent/instrumentation/queue_time_test.rb +1 -1
  117. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  118. data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +1 -1
  119. data/test/new_relic/agent/instrumentation/sinatra_test.rb +1 -1
  120. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +7 -7
  121. data/test/new_relic/agent/javascript_instrumentor_test.rb +47 -55
  122. data/test/new_relic/agent/memcache_instrumentation_test.rb +1 -1
  123. data/test/new_relic/agent/memory_logger_test.rb +1 -1
  124. data/test/new_relic/agent/method_interrobang_test.rb +2 -3
  125. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -4
  126. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  127. data/test/new_relic/agent/method_tracer_test.rb +6 -7
  128. data/test/new_relic/agent/method_visibility_test.rb +1 -1
  129. data/test/new_relic/agent/new_relic_service_test.rb +129 -19
  130. data/test/new_relic/agent/obfuscator_test.rb +1 -1
  131. data/test/new_relic/agent/pipe_channel_manager_test.rb +143 -145
  132. data/test/new_relic/agent/pipe_service_test.rb +2 -4
  133. data/test/new_relic/agent/request_sampler_test.rb +23 -19
  134. data/test/new_relic/agent/rpm_agent_test.rb +3 -3
  135. data/test/new_relic/agent/rules_engine_test.rb +1 -1
  136. data/test/new_relic/agent/sampled_buffer_test.rb +1 -1
  137. data/test/new_relic/agent/sampler_collection_test.rb +3 -3
  138. data/test/new_relic/agent/sampler_test.rb +1 -1
  139. data/test/new_relic/agent/shim_agent_test.rb +1 -1
  140. data/test/new_relic/agent/sql_sampler_test.rb +4 -6
  141. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
  142. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +5 -5
  143. data/test/new_relic/agent/stats_engine/samplers_test.rb +2 -2
  144. data/test/new_relic/agent/stats_engine_test.rb +3 -3
  145. data/test/new_relic/agent/stats_hash_test.rb +2 -2
  146. data/test/new_relic/agent/stats_test.rb +1 -1
  147. data/test/new_relic/agent/threading/agent_thread_test.rb +2 -4
  148. data/test/new_relic/agent/threading/backtrace_node_test.rb +1 -1
  149. data/test/new_relic/agent/threading/backtrace_service_test.rb +5 -5
  150. data/test/new_relic/agent/threading/thread_profile_test.rb +1 -1
  151. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +1 -1
  152. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +1 -1
  153. data/test/new_relic/agent/transaction/pop_test.rb +1 -1
  154. data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +1 -1
  155. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
  156. data/test/new_relic/agent/transaction_interrobang_test.rb +2 -3
  157. data/test/new_relic/agent/transaction_sample_builder_test.rb +16 -14
  158. data/test/new_relic/agent/transaction_sampler_test.rb +16 -21
  159. data/test/new_relic/agent/transaction_state_test.rb +1 -1
  160. data/test/new_relic/agent/transaction_test.rb +61 -1
  161. data/test/new_relic/agent/transaction_timings_test.rb +1 -1
  162. data/test/new_relic/agent/worker_loop_test.rb +1 -1
  163. data/test/new_relic/agent_test.rb +2 -3
  164. data/test/new_relic/cli/deployments_test.rb +3 -3
  165. data/test/new_relic/coerce_test.rb +1 -1
  166. data/test/new_relic/collection_helper_test.rb +1 -1
  167. data/test/new_relic/control/class_methods_test.rb +2 -2
  168. data/test/new_relic/control/frameworks/rails_test.rb +1 -1
  169. data/test/new_relic/control_test.rb +9 -4
  170. data/test/new_relic/dependency_detection_test.rb +1 -1
  171. data/test/new_relic/dispatcher_test.rb +1 -1
  172. data/test/new_relic/environment_report_test.rb +4 -6
  173. data/test/new_relic/fake_collector.rb +1 -158
  174. data/test/new_relic/framework_test.rb +2 -1
  175. data/test/new_relic/http_client_test_cases.rb +2 -3
  176. data/test/new_relic/json_wrapper_test.rb +77 -0
  177. data/test/new_relic/language_support_test.rb +1 -1
  178. data/test/new_relic/license_test.rb +2 -2
  179. data/test/new_relic/load_test.rb +2 -8
  180. data/test/new_relic/local_environment_test.rb +1 -1
  181. data/test/new_relic/metric_data_test.rb +1 -1
  182. data/test/new_relic/metric_parser/metric_parser_test.rb +1 -1
  183. data/test/new_relic/metric_spec_test.rb +1 -1
  184. data/test/new_relic/multiverse_helpers.rb +26 -30
  185. data/test/new_relic/noticed_error_test.rb +1 -1
  186. data/test/new_relic/rack/agent_hooks_test.rb +1 -1
  187. data/test/new_relic/rack/all_test.rb +1 -1
  188. data/test/new_relic/rack/browser_monitoring_test.rb +4 -2
  189. data/test/new_relic/rack/deferred_instrumentation_test.rb +3 -5
  190. data/test/new_relic/rack/developer_mode_helper_test.rb +1 -1
  191. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  192. data/test/new_relic/rack/error_collector_test.rb +8 -8
  193. data/test/new_relic/rack/transaction_reset_test.rb +35 -0
  194. data/test/new_relic/transaction_analysis/segment_summary_test.rb +2 -2
  195. data/test/new_relic/transaction_analysis_test.rb +1 -1
  196. data/test/new_relic/transaction_sample/composite_segment_test.rb +1 -1
  197. data/test/new_relic/transaction_sample/fake_segment_test.rb +2 -4
  198. data/test/new_relic/transaction_sample/segment_test.rb +3 -7
  199. data/test/new_relic/transaction_sample/summary_segment_test.rb +1 -1
  200. data/test/new_relic/transaction_sample_subtest_test.rb +1 -1
  201. data/test/new_relic/transaction_sample_test.rb +4 -6
  202. data/test/new_relic/version_number_test.rb +1 -1
  203. data/test/performance/lib/performance/instrumentation/gc_stats.rb +1 -1
  204. data/test/performance/lib/performance/json_reporter.rb +1 -1
  205. data/test/performance/suites/marshalling.rb +76 -0
  206. data/test/test_helper.rb +6 -39
  207. metadata +19 -12
  208. metadata.gz.sig +0 -0
  209. data/test/new_relic/helper_test.rb +0 -32
@@ -16,84 +16,66 @@ class InstrumentActiveRecordMethods < MiniTest::Unit::TestCase
16
16
  include MultiverseHelpers
17
17
  setup_and_teardown_agent
18
18
 
19
- if RUBY_VERSION >= '1.8.7'
20
- if RUBY_PLATFORM == 'java'
21
- require 'jdbc/sqlite3'
22
- @@adapter = 'sqlite3'
23
- else
24
- require 'sqlite3'
25
- @@adapter = 'sqlite3'
26
- end
27
-
28
- class User < ActiveRecord::Base
29
- include NewRelic::Agent::MethodTracer
30
- has_many :aliases
31
-
32
- add_method_tracer :save!
33
- add_method_tracer :persisted?
34
- end
19
+ class User < ActiveRecord::Base
20
+ include NewRelic::Agent::MethodTracer
21
+ has_many :aliases
35
22
 
36
- class Alias < ActiveRecord::Base
37
- include NewRelic::Agent::MethodTracer
23
+ add_method_tracer :save!
24
+ add_method_tracer :persisted?
25
+ end
38
26
 
39
- add_method_tracer :save!
40
- add_method_tracer :persisted?
41
- add_method_tracer :destroyed?
42
- end
27
+ class Alias < ActiveRecord::Base
28
+ include NewRelic::Agent::MethodTracer
43
29
 
44
- def after_setup
45
- puts "adapter : #{@@adapter}"
46
- @db_connection = ActiveRecord::Base.establish_connection( :adapter => @@adapter, :database => "testdb.sqlite3")
47
- ActiveRecord::Migration.class_eval do
48
- @connection = @db_connection
49
- create_table :users do |t|
50
- t.string :name
51
- end
30
+ add_method_tracer :save!
31
+ add_method_tracer :persisted?
32
+ add_method_tracer :destroyed?
33
+ end
52
34
 
53
- create_table :aliases do |t|
54
- t.integer :user_id
55
- t.string :aka
56
- end
35
+ def after_setup
36
+ @db_connection = ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => 'testdb.sqlite3')
37
+ ActiveRecord::Migration.class_eval do
38
+ @connection = @db_connection
39
+ create_table :users do |t|
40
+ t.string :name
57
41
  end
58
- end
59
42
 
60
- def after_teardown
61
- @db_connection = ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => "testdb.sqlite3")
62
- ActiveRecord::Migration.class_eval do
63
- @connection = @db_connection
64
- drop_table :users
65
- drop_table :aliases
43
+ create_table :aliases do |t|
44
+ t.integer :user_id
45
+ t.string :aka
66
46
  end
67
47
  end
48
+ end
68
49
 
69
- def test_basic_creation
70
- a_user = User.new :name => "Bob"
71
- assert a_user.new_record?
72
- a_user.save!
73
- assert User.connected?
74
- assert a_user.persisted?
75
- assert a_user.id == 1
50
+ def after_teardown
51
+ ActiveRecord::Migration.class_eval do
52
+ @connection = @db_connection
53
+ drop_table :users
54
+ drop_table :aliases
76
55
  end
56
+ end
77
57
 
78
- def test_alias_collection_query_method
79
- a_user = User.new :name => "Bob"
80
- a_user.save!
81
- a_user = User.find(1)
82
- assert User.connected?
83
- assert a_user.id = 1
84
-
85
- an_alias = Alias.new :user_id => a_user.id, :aka => "the Blob"
86
- assert an_alias.new_record?
87
- an_alias.save!
88
- assert an_alias.persisted?
89
- an_alias.destroy
90
- assert an_alias.destroyed?
91
- end
58
+ def test_basic_creation
59
+ a_user = User.new :name => "Bob"
60
+ assert a_user.new_record?
61
+ a_user.save!
62
+ assert User.connected?
63
+ assert a_user.persisted?
64
+ assert a_user.id == 1
65
+ end
92
66
 
93
- else
94
- def test_truth
95
- assert true # jruby freaks out if there are no tests defined in the test class
96
- end
97
- puts yellow('SKIPPED! skipped until ruby 1.8.6 compatibilites ironed out')
67
+ def test_alias_collection_query_method
68
+ a_user = User.new :name => "Bob"
69
+ a_user.save!
70
+ a_user = User.find(1)
71
+ assert User.connected?
72
+ assert a_user.id = 1
73
+
74
+ an_alias = Alias.new :user_id => a_user.id, :aka => "the Blob"
75
+ assert an_alias.new_record?
76
+ an_alias.save!
77
+ assert an_alias.persisted?
78
+ an_alias.destroy
79
+ assert an_alias.destroyed?
98
80
  end
99
81
  end
@@ -0,0 +1,128 @@
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
+ if RUBY_VERSION >= '1.9'
6
+
7
+ class CollectorExceptionHandlingTest < MiniTest::Unit::TestCase
8
+ include MultiverseHelpers
9
+
10
+ setup_and_teardown_agent
11
+
12
+ # We're hitting a Rubinius bug when running this test there:
13
+ # https://github.com/rubinius/rubinius/issues/2899
14
+ unless NewRelic::LanguageSupport.rubinius?
15
+ def test_handles_mis_encoded_database_queries
16
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0,
17
+ :'transaction_tracer.record_sql' => :raw) do
18
+ in_transaction do
19
+ agent.transaction_sampler.notice_sql(bad_string, nil, 42)
20
+ end
21
+ assert_endpoint_received_string('transaction_sample_data', normalized_bad_string)
22
+ end
23
+ end
24
+ end
25
+
26
+ def test_handles_mis_encoded_request_params
27
+ with_config(:'capture_params' => true,
28
+ :'transaction_tracer.transaction_threshold' => 0.0) do
29
+ options = { :filtered_params => { bad_string => bad_string }}
30
+ in_transaction(options) do
31
+ # nothin
32
+ end
33
+ end
34
+ assert_endpoint_received_string('transaction_sample_data', normalized_bad_string)
35
+ end
36
+
37
+ def test_handles_mis_encoded_custom_params
38
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
39
+ in_transaction do
40
+ NewRelic::Agent.add_custom_parameters(:foo => bad_string)
41
+ end
42
+ end
43
+ assert_endpoint_received_string('transaction_sample_data', normalized_bad_string)
44
+ end
45
+
46
+ def test_handles_mis_encoded_custom_params_on_analytics_events
47
+ in_transaction(:type => :controller) do
48
+ NewRelic::Agent.add_custom_parameters(:foo => bad_string)
49
+ end
50
+ assert_endpoint_received_string('analytic_event_data', normalized_bad_string)
51
+ end
52
+
53
+ def test_handles_mis_encoded_custom_params_on_errors
54
+ NewRelic::Agent.notice_error('bad news', :custom_params => {'foo' => bad_string})
55
+ assert_endpoint_received_string('error_data', normalized_bad_string)
56
+ end
57
+
58
+ def test_handles_mis_encoded_exception_message
59
+ NewRelic::Agent.notice_error(bad_string)
60
+ assert_endpoint_received_string('error_data', normalized_bad_string)
61
+ end
62
+
63
+ def test_handles_mis_encoded_metric_names
64
+ NewRelic::Agent.record_metric(bad_string, 42)
65
+ assert_endpoint_received_string('metric_data', normalized_bad_string)
66
+ end
67
+
68
+ def test_handles_mis_encoded_transaction_names
69
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
70
+ in_transaction do
71
+ NewRelic::Agent.set_transaction_name(bad_string)
72
+ end
73
+ end
74
+ expected_transaction_name = "other/#{normalized_bad_string}"
75
+ assert_endpoint_received_string('transaction_sample_data', expected_transaction_name)
76
+ end
77
+
78
+ def test_handles_mis_encoded_strings_in_environment_report
79
+ $collector.reset
80
+ ::NewRelic::EnvironmentReport.report_on('Dummy') do
81
+ bad_string
82
+ end
83
+ agent.instance_variable_set(:@environment_report, agent.environment_for_connect)
84
+ agent.connect_to_server
85
+ assert_endpoint_received_string('connect', normalized_bad_string)
86
+ end
87
+
88
+ def assert_endpoint_received_string(endpoint, string)
89
+ agent.send(:transmit_data)
90
+ requests = $collector.calls_for(endpoint)
91
+ assert_equal(1, requests.size)
92
+ request = requests.first
93
+ request.decode! if request.respond_to?(:decode!)
94
+ assert_contains_string(request, string)
95
+ end
96
+
97
+ def assert_contains_string(request, string)
98
+ object_graph = request.body
99
+ object_graph = request.samples if request.respond_to?(:samples)
100
+ assert object_graph_contains_string?(request.body, string), "Did not find desired string in #{request.body.inspect}"
101
+ end
102
+
103
+ def object_graph_contains_string?(object_graph, string)
104
+ case object_graph
105
+ when String
106
+ string == object_graph
107
+ when Array
108
+ object_graph.any? { |x| object_graph_contains_string?(x, string) }
109
+ when Hash
110
+ (
111
+ object_graph_contains_string?(object_graph.keys, string) ||
112
+ object_graph_contains_string?(object_graph.values, string)
113
+ )
114
+ else
115
+ false
116
+ end
117
+ end
118
+
119
+ def bad_string
120
+ (0..250).to_a.pack("C*").force_encoding('UTF-8')
121
+ end
122
+
123
+ def normalized_bad_string
124
+ bad_string.force_encoding('ISO-8859-1').encode('UTF-8')
125
+ end
126
+ end
127
+
128
+ end
@@ -33,15 +33,13 @@ class MarshalingTest < MiniTest::Unit::TestCase
33
33
  agent.service.connect
34
34
  agent.send(:harvest_and_send_transaction_traces)
35
35
 
36
- if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
37
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
38
- else
39
- marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
40
- end
41
-
42
- assert_equal('666', $collector.calls_for('transaction_sample_data')[0].run_id)
43
- assert_equal(expected_sample.to_collector_array(marshaller.default_encoder),
44
- $collector.calls_for('transaction_sample_data')[0][1][0])
36
+ marshaller = agent.service.marshaller
37
+
38
+ transaction_sample_data_post = $collector.calls_for('transaction_sample_data')[0]
39
+ assert_equal('666', transaction_sample_data_post.run_id)
40
+ encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
41
+ assert_equal(expected_sample.to_collector_array(encoder),
42
+ transaction_sample_data_post[1][0])
45
43
  end
46
44
 
47
45
  def test_metric_data_marshalling
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # This file is distributed under New Relic's license terms.
4
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+
6
+ ENV["NEW_RELIC_LOG_FILE_PATH"] = "STDOUT"
7
+
8
+ require 'newrelic_rpm'
9
+
10
+ # Force all named items to re-enable
11
+ enable_everyone = {}
12
+ DependencyDetection.items.each do |item|
13
+ if item.name
14
+ enable_everyone["disable_#{item.name}".to_sym] = false
15
+ end
16
+ end
17
+ NewRelic::Agent.config.apply_config(enable_everyone)
18
+
19
+ # Run dependency detection again!
20
+ DependencyDetection.detect!
@@ -23,4 +23,11 @@ class StartUpTest < MiniTest::Unit::TestCase
23
23
 
24
24
  assert_equal '', output.chomp
25
25
  end
26
+
27
+ def test_instrumentation_loads_clean_even_without_dependencies
28
+ output = `bundle exec ruby script/loading.rb`
29
+
30
+ problems = output.scan(/ERROR : .*/)
31
+ assert_empty problems
32
+ end
26
33
  end
@@ -0,0 +1,3 @@
1
+ gemfile <<-RB
2
+ gem 'newrelic_rpm', :require => false, :path => File.expand_path('../../../../')
3
+ RB
@@ -0,0 +1,43 @@
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
+ # This test is based on the example code at:
6
+ # https://docs.newrelic.com/docs/ruby/ruby-custom-metric-collection#example_class
7
+ #
8
+ # See https://newrelic.atlassian.net/browse/RUBY-1116 for details on how this
9
+ # was broken previously.
10
+
11
+ require 'new_relic/agent/method_tracer'
12
+
13
+ class StandaloneInstrumentationTest < MiniTest::Unit::TestCase
14
+ class InstrumentedClass
15
+ def instance_method(*args)
16
+ args
17
+ end
18
+
19
+ def self.class_method(*args)
20
+ args
21
+ end
22
+
23
+ include NewRelic::Agent::MethodTracer
24
+ add_method_tracer :instance_method
25
+
26
+ class << self
27
+ include ::NewRelic::Agent::MethodTracer
28
+ add_method_tracer :class_method
29
+ end
30
+ end
31
+
32
+ def test_instance_method_tracers_should_not_cause_errors
33
+ args = [1, 2, 3]
34
+ result = InstrumentedClass.new.instance_method(*args)
35
+ assert_equal(args, result)
36
+ end
37
+
38
+ def test_class_method_tracer_should_not_cause_errors
39
+ args = [1, 2, 3]
40
+ result = InstrumentedClass.class_method(*args)
41
+ assert_equal(args, result)
42
+ end
43
+ end
@@ -5,8 +5,6 @@ if RUBY_VERSION >= '1.9.3'
5
5
  RB
6
6
  end
7
7
 
8
- omit_mocha!
9
-
10
8
  gemfile <<-RB
11
9
  gem 'rails', '~>3.2.16'
12
10
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
@@ -1 +1,2 @@
1
+ <%- advance_time(@delay) if @delay %>
1
2
  This is a partial
@@ -1,4 +1,4 @@
1
-
1
+ <%- advance_time(@delay) if @delay %>
2
2
  <%- 3.times do |i| %>
3
3
  <%= render "a_partial" %>
4
4
  <%- end%>
@@ -218,7 +218,7 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
218
218
  end
219
219
 
220
220
  def test_captured_errors_should_not_include_custom_params_if_config_says_no
221
- with_config(:'capture_attributes.traces' => false) do
221
+ with_config(:'error_collector.capture_attributes' => false) do
222
222
  get '/error/error_with_custom_params'
223
223
  end
224
224
  assert_error_reported_once('bad things')
@@ -79,15 +79,20 @@ class RequestStatsTest < ActionController::TestCase
79
79
  assert_kind_of Array, post.body
80
80
  assert_kind_of Array, post.body.first
81
81
 
82
- sample = post.body.first.first
82
+ sample = post.body.first[0]
83
83
  assert_kind_of Hash, sample
84
84
 
85
85
  assert_equal 'Controller/request_stats/stats_action_with_custom_params', sample['name']
86
86
  assert_encoding 'utf-8', sample['name']
87
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')
88
+ ['blue', 'bar', 'bad'].each do |key|
89
+ assert_not_includes(sample, key)
90
+ end
91
+
92
+ custom_params = post.body.first[1]
93
+ assert_equal 'blue', custom_params['color']
94
+ assert_equal 'bar', custom_params['1']
95
+ assert_false custom_params.has_key?('bad')
91
96
  end
92
97
  end
93
98
 
@@ -10,10 +10,17 @@ ActionController::Base.view_paths = ['app/views']
10
10
 
11
11
  class ViewsController < ApplicationController
12
12
  include Rails.application.routes.url_helpers
13
+
13
14
  def template_render_with_3_partial_renders
14
15
  render 'index'
15
16
  end
16
17
 
18
+ def render_with_delays
19
+ freeze_time
20
+ @delay = 1
21
+ render 'index'
22
+ end
23
+
17
24
  def deep_partial_render
18
25
  render 'deep_partial'
19
26
  end
@@ -63,10 +70,11 @@ class ViewsController < ApplicationController
63
70
  # proc rendering isn't available in rails 3 but you can do nonsense like this
64
71
  # and assign an enumerable object to the response body.
65
72
  def proc_render
66
- streamer = Class.new
67
- def each
68
- 10_000.times do |i|
69
- yield "This is line #{i}\n"
73
+ streamer = Class.new do
74
+ def each
75
+ 10_000.times do |i|
76
+ yield "This is line #{i}\n"
77
+ end
70
78
  end
71
79
  end
72
80
  self.response_body = streamer.new
@@ -77,12 +85,10 @@ class ViewsController < ApplicationController
77
85
  end
78
86
  end
79
87
 
80
- class ViewControllerTest < ActionController::TestCase
81
- tests ViewsController
82
-
88
+ class ViewInstrumentationTest < ActionDispatch::IntegrationTest
83
89
  include MultiverseHelpers
90
+
84
91
  setup_and_teardown_agent do
85
- @controller = ViewsController.new
86
92
  # ActiveSupport testing keeps blowing away my subscribers on
87
93
  # teardown for some reason. Have to keep putting it back.
88
94
  if Rails::VERSION::MAJOR.to_i == 4
@@ -92,128 +98,127 @@ class ViewControllerTest < ActionController::TestCase
92
98
  .subscribe(/^process_action.action_controller$/)
93
99
  end
94
100
  end
95
- end
96
101
 
97
- # SANITY TESTS - Make sure nothing raises errors,
98
- # unless it's supposed to
99
- class SanityTest < ViewControllerTest
100
-
101
- # assert we can call any of these renders with no errors
102
- # (except the one that does raise an error)
103
- (ViewsController.action_methods - ["raise_render"]).each do |method|
104
- test "should not raise errors on GET to #{method.inspect}" do
105
- get method.dup
102
+ (ViewsController.action_methods - ['raise_render']).each do |method|
103
+ define_method("test_sanity_#{method}") do
104
+ get "views/#{method}"
105
+ assert_equal 200, status
106
106
  end
107
107
 
108
- test "should not raise errors on POST to #{method.inspect}" do
109
- post method.dup
108
+ def test_should_allow_uncaught_exception_to_propagate
109
+ get "views/raise_render"
110
+ assert_equal 500, status
110
111
  end
111
- end
112
112
 
113
- test "should allow an uncaught exception to propogate" do
114
- assert_raises RuntimeError do
115
- get :raise_render
113
+ def test_should_count_all_the_template_and_partial_segments
114
+ get 'views/template_render_with_3_partial_renders'
115
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
116
+ assert_equal 5, sample.count_segments, "should be a node for the controller action, the template, and 3 partials (5)"
116
117
  end
117
- end
118
- end
119
118
 
120
- # A controller action that renders 1 template and the same partial 3 times
121
- class NormalishRenderTest < ViewControllerTest
122
- test "should count all the template and partial segments" do
123
- get :template_render_with_3_partial_renders
124
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
125
- assert_equal 5, sample.count_segments, "should be a node for the controller action, the template, and 3 partials (5)"
126
- end
119
+ def test_should_have_3_segments_with_the_correct_metric_name
120
+ get 'views/template_render_with_3_partial_renders'
121
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
127
122
 
128
- test "should have 3 segments with the metric name 'View/views/_a_partial.html.erb/Partial'" do
129
- get :template_render_with_3_partial_renders
130
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
123
+ partial_segments = sample.root_segment.called_segments.first.called_segments.first.called_segments
124
+ assert_equal 3, partial_segments.size, "sanity check"
131
125
 
132
- partial_segments = sample.root_segment.called_segments.first.called_segments.first.called_segments
133
- assert_equal 3, partial_segments.size, "sanity check"
126
+ assert_equal ['View/views/_a_partial.html.erb/Partial'], partial_segments.map(&:metric_name).uniq
127
+ end
134
128
 
135
- assert_equal ['View/views/_a_partial.html.erb/Partial'], partial_segments.map(&:metric_name).uniq
136
- end
137
- end
129
+ # it doesn't seem worth it to get consistent behavior here.
130
+ if Rails::VERSION::MAJOR.to_i == 3 && Rails::VERSION::MINOR.to_i == 0
131
+ def test_should_not_instrument_rendering_of_text
132
+ get 'views/text_render'
133
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
134
+ assert_equal [], sample.root_segment.called_segments.first.called_segments
135
+ end
136
+ else
137
+ def test_should_create_a_metric_for_the_rendered_text
138
+ get 'views/text_render'
139
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
140
+ text_segment = sample.root_segment.called_segments.first.called_segments.first
141
+ assert_equal 'View/text template/Rendering', text_segment.metric_name
142
+ end
143
+ end
138
144
 
139
- class TextRenderTest < ViewControllerTest
140
- # it doesn't seem worth it to get consistent behavior here.
141
- if Rails::VERSION::MAJOR.to_i == 3 && Rails::VERSION::MINOR.to_i == 0
142
- test "should not instrument rendering of text" do
143
- get :text_render
145
+ def test_should_create_a_metric_for_the_rendered_inline_template
146
+ get 'views/inline_render'
144
147
  sample = NewRelic::Agent.agent.transaction_sampler.last_sample
145
- assert_equal [], sample.root_segment.called_segments.first.called_segments
148
+ text_segment = sample.root_segment.called_segments.first.called_segments.first
149
+ assert_equal 'View/inline template/Rendering', text_segment.metric_name
146
150
  end
147
- else
148
- test "should create a metric for the rendered text" do
149
- get :text_render
151
+
152
+ def test_should_create_a_metric_for_the_rendered_haml_template
153
+ get 'views/haml_render'
150
154
  sample = NewRelic::Agent.agent.transaction_sampler.last_sample
151
155
  text_segment = sample.root_segment.called_segments.first.called_segments.first
152
- assert_equal 'View/text template/Rendering', text_segment.metric_name
156
+ assert_equal 'View/views/haml_view.html.haml/Rendering', text_segment.metric_name
153
157
  end
154
- end
155
- end
156
-
157
- class InlineTemplateRenderTest < ViewControllerTest
158
- test "should create a metric for the rendered inline template" do
159
- get :inline_render
160
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
161
- text_segment = sample.root_segment.called_segments.first.called_segments.first
162
- assert_equal 'View/inline template/Rendering', text_segment.metric_name
163
- end
164
- end
165
158
 
166
- class HamlRenderTest < ViewControllerTest
167
- test "should create a metric for the rendered haml template" do
168
- get :haml_render
169
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
170
- text_segment = sample.root_segment.called_segments.first.called_segments.first
171
- assert_equal 'View/views/haml_view.html.haml/Rendering', text_segment.metric_name
172
- end
173
- end
159
+ def test_should_create_a_proper_metric_when_the_template_is_unknown
160
+ get 'views/no_template'
161
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
162
+ text_segment = sample.root_segment.called_segments.first.called_segments.first
174
163
 
175
- class MissingTemplateTest < ViewControllerTest
176
- test "should create an proper metric when the template is unknown" do
177
- get :no_template
178
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
179
- text_segment = sample.root_segment.called_segments.first.called_segments.first
164
+ # Different versions have significant difference in handling, but we're
165
+ # happy enough with what each of them does in the unknown case
166
+ if Rails::VERSION::MAJOR.to_i == 3 && Rails::VERSION::MINOR.to_i == 0
167
+ assert_nil text_segment
168
+ elsif Rails::VERSION::MAJOR.to_i == 3
169
+ assert_equal 'View/collection/Partial', text_segment.metric_name
170
+ else
171
+ assert_equal 'View/(unknown)/Partial', text_segment.metric_name
172
+ end
173
+ end
180
174
 
181
- # Different versions have significant difference in handling, but we're
182
- # happy enough with what each of them does in the unknown case
183
- if Rails::VERSION::MAJOR.to_i == 3 && Rails::VERSION::MINOR.to_i == 0
184
- assert_nil text_segment
185
- elsif Rails::VERSION::MAJOR.to_i == 3
186
- assert_equal 'View/collection/Partial', text_segment.metric_name
187
- else
188
- assert_equal 'View/(unknown)/Partial', text_segment.metric_name
175
+ def test_should_create_a_proper_metric_when_we_render_a_collection
176
+ get 'views/collection_render'
177
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
178
+ text_segment = sample.root_segment.called_segments.first.called_segments.first
179
+ assert_equal "View/foos/_foo.html.haml/Partial", text_segment.metric_name
189
180
  end
190
- end
191
- end
192
181
 
193
- class CollectionTemplateTest < ViewControllerTest
194
- test "should create a proper metric when we render a collection" do
195
- get :collection_render
196
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
197
- text_segment = sample.root_segment.called_segments.first.called_segments.first
198
- assert_equal "View/foos/_foo.html.haml/Partial", text_segment.metric_name
199
- end
200
- end
182
+ [:js_render, :xml_render, :proc_render, :json_render ].each do |action|
183
+ define_method("test_should_not_instrument_rendering_of_#{action}") do
184
+ get "views/#{action}"
185
+ sample = NewRelic::Agent.agent.transaction_sampler.last_sample
186
+ assert_equal [], sample.root_segment.called_segments.first.called_segments
187
+ end
188
+ end
201
189
 
202
- class UninstrumentedRendersTest < ViewControllerTest
203
- [:js_render, :xml_render, :proc_render, :json_render ].each do |action|
204
- test "should not instrument rendering of #{action.inspect}" do
205
- get action
190
+ def test_should_create_a_metric_for_rendered_file_that_does_not_include_the_filename_so_it_doesnt_metric_explode
191
+ get 'views/file_render'
206
192
  sample = NewRelic::Agent.agent.transaction_sampler.last_sample
207
- assert_equal [], sample.root_segment.called_segments.first.called_segments
193
+ text_segment = sample.root_segment.called_segments.first.called_segments.first
194
+ assert_equal 'View/file/Rendering', text_segment.metric_name
208
195
  end
209
- end
210
- end
211
196
 
212
- class FileRenderTest < ViewControllerTest
213
- test "should create a metric for rendered file that does not include the filename so it doesn't metric explode" do
214
- get :file_render
215
- sample = NewRelic::Agent.agent.transaction_sampler.last_sample
216
- text_segment = sample.root_segment.called_segments.first.called_segments.first
217
- assert_equal 'View/file/Rendering', text_segment.metric_name
197
+ def test_exclusive_time_for_template_render_metrics_should_not_include_partial_rendering_time
198
+ get 'views/render_with_delays'
199
+
200
+ expected_stats_partial = {
201
+ :call_count => 3,
202
+ :total_call_time => 3.0,
203
+ :total_exclusive_time => 3.0
204
+ }
205
+
206
+ expected_stats_template = {
207
+ :call_count => 1,
208
+ :total_call_time => 4.0,
209
+ :total_exclusive_time => 1.0 # top-level template takes 1s itself
210
+ }
211
+
212
+ scope = 'Controller/views/render_with_delays'
213
+ partial_metric = 'View/views/_a_partial.html.erb/Partial'
214
+ template_metric = 'View/views/index.html.erb/Rendering'
215
+
216
+ assert_metrics_recorded(
217
+ partial_metric => expected_stats_partial,
218
+ template_metric => expected_stats_template,
219
+ [partial_metric, scope] => expected_stats_partial,
220
+ [template_metric, scope] => expected_stats_template
221
+ )
222
+ end
218
223
  end
219
224
  end