newrelic_rpm 3.11.2.286 → 3.12.0.288

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/.yardopts +2 -0
  4. data/CHANGELOG +39 -4
  5. data/README.md +4 -2
  6. data/lib/new_relic/agent.rb +229 -214
  7. data/lib/new_relic/agent/agent.rb +23 -12
  8. data/lib/new_relic/agent/attribute_filter.rb +242 -0
  9. data/lib/new_relic/agent/attribute_processing.rb +62 -0
  10. data/lib/new_relic/agent/commands/xray_session_collection.rb +4 -1
  11. data/lib/new_relic/agent/configuration/default_source.rb +284 -30
  12. data/lib/new_relic/agent/configuration/high_security_source.rb +0 -8
  13. data/lib/new_relic/agent/configuration/manager.rb +1 -1
  14. data/lib/new_relic/agent/configuration/server_source.rb +86 -31
  15. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -1
  16. data/lib/new_relic/agent/cross_app_monitor.rb +8 -13
  17. data/lib/new_relic/agent/cross_app_tracing.rb +15 -15
  18. data/lib/new_relic/agent/custom_event_aggregator.rb +6 -2
  19. data/lib/new_relic/agent/database.rb +15 -2
  20. data/lib/new_relic/agent/datastores.rb +52 -38
  21. data/lib/new_relic/agent/datastores/metric_helper.rb +2 -1
  22. data/lib/new_relic/agent/encoding_normalizer.rb +82 -0
  23. data/lib/new_relic/agent/error_collector.rb +125 -169
  24. data/lib/new_relic/agent/hash_extensions.rb +26 -0
  25. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +13 -11
  26. data/lib/new_relic/agent/http_clients/uri_util.rb +9 -0
  27. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -3
  28. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +12 -5
  31. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +6 -7
  32. data/lib/new_relic/agent/instrumentation/curb.rb +6 -6
  33. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +4 -4
  34. data/lib/new_relic/agent/instrumentation/grape.rb +4 -3
  35. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -3
  36. data/lib/new_relic/agent/instrumentation/rails/errors.rb +9 -3
  37. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -1
  38. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +9 -7
  39. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +8 -6
  40. data/lib/new_relic/agent/instrumentation/resque.rb +2 -3
  41. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -3
  42. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  43. data/lib/new_relic/agent/javascript_instrumentor.rb +24 -16
  44. data/lib/new_relic/agent/parameter_filtering.rb +8 -1
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
  46. data/lib/new_relic/agent/sql_sampler.rb +1 -0
  47. data/lib/new_relic/agent/stats.rb +0 -4
  48. data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -3
  49. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -0
  50. data/lib/new_relic/agent/supported_versions.rb +2 -2
  51. data/lib/new_relic/agent/traced_method_stack.rb +3 -3
  52. data/lib/new_relic/agent/transaction.rb +141 -118
  53. data/lib/new_relic/agent/transaction/attributes.rb +161 -0
  54. data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +4 -4
  55. data/lib/new_relic/agent/transaction/trace.rb +150 -0
  56. data/lib/new_relic/agent/transaction/trace_node.rb +190 -0
  57. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +2 -2
  58. data/lib/new_relic/agent/transaction_event_aggregator.rb +23 -7
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +37 -62
  60. data/lib/new_relic/agent/transaction_sampler.rb +29 -66
  61. data/lib/new_relic/cli/commands/install.rb +2 -2
  62. data/lib/new_relic/coerce.rb +15 -28
  63. data/lib/new_relic/json_wrapper.rb +14 -73
  64. data/lib/new_relic/noticed_error.rb +81 -5
  65. data/lib/new_relic/rack/browser_monitoring.rb +14 -19
  66. data/lib/new_relic/rack/developer_mode.rb +68 -14
  67. data/lib/new_relic/rack/developer_mode/segment_summary.rb +56 -0
  68. data/lib/new_relic/version.rb +2 -2
  69. data/newrelic.yml +19 -196
  70. data/test/agent_helper.rb +42 -36
  71. data/test/config/newrelic.yml +0 -1
  72. data/test/environments/rails40/Gemfile +1 -1
  73. data/test/environments/rails41/Gemfile +1 -1
  74. data/test/environments/rails42/Gemfile +1 -1
  75. data/test/fixtures/cross_agent_tests/attribute_configuration.json +35 -0
  76. data/test/fixtures/cross_agent_tests/sql_obfuscation/README.md +19 -12
  77. data/test/fixtures/cross_agent_tests/sql_obfuscation/sql_obfuscation.json +365 -0
  78. data/test/multiverse/lib/multiverse/suite.rb +5 -1
  79. data/test/multiverse/suites/active_record/active_record_test.rb +8 -8
  80. data/test/multiverse/suites/agent_only/agent_attributes_test.rb +145 -0
  81. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +8 -0
  82. data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +5 -1
  83. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +6 -6
  84. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  85. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +2 -3
  86. data/test/multiverse/suites/agent_only/synthetics_test.rb +3 -3
  87. data/test/multiverse/suites/agent_only/testing_app.rb +4 -0
  88. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -1
  89. data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +9 -7
  90. data/test/multiverse/suites/curb/Envfile +5 -6
  91. data/test/multiverse/suites/curb/curb_test.rb +4 -5
  92. data/test/multiverse/suites/datamapper/datamapper_test.rb +2 -2
  93. data/test/multiverse/suites/excon/Envfile +11 -4
  94. data/test/multiverse/suites/excon/excon_test.rb +5 -5
  95. data/test/multiverse/suites/grape/config/newrelic.yml +1 -0
  96. data/test/multiverse/suites/grape/grape_test.rb +76 -12
  97. data/test/multiverse/suites/grape/grape_test_api.rb +16 -0
  98. data/test/multiverse/suites/high_security/config/newrelic.yml +43 -3
  99. data/test/multiverse/suites/high_security/high_security_test.rb +165 -9
  100. data/test/multiverse/suites/httpclient/Envfile +5 -1
  101. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  102. data/test/multiverse/suites/memcached/Envfile +1 -1
  103. data/test/multiverse/suites/mongo/Envfile +8 -1
  104. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +29 -29
  105. data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +43 -8
  106. data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +13 -3
  107. data/test/multiverse/suites/rails/Envfile +3 -3
  108. data/test/multiverse/suites/rails/error_tracing_test.rb +52 -31
  109. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +1 -1
  110. data/test/multiverse/suites/rails/ignore_test.rb +1 -1
  111. data/test/multiverse/suites/rails/parameter_capture_test.rb +108 -40
  112. data/test/multiverse/suites/rails/request_statistics_test.rb +10 -4
  113. data/test/multiverse/suites/rails/view_instrumentation_test.rb +24 -24
  114. data/test/multiverse/suites/resque/instrumentation_test.rb +46 -12
  115. data/test/multiverse/suites/sequel/sequel_extension_test.rb +8 -8
  116. data/test/multiverse/suites/sequel/sequel_helpers.rb +11 -11
  117. data/test/multiverse/suites/sequel/sequel_plugin_test.rb +11 -11
  118. data/test/multiverse/suites/sidekiq/Envfile +1 -4
  119. data/test/multiverse/suites/sidekiq/after_suite.rb +9 -0
  120. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +49 -16
  121. data/test/multiverse/suites/sidekiq/test_worker.rb +1 -2
  122. data/test/multiverse/suites/sinatra/Envfile +1 -1
  123. data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
  124. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -4
  125. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -4
  126. data/test/multiverse/suites/sinatra/sinatra_parameter_capture_test.rb +65 -0
  127. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -11
  128. data/test/multiverse/suites/typhoeus/Envfile +8 -2
  129. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +4 -4
  130. data/test/new_relic/agent/agent/connect_test.rb +13 -9
  131. data/test/new_relic/agent/agent_test.rb +34 -24
  132. data/test/new_relic/agent/attribute_filter_test.rb +218 -0
  133. data/test/new_relic/agent/attribute_processing_test.rb +160 -0
  134. data/test/new_relic/agent/configuration/default_source_test.rb +88 -0
  135. data/test/new_relic/agent/configuration/manager_test.rb +3 -4
  136. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +3 -1
  137. data/test/new_relic/agent/configuration/server_source_test.rb +39 -0
  138. data/test/new_relic/agent/cross_app_monitor_test.rb +6 -30
  139. data/test/new_relic/agent/cross_app_tracing_test.rb +12 -12
  140. data/test/new_relic/agent/database/sql_obfuscation_test.rb +39 -65
  141. data/test/new_relic/agent/datastores/metric_helper_test.rb +36 -0
  142. data/test/new_relic/agent/encoding_normalizer_test.rb +66 -0
  143. data/test/new_relic/agent/error_collector_test.rb +181 -34
  144. data/test/new_relic/agent/hash_extensions_test.rb +34 -0
  145. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +20 -23
  146. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +12 -12
  147. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +5 -5
  148. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +4 -4
  149. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +21 -11
  150. data/test/new_relic/agent/javascript_instrumentor_test.rb +69 -45
  151. data/test/new_relic/agent/pipe_service_test.rb +2 -2
  152. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
  153. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +8 -7
  154. data/test/new_relic/agent/stats_engine/stats_hash_test.rb +2 -2
  155. data/test/new_relic/agent/threading/backtrace_node_test.rb +2 -2
  156. data/test/new_relic/agent/transaction/attributes_test.rb +276 -0
  157. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +10 -10
  158. data/test/new_relic/agent/transaction/trace_node_test.rb +361 -0
  159. data/test/new_relic/agent/transaction/trace_test.rb +394 -0
  160. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
  161. data/test/new_relic/agent/transaction_event_aggregator_test.rb +127 -57
  162. data/test/new_relic/agent/transaction_sample_builder_test.rb +70 -78
  163. data/test/new_relic/agent/transaction_sampler_test.rb +76 -185
  164. data/test/new_relic/agent/transaction_test.rb +283 -135
  165. data/test/new_relic/agent_test.rb +27 -12
  166. data/test/new_relic/cli/commands/install_test.rb +27 -0
  167. data/test/new_relic/coerce_test.rb +0 -59
  168. data/test/new_relic/data_container_tests.rb +5 -5
  169. data/test/new_relic/fake_collector.rb +27 -9
  170. data/test/new_relic/filtering_test_app.rb +2 -1
  171. data/test/new_relic/http_client_test_cases.rb +16 -16
  172. data/test/new_relic/json_wrapper_test.rb +0 -54
  173. data/test/new_relic/marshalling_test_cases.rb +1 -0
  174. data/test/new_relic/multiverse_helpers.rb +144 -0
  175. data/test/new_relic/noticed_error_test.rb +112 -9
  176. data/test/new_relic/rack/browser_monitoring_test.rb +12 -7
  177. data/test/new_relic/{transaction_analysis → rack/developer_mode}/segment_summary_test.rb +5 -4
  178. data/test/new_relic/rack/developer_mode_test.rb +17 -3
  179. data/test/new_relic/rack/error_collector_test.rb +1 -1
  180. data/test/performance/lib/performance/instrumentation/stackprof.rb +1 -1
  181. data/test/performance/script/runner +2 -2
  182. data/test/performance/suites/active_record.rb +3 -3
  183. data/test/performance/suites/agent_attributes.rb +62 -0
  184. data/test/performance/suites/rack_middleware.rb +78 -28
  185. data/test/performance/suites/transaction_tracing.rb +35 -0
  186. data/test/test_helper.rb +9 -1
  187. data/ui/helpers/developer_mode_helper.rb +16 -23
  188. data/ui/views/newrelic/_sample.rhtml +3 -3
  189. data/ui/views/newrelic/_segment.rhtml +1 -1
  190. data/ui/views/newrelic/_show_sample_summary.rhtml +1 -1
  191. data/ui/views/newrelic/show_sample.rhtml +5 -4
  192. metadata +23 -80
  193. data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +0 -25
  194. data/lib/new_relic/transaction_analysis.rb +0 -80
  195. data/lib/new_relic/transaction_analysis/segment_summary.rb +0 -53
  196. data/lib/new_relic/transaction_sample.rb +0 -207
  197. data/lib/new_relic/transaction_sample/composite_segment.rb +0 -31
  198. data/lib/new_relic/transaction_sample/fake_segment.rb +0 -13
  199. data/lib/new_relic/transaction_sample/segment.rb +0 -197
  200. data/lib/new_relic/transaction_sample/summary_segment.rb +0 -25
  201. data/lib/new_relic/url_rule.rb +0 -18
  202. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.obfuscated +0 -1
  203. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.sql +0 -1
  204. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.obfuscated +0 -1
  205. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.sql +0 -1
  206. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.obfuscated +0 -1
  207. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.sql +0 -1
  208. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.obfuscated +0 -2
  209. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.sql +0 -2
  210. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.obfuscated +0 -1
  211. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.sql +0 -1
  212. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.obfuscated +0 -2
  213. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.sql +0 -2
  214. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.obfuscated +0 -1
  215. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.sql +0 -1
  216. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.obfuscated +0 -1
  217. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.sql +0 -4
  218. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_double_quoted_string.mysql.sql +0 -1
  219. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_single_quoted_string.sql +0 -1
  220. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.obfuscated +0 -1
  221. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.sql +0 -1
  222. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.obfuscated +0 -1
  223. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.sql +0 -1
  224. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.obfuscated +0 -1
  225. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.sql +0 -1
  226. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/README.md +0 -4
  227. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.obfuscated +0 -1
  228. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.sql +0 -2
  229. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.obfuscated +0 -1
  230. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.sql +0 -2
  231. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.obfuscated +0 -1
  232. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.sql +0 -4
  233. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.obfuscated +0 -1
  234. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.sql +0 -3
  235. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.obfuscated +0 -1
  236. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.sql +0 -1
  237. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.obfuscated +0 -1
  238. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.sql +0 -1
  239. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.obfuscated +0 -1
  240. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.sql +0 -1
  241. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.obfuscated +0 -1
  242. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.sql +0 -4
  243. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.obfuscated +0 -1
  244. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.sql +0 -1
  245. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.obfuscated +0 -1
  246. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.sql +0 -2
  247. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.obfuscated +0 -1
  248. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.sql +0 -1
  249. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.obfuscated +0 -1
  250. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.sql +0 -1
  251. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.obfuscated +0 -1
  252. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.sql +0 -4
  253. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.obfuscated +0 -1
  254. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.sql +0 -1
  255. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.obfuscated +0 -1
  256. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.sql +0 -1
  257. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.obfuscated +0 -1
  258. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.sql +0 -1
  259. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.obfuscated +0 -1
  260. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.sql +0 -1
  261. data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -261
  262. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +0 -52
  263. data/test/new_relic/transaction_analysis_test.rb +0 -125
  264. data/test/new_relic/transaction_sample/composite_segment_test.rb +0 -38
  265. data/test/new_relic/transaction_sample/fake_segment_test.rb +0 -18
  266. data/test/new_relic/transaction_sample/segment_test.rb +0 -361
  267. data/test/new_relic/transaction_sample/summary_segment_test.rb +0 -34
  268. data/test/new_relic/transaction_sample_subtest_test.rb +0 -41
  269. data/test/new_relic/transaction_sample_test.rb +0 -361
@@ -3,43 +3,124 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
6
+ require 'new_relic/agent/transaction/attributes'
6
7
 
7
8
  class NewRelic::Agent::NoticedErrorTest < Minitest::Test
8
9
  include NewRelic::TestHelpers::Exceptions
9
10
 
10
11
  def setup
11
12
  @path = 'foo/bar/baz'
12
- @params = { 'key' => 'val' }
13
+
14
+ freeze_time
13
15
  @time = Time.now
16
+
17
+ @attributes = NewRelic::Agent::Transaction::Attributes.new(NewRelic::Agent.instance.attribute_filter)
18
+ @attributes_from_notice_error = { :user => 'params' }
14
19
  end
15
20
 
16
21
  def test_to_collector_array
17
22
  e = TestError.new('test exception')
18
- error = NewRelic::NoticedError.new(@path, @params, e, @time)
23
+
24
+ error = create_error(e)
25
+ error.request_uri = "http://com.google"
26
+ error.attributes_from_notice_error = @attributes_from_notice_error
27
+
19
28
  expected = [
20
- (@time.to_f * 1000).round, @path, 'test exception', 'NewRelic::TestHelpers::Exceptions::TestError', @params
29
+ (@time.to_f * 1000).round,
30
+ @path,
31
+ 'test exception',
32
+ 'NewRelic::TestHelpers::Exceptions::TestError',
33
+ {
34
+ :request_uri => 'http://com.google',
35
+ 'userAttributes' => { 'user' => 'params' },
36
+ 'agentAttributes' => {},
37
+ 'intrinsics' => {}
38
+ }
39
+ ]
40
+ assert_equal expected, error.to_collector_array
41
+ end
42
+
43
+ def test_to_collector_array_merges_custom_attributes_and_params
44
+ e = TestError.new('test exception')
45
+ @attributes.merge_custom_attributes(:custom => "attribute")
46
+
47
+ error = create_error(e)
48
+ error.attributes_from_notice_error = @attributes_from_notice_error
49
+
50
+ actual = extract_attributes(error)
51
+ expected = {
52
+ 'userAttributes' => {
53
+ 'user' => 'params',
54
+ 'custom' => 'attribute'
55
+ },
56
+ 'agentAttributes' => {},
57
+ 'intrinsics' => {}
58
+ }
59
+
60
+ assert_equal expected, actual
61
+ end
62
+
63
+ def test_to_collector_array_includes_agent_attributes
64
+ e = TestError.new('test exception')
65
+ @attributes.add_agent_attribute(:agent, "attribute", NewRelic::Agent::AttributeFilter::DST_ALL)
66
+ error = create_error(e)
67
+
68
+ actual = extract_attributes(error)
69
+ assert_equal({:agent => "attribute"}, actual["agentAttributes"])
70
+ end
71
+
72
+ def test_to_collector_array_includes_intrinsic_attributes
73
+ e = TestError.new('test exception')
74
+ @attributes.add_intrinsic_attribute(:intrinsic, "attribute")
75
+ error = create_error(e)
76
+
77
+ actual = extract_attributes(error)
78
+ assert_equal({:intrinsic => "attribute"}, actual["intrinsics"])
79
+ end
80
+
81
+ def test_to_collector_array_happy_without_attribute_collections
82
+ error = NewRelic::NoticedError.new(@path, "BOOM")
83
+
84
+ expected = [
85
+ (@time.to_f * 1000).round,
86
+ @path,
87
+ "BOOM",
88
+ "Error",
89
+ {
90
+ 'userAttributes' => {},
91
+ 'agentAttributes' => {},
92
+ 'intrinsics' => {}
93
+ }
21
94
  ]
22
95
  assert_equal expected, error.to_collector_array
23
96
  end
24
97
 
25
98
  def test_to_collector_array_with_bad_values
26
- error = NewRelic::NoticedError.new(@path, @params, nil, Rational(10, 1))
99
+ error = NewRelic::NoticedError.new(@path, nil, Rational(10, 1))
27
100
  expected = [
28
- 10_000.0, @path, "<no message>", "Error", @params
101
+ 10_000.0,
102
+ @path,
103
+ "<no message>",
104
+ "Error",
105
+ {
106
+ 'userAttributes' => {},
107
+ 'agentAttributes' => {},
108
+ 'intrinsics' => {}
109
+ }
29
110
  ]
30
111
  assert_equal expected, error.to_collector_array
31
112
  end
32
113
 
33
114
  def test_handles_non_string_exception_messages
34
115
  e = Exception.new({ :non => :string })
35
- error = NewRelic::NoticedError.new(@path, @params, e, @time)
116
+ error = NewRelic::NoticedError.new(@path, e, @time)
36
117
  assert_equal(String, error.message.class)
37
118
  end
38
119
 
39
120
  def test_strips_message_from_exceptions_in_high_security_mode
40
121
  with_config(:high_security => true) do
41
122
  e = TestError.new('test exception')
42
- error = NewRelic::NoticedError.new(@path, @params, e, @time)
123
+ error = NewRelic::NoticedError.new(@path, e, @time)
43
124
 
44
125
  assert_equal NewRelic::NoticedError::STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE, error.message
45
126
  end
@@ -48,7 +129,7 @@ class NewRelic::Agent::NoticedErrorTest < Minitest::Test
48
129
  def test_permits_messages_from_whitelisted_exceptions_in_high_security_mode
49
130
  with_config(:'strip_exception_messages.whitelist' => 'NewRelic::TestHelpers::Exceptions::TestError') do
50
131
  e = TestError.new('whitelisted test exception')
51
- error = NewRelic::NoticedError.new(@path, @params, e, @time)
132
+ error = NewRelic::NoticedError.new(@path, e, @time)
52
133
 
53
134
  assert_equal 'whitelisted test exception', error.message
54
135
  end
@@ -87,8 +168,30 @@ class NewRelic::Agent::NoticedErrorTest < Minitest::Test
87
168
  def test_handles_exception_with_nil_original_exception
88
169
  e = Exception.new('Buffy FOREVER')
89
170
  e.stubs(:original_exception).returns(nil)
90
- error = NewRelic::NoticedError.new(@path, @params, e, @time)
171
+ error = NewRelic::NoticedError.new(@path, e, @time)
91
172
  assert_equal(error.message.to_s, 'Buffy FOREVER')
92
173
  end
93
174
 
175
+ def test_intrinsics_always_get_sent
176
+ with_config(:'error_collector.attributes.enabled' => false) do
177
+ attributes = NewRelic::Agent::Transaction::Attributes.new(NewRelic::Agent.instance.attribute_filter)
178
+ attributes.add_intrinsic_attribute(:intrinsic, "attribute")
179
+
180
+ error = NewRelic::NoticedError.new(@path, Exception.new("O_o"))
181
+ error.attributes = attributes
182
+
183
+ serialized_attributes = extract_attributes(error)
184
+ assert_equal({ :intrinsic => "attribute" }, serialized_attributes["intrinsics"])
185
+ end
186
+ end
187
+
188
+ def create_error(exception = StandardError.new)
189
+ noticed_error = NewRelic::NoticedError.new(@path, exception, @time)
190
+ noticed_error.attributes = @attributes
191
+ noticed_error
192
+ end
193
+
194
+ def extract_attributes(error)
195
+ error.to_collector_array[4]
196
+ end
94
197
  end
@@ -179,14 +179,19 @@ EOL
179
179
  assert last_response.ok?
180
180
  end
181
181
 
182
- def test_calculate_content_length_accounts_for_multibyte_characters_for_186
183
- String.stubs(:respond_to?).with(:bytesize).returns(false)
184
- browser_monitoring = NewRelic::Rack::BrowserMonitoring.new(mock('app'))
185
- assert_equal 24, browser_monitoring.calculate_content_length("猿も木から落ちる")
182
+ def test_content_length_set_when_we_modify_source
183
+ original_headers = {
184
+ "Content-Length" => 0,
185
+ "Content-Type" => "text/html"
186
+ }
187
+ headers = headers_from_request(original_headers, "<html><body></body></html>")
188
+ assert_equal "390", headers["Content-Length"]
186
189
  end
187
190
 
188
- def test_calculate_content_length_accounts_for_multibyte_characters_for_modern_ruby
189
- browser_monitoring = NewRelic::Rack::BrowserMonitoring.new(mock('app'))
190
- assert_equal 18, browser_monitoring.calculate_content_length("七転び八起き")
191
+ def headers_from_request(headers, content)
192
+ app = mock('app', :call => [200, headers, [content]])
193
+ browser_monitoring = NewRelic::Rack::BrowserMonitoring.new(app)
194
+ _, headers, _ = browser_monitoring.call({})
195
+ headers
191
196
  end
192
197
  end
@@ -2,13 +2,14 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helper'))
6
- require 'new_relic/transaction_analysis/segment_summary'
7
- class NewRelic::TransactionAnalysis::SegmentSummaryTest < Minitest::Test
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..','test_helper'))
6
+ require 'new_relic/rack/developer_mode'
7
+ require 'new_relic/rack/developer_mode/segment_summary'
8
8
 
9
+ class SegmentSummaryTest < Minitest::Test
9
10
  def setup
10
11
  @sample = mock('sample')
11
- @ss = NewRelic::TransactionAnalysis::SegmentSummary.new('Controller/foo', @sample)
12
+ @ss = NewRelic::Rack::DeveloperMode::SegmentSummary.new('Controller/foo', @sample)
12
13
  end
13
14
 
14
15
  # these are mostly stub tests just making sure that the API doesn't
@@ -53,11 +53,11 @@ class DeveloperModeTest < Minitest::Test
53
53
 
54
54
  def test_explain_sql_displays_query_plan
55
55
  sample = @sampler.dev_mode_sample_buffer.samples[0]
56
- sql_segment = sample.sql_segments[0]
56
+ sql_segment = app.send(:sql_segments, sample)[0]
57
57
  explain_results = NewRelic::Agent::Database.process_resultset(dummy_mysql_explain_result, 'mysql')
58
58
 
59
- NewRelic::TransactionSample::Segment.any_instance.expects(:explain_sql).returns(explain_results)
60
- get "/newrelic/explain_sql?id=#{sample.sample_id}&segment=#{sql_segment.segment_id}"
59
+ NewRelic::Agent::Transaction::TraceNode.any_instance.expects(:explain_sql).returns(explain_results)
60
+ get "/newrelic/explain_sql?id=#{sample.sample_id}&segment=#{sql_segment.object_id}"
61
61
 
62
62
  assert last_response.ok?
63
63
  assert last_response.body.include?('PRIMARY')
@@ -72,6 +72,20 @@ class DeveloperModeTest < Minitest::Test
72
72
 
73
73
  assert_empty NewRelic::Agent.instance.transaction_sampler.dev_mode_sample_buffer.samples
74
74
  end
75
+
76
+ def test_request_attributes
77
+ attributes = NewRelic::Agent::Transaction::Attributes.new(NewRelic::Agent.instance.attribute_filter)
78
+ attributes.add_agent_attribute("request.parameters.foo", "bar", NewRelic::Agent::AttributeFilter::DST_ALL)
79
+ attributes.add_agent_attribute(:"request.headers.referer", "/somewhere", NewRelic::Agent::AttributeFilter::DST_ALL)
80
+ sample = stub(:attributes => attributes)
81
+
82
+ expected = {
83
+ "request.parameters.foo" => "bar"
84
+ }
85
+
86
+ result = app.send(:request_attributes_for, sample)
87
+ assert_equal expected, result
88
+ end
75
89
  end
76
90
 
77
91
  else
@@ -66,7 +66,7 @@ module NewRelic::Rack
66
66
  end
67
67
 
68
68
  assert_equal('unhandled error', last_error.message)
69
- assert_equal('/foo/bar', last_error.params[:request_uri])
69
+ assert_equal('/foo/bar', last_error.request_uri)
70
70
  end
71
71
  end
72
72
 
@@ -5,7 +5,7 @@
5
5
  module Performance
6
6
  module Instrumentation
7
7
  class StackProfProfile < Instrumentor
8
- platforms :mri_21
8
+ platforms :mri_21, :mri_22
9
9
 
10
10
  def self.setup
11
11
  require 'tmpdir'
@@ -39,9 +39,9 @@ parser = OptionParser.new do |opts|
39
39
  options[:list] = true
40
40
  end
41
41
 
42
- opts.on("-s", "--suite=NAME", "Filter to just run a single test suite") do |name|
42
+ opts.on("-s", "--suite=NAME", "Filter test suites to run (allows comma separated list)") do |name|
43
43
  options[:suite] ||= []
44
- options[:suite] << name
44
+ options[:suite].concat(name.split(","))
45
45
  end
46
46
 
47
47
  opts.on("-n", "--name=NAME", "Filter tests to those matching NAME") do |name|
@@ -2,13 +2,13 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- require 'new_relic/agent/instrumentation/active_record_helper'
6
5
 
7
6
  class ActiveRecordTest < Performance::TestCase
7
+ def setup
8
+ require 'new_relic/agent/instrumentation/active_record_helper'
8
9
 
9
- ActiveRecordHelper = NewRelic::Agent::Instrumentation::ActiveRecordHelper unless defined?(ActiveRecordHelper)
10
+ const_set(:ActiveRecordHelper, NewRelic::Agent::Instrumentation::ActiveRecordHelper) unless defined?(ActiveRecordHelper)
10
11
 
11
- def setup
12
12
  if ActiveRecordHelper.respond_to?(:metrics_for)
13
13
  @run = ActiveRecordHelper.method(:metrics_for)
14
14
  else
@@ -0,0 +1,62 @@
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 'securerandom'
6
+
7
+ class AgentAttributesTests < Performance::TestCase
8
+ def setup
9
+ require 'new_relic/agent/attribute_filter'
10
+ end
11
+
12
+ ALPHA = "alpha".freeze
13
+ BETA = "beta".freeze
14
+
15
+ def test_empty_agent_attributes
16
+ @filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
17
+
18
+ measure do
19
+ @filter.apply(ALPHA, NewRelic::Agent::AttributeFilter::DST_ALL)
20
+ @filter.apply(BETA, NewRelic::Agent::AttributeFilter::DST_ALL)
21
+ end
22
+ end
23
+
24
+ def test_with_attribute_rules
25
+ with_config(:'attributes.include' => ['alpha'],
26
+ :'attributes.exclude' => ['beta']) do
27
+
28
+ @filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
29
+
30
+ measure do
31
+ @filter.apply(ALPHA, NewRelic::Agent::AttributeFilter::DST_ALL)
32
+ @filter.apply(BETA, NewRelic::Agent::AttributeFilter::DST_ALL)
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_with_wildcards
38
+ with_config(:'attributes.include' => ['alpha*'],
39
+ :'attributes.exclude' => ['beta*']) do
40
+
41
+ @filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
42
+
43
+ measure do
44
+ @filter.apply(ALPHA, NewRelic::Agent::AttributeFilter::DST_ALL)
45
+ @filter.apply(BETA, NewRelic::Agent::AttributeFilter::DST_ALL)
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_with_tons_o_rules
51
+ with_config(:'attributes.include' => 100.times.map { SecureRandom.hex },
52
+ :'attributes.exclude' => 100.times.map { SecureRandom.hex }) do
53
+
54
+ @filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
55
+
56
+ measure do
57
+ @filter.apply(ALPHA, NewRelic::Agent::AttributeFilter::DST_ALL)
58
+ @filter.apply(BETA, NewRelic::Agent::AttributeFilter::DST_ALL)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -29,6 +29,28 @@ class RackMiddleware < Performance::TestCase
29
29
  class TestMiddlewareI < TestMiddleware; def call(e); @app.call(e); end; end
30
30
  class TestMiddlewareJ < TestMiddleware; def call(e); @app.call(e); end; end
31
31
 
32
+ class TestAppWithParams
33
+ def call(env)
34
+ params = {
35
+ 'user' => {
36
+ 'shipping_address' => {
37
+ 'street' => '1234 Nowhere Road',
38
+ 'city' => 'Nowhere',
39
+ 'state' => 'TX'
40
+ },
41
+ 'billing_address' => {
42
+ 'street' => '4321 Nowhere Lane',
43
+ 'city' => 'Nowhere',
44
+ 'state' => 'TX'
45
+ }
46
+ }
47
+ }
48
+ perform_action_with_newrelic_trace(:name => 'dorkbot', :params => params) do
49
+ [200, { 'Content-Type' => 'text/html' }, ['<body>hi</body>']]
50
+ end
51
+ end
52
+ end
53
+
32
54
  class TestApp
33
55
  def call(env)
34
56
  [200, { 'Content-Type' => 'text/html' }, ['<body>hi</body>']]
@@ -37,45 +59,59 @@ class RackMiddleware < Performance::TestCase
37
59
 
38
60
  def setup
39
61
  require 'new_relic/rack/browser_monitoring'
40
- require 'new_relic/rack/error_collector'
41
- require 'new_relic/rack/agent_hooks'
62
+
63
+ @config = {
64
+ :beacon => 'beacon',
65
+ :browser_key => 'browserKey',
66
+ :js_agent_loader => 'loader',
67
+ :encoding_key => 'lolz',
68
+ :application_id => '5, 6', # collector can return app multiple ids
69
+ :'rum.enabled' => true,
70
+ :license_key => 'a' * 40,
71
+ :developer_mode => false
72
+ }
73
+ NewRelic::Agent.config.add_config_for_testing(@config)
42
74
 
43
75
  NewRelic::Agent.manual_start(
44
76
  :developer_mode => false,
45
77
  :monitor_mode => false
46
78
  )
47
79
 
48
- @config = {
49
- :beacon => 'beacon',
50
- :browser_key => 'browserKey',
51
- :js_agent_loader => 'loader',
52
- :encoding_key => 'lolz',
53
- :application_id => '5, 6', # collector can return app multiple ids
54
- :'rum.enabled' => true,
55
- :license_key => 'a' * 40,
56
- :developer_mode => false
57
- }
58
- NewRelic::Agent.config.add_config_for_testing(@config)
59
-
60
80
  NewRelic::Agent.agent.events.notify(:finished_configuring)
61
81
 
82
+ middlewares = [
83
+ TestMiddlewareA,
84
+ TestMiddlewareB,
85
+ TestMiddlewareC,
86
+ TestMiddlewareD,
87
+ TestMiddlewareE,
88
+ TestMiddlewareF,
89
+ TestMiddlewareG,
90
+ TestMiddlewareH,
91
+ TestMiddlewareI,
92
+ TestMiddlewareJ,
93
+ NewRelic::Rack::BrowserMonitoring
94
+ ]
95
+
96
+ TestAppWithParams.class_eval do
97
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
98
+ end
99
+
62
100
  @stack = Rack::Builder.new do
63
- use TestMiddlewareA
64
- use TestMiddlewareB
65
- use TestMiddlewareC
66
- use TestMiddlewareD
67
- use TestMiddlewareE
68
- use TestMiddlewareF
69
- use TestMiddlewareG
70
- use TestMiddlewareH
71
- use TestMiddlewareI
72
- use TestMiddlewareJ
73
- use NewRelic::Rack::AgentHooks
74
- use NewRelic::Rack::BrowserMonitoring
75
- use NewRelic::Rack::ErrorCollector
101
+ middlewares.each { |m| use m }
76
102
  run TestApp.new
77
103
  end.to_app
78
- @env = {}
104
+
105
+ @stack_with_params = Rack::Builder.new do
106
+ middlewares.each { |m| use m }
107
+ run TestAppWithParams.new
108
+ end.to_app
109
+
110
+ @env = {
111
+ 'SCRIPT_NAME' => '',
112
+ 'PATH_INFO' => '/users/12/blogs',
113
+ 'QUERY_STRING' => 'q=foobar'
114
+ }
79
115
  end
80
116
 
81
117
  def test_basic_middleware_stack()
@@ -83,4 +119,18 @@ class RackMiddleware < Performance::TestCase
83
119
  @stack.call(@env.dup)
84
120
  end
85
121
  end
122
+
123
+ def test_request_with_params_capture_params_off
124
+ measure do
125
+ @stack_with_params.call(@env.dup)
126
+ end
127
+ end
128
+
129
+ def test_request_with_params_capture_params_on
130
+ NewRelic::Agent.config.add_config_for_testing(:capture_params => true)
131
+ NewRelic::Agent.agent.events.notify(:finished_configuring)
132
+ measure do
133
+ @stack_with_params.call(@env.dup)
134
+ end
135
+ end
86
136
  end