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
@@ -0,0 +1,66 @@
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 'new_relic/agent/encoding_normalizer.rb'
7
+
8
+ class EncodingNormalizerTest < Minitest::Test
9
+ EncodingNormalizer = NewRelic::Agent::EncodingNormalizer
10
+
11
+ def test_normalize_object_converts_symbol_values_to_strings
12
+ result = EncodingNormalizer.normalize_object([:foo, :bar])
13
+ assert_equal(['foo', 'bar'], result)
14
+ end
15
+
16
+ def test_normalize_object_converts_symbols_in_hash_to_strings
17
+ result = EncodingNormalizer.normalize_object({:key => :value})
18
+ assert_equal({'key' => 'value'}, result)
19
+ end
20
+
21
+ if NewRelic::LanguageSupport.supports_string_encodings?
22
+ def test_normalize_string_returns_input_if_correctly_encoded_utf8
23
+ string = "i want a pony"
24
+ result = EncodingNormalizer.normalize_string(string)
25
+ assert_same(string, result)
26
+ assert_equal(Encoding.find('UTF-8'), result.encoding)
27
+ end
28
+
29
+ def test_normalize_string_returns_munged_copy_if_ascii_8bit
30
+ string = (0..255).to_a.pack("C*")
31
+ result = EncodingNormalizer.normalize_string(string)
32
+ refute_same(string, result)
33
+ assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
34
+ assert_equal(string, result.dup.force_encoding('ASCII-8BIT'))
35
+ end
36
+
37
+ def test_normalize_string_returns_munged_copy_if_invalid_utf8
38
+ string = (0..255).to_a.pack("C*").force_encoding('UTF-8')
39
+ result = EncodingNormalizer.normalize_string(string)
40
+ refute_same(result, string)
41
+ assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
42
+ assert_equal(string, result.dup.force_encoding('UTF-8'))
43
+ end
44
+
45
+ def test_normalize_string_returns_munged_copy_if_other_convertible_encoding
46
+ string = "i want a pony".encode('UTF-16LE')
47
+ result = EncodingNormalizer.normalize_string(string)
48
+ refute_same(result, string)
49
+ assert_equal(Encoding.find('UTF-8'), result.encoding)
50
+ assert_equal(string, result.encode('UTF-16LE'))
51
+ end
52
+
53
+ def test_normalize_string_returns_munged_copy_if_other_non_convertible_enocding
54
+ # Attempting to convert from UTF-7 to UTF-8 in Ruby will raise an
55
+ # Encoding::ConverterNotFoundError, which is what we're trying to
56
+ # replicate for this test case.
57
+ # The following UTF-7 string decodes to 'Jyväskylä', a city in Finland
58
+ string = "Jyv+AOQ-skyl+AOQ-".force_encoding("UTF-7")
59
+ assert string.valid_encoding?
60
+ result = EncodingNormalizer.normalize_string(string)
61
+ refute_same(result, string)
62
+ assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
63
+ assert_equal('Jyv+AOQ-skyl+AOQ-'.force_encoding('ISO-8859-1'), result)
64
+ end
65
+ end
66
+ end
@@ -8,7 +8,10 @@ require 'new_relic/agent/internal_agent_error'
8
8
 
9
9
  class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
10
10
  def setup
11
- @test_config = { :capture_params => true }
11
+ @test_config = {
12
+ :capture_params => true,
13
+ :disable_harvest_thread => true
14
+ }
12
15
  NewRelic::Agent.config.add_config_for_testing(@test_config)
13
16
 
14
17
  @error_collector = NewRelic::Agent::ErrorCollector.new
@@ -43,25 +46,25 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
43
46
 
44
47
  def test_empty
45
48
  @error_collector.harvest!
46
- @error_collector.notice_error(nil, :metric=> 'path', :request_params => {:x => 'y'})
49
+ @error_collector.notice_error(nil, :metric=> 'path')
47
50
  errors = @error_collector.harvest!
48
51
 
49
52
  assert_equal 0, errors.length
50
53
 
51
- @error_collector.notice_error('Some error message', :metric=> 'path', :request_params => {:x => 'y'})
54
+ @error_collector.notice_error('Some error message', :metric=> 'path')
52
55
  errors = @error_collector.harvest!
53
56
 
54
57
  err = errors.first
55
58
  assert_equal 'Some error message', err.message
56
- assert_equal 'y', err.params[:request_params][:x]
57
- assert_equal '', err.params[:request_uri]
58
- assert_equal '', err.params[:request_referer]
59
+ assert_equal '', err.request_uri
59
60
  assert_equal 'path', err.path
60
61
  assert_equal 'Error', err.exception_class_name
61
62
  end
62
63
 
63
64
  def test_simple
64
- @error_collector.notice_error(StandardError.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
65
+ @error_collector.notice_error(StandardError.new("message"),
66
+ :uri => '/myurl/',
67
+ :metric => 'path')
65
68
 
66
69
  errors = @error_collector.harvest!
67
70
 
@@ -69,22 +72,32 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
69
72
 
70
73
  err = errors.first
71
74
  assert_equal 'message', err.message
72
- assert_equal 'y', err.params[:request_params][:x]
73
- assert_equal '/myurl/', err.params[:request_uri]
74
- assert_equal 'test_referer', err.params[:request_referer]
75
+ assert_equal '/myurl/', err.request_uri
75
76
  assert_equal 'path', err.path
76
77
  assert_equal 'StandardError', err.exception_class_name
77
78
 
78
79
  # the collector should now return an empty array since nothing
79
80
  # has been added since its last harvest
80
81
  errors = @error_collector.harvest!
81
- assert errors.length == 0
82
+ assert_empty errors
83
+ end
84
+
85
+ def test_drops_deprecated_options
86
+ expects_logging(:warn, any_parameters)
87
+ @error_collector.notice_error(StandardError.new("message"),
88
+ :referer => "lalalalala",
89
+ :request => stub('request'),
90
+ :request_params => {:x => 'y'})
91
+
92
+ errors = @error_collector.harvest!
93
+
94
+ assert_empty errors.first.attributes_from_notice_error
82
95
  end
83
96
 
84
97
  def test_long_message
85
98
  #yes, times 500. it's a 5000 byte string. Assuming strings are
86
99
  #still 1 byte / char.
87
- @error_collector.notice_error(StandardError.new("1234567890" * 500), :uri => '/myurl/', :metric => 'path', :request_params => {:x => 'y'})
100
+ @error_collector.notice_error(StandardError.new("1234567890" * 500), :uri => '/myurl/', :metric => 'path')
88
101
 
89
102
  errors = @error_collector.harvest!
90
103
 
@@ -96,13 +109,13 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
96
109
  end
97
110
 
98
111
  def test_collect_failover
99
- @error_collector.notice_error(StandardError.new("message"), :metric => 'first', :request_params => {:x => 'y'})
112
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'first')
100
113
 
101
114
  errors = @error_collector.harvest!
102
115
 
103
- @error_collector.notice_error(StandardError.new("message"), :metric => 'second', :request_params => {:x => 'y'})
104
- @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
105
- @error_collector.notice_error(StandardError.new("message"), :metric => 'last', :request_params => {:x => 'y'})
116
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'second')
117
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path')
118
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'last')
106
119
 
107
120
  @error_collector.merge!(errors)
108
121
  errors = @error_collector.harvest!
@@ -110,8 +123,8 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
110
123
  assert_equal 4, errors.length
111
124
  assert_equal_unordered(%w(first second path last), errors.map { |e| e.path })
112
125
 
113
- @error_collector.notice_error(StandardError.new("message"), :metric => 'first', :request_params => {:x => 'y'})
114
- @error_collector.notice_error(StandardError.new("message"), :metric => 'last', :request_params => {:x => 'y'})
126
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'first')
127
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'last')
115
128
 
116
129
  errors = @error_collector.harvest!
117
130
  assert_equal 2, errors.length
@@ -120,20 +133,22 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
120
133
  end
121
134
 
122
135
  def test_queue_overflow
123
-
124
- max_q_length = 20 # for some reason I can't read the constant in ErrorCollector
136
+ max_q_length = NewRelic::Agent::ErrorCollector::MAX_ERROR_QUEUE_LENGTH
125
137
 
126
138
  silence_stream(::STDOUT) do
127
139
  (max_q_length + 5).times do |n|
128
- @error_collector.notice_error(StandardError.new("exception #{n}"), :metric => "path", :request_params => {:x => n})
140
+ @error_collector.notice_error(StandardError.new("exception #{n}"),
141
+ :metric => "path",
142
+ :custom_params => {:x => n})
129
143
  end
130
144
  end
131
145
 
132
146
  errors = @error_collector.harvest!
133
147
  assert errors.length == max_q_length
134
148
  errors.each_index do |i|
135
- err = errors.shift
136
- assert_equal i.to_s, err.params[:request_params][:x], err.params.inspect
149
+ error = errors.shift
150
+ actual = error.to_collector_array.last["userAttributes"]["x"]
151
+ assert_equal i.to_s, actual
137
152
  end
138
153
  end
139
154
 
@@ -148,15 +163,18 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
148
163
  types = [[1, '1'],
149
164
  [1.1, '1.1'],
150
165
  ['hi', 'hi'],
151
- [:hi, :hi],
166
+ [:hi, 'hi'],
152
167
  [StandardError.new("test"), "#<StandardError>"],
153
168
  [TestClass.new, "#<NewRelic::Agent::ErrorCollectorTest::TestClass>"]
154
169
  ]
155
170
 
156
171
  types.each do |test|
157
- @error_collector.notice_error(StandardError.new("message"), :metric => 'path',
158
- :request_params => {:x => test[0]})
159
- assert_equal test[1], @error_collector.harvest![0].params[:request_params][:x]
172
+ @error_collector.notice_error(StandardError.new("message"),
173
+ :metric => 'path',
174
+ :custom_params => {:x => test[0]})
175
+ error = @error_collector.harvest![0].to_collector_array
176
+ actual = error.last["userAttributes"]["x"]
177
+ assert_equal test[1], actual
160
178
  end
161
179
  end
162
180
 
@@ -164,7 +182,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
164
182
  def test_exclude
165
183
  @error_collector.ignore(["IOError"])
166
184
 
167
- @error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
185
+ @error_collector.notice_error(IOError.new("message"), :metric => 'path')
168
186
 
169
187
  errors = @error_collector.harvest!
170
188
 
@@ -186,8 +204,8 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
186
204
  def test_exclude_block
187
205
  @error_collector.class.ignore_error_filter = wrapped_filter_proc
188
206
 
189
- @error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
190
- @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
207
+ @error_collector.notice_error(IOError.new("message"), :metric => 'path')
208
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path')
191
209
 
192
210
  errors = @error_collector.harvest!
193
211
 
@@ -311,8 +329,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
311
329
 
312
330
  err = @error_collector.errors.first
313
331
  assert_equal "NewRelic/AgentError", err.path
314
- assert_kind_of Hash, err.params
315
- refute_nil err.params[:stack_trace]
332
+ refute_nil err.stack_trace
316
333
  end
317
334
 
318
335
  def test_notice_agent_error_uses_exception_backtrace_if_present
@@ -321,7 +338,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
321
338
  exception.set_backtrace(trace)
322
339
  @error_collector.notice_agent_error(exception)
323
340
 
324
- assert_equal trace, @error_collector.errors.first.params[:stack_trace]
341
+ assert_equal trace, @error_collector.errors.first.stack_trace
325
342
  end
326
343
 
327
344
  def test_notice_agent_error_uses_caller_if_no_exception_backtrace
@@ -329,7 +346,7 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
329
346
  exception.set_backtrace(nil)
330
347
  @error_collector.notice_agent_error(exception)
331
348
 
332
- trace = @error_collector.errors.first.params[:stack_trace]
349
+ trace = @error_collector.errors.first.stack_trace
333
350
  assert trace.any? {|line| line.include?(__FILE__)}
334
351
  end
335
352
 
@@ -418,6 +435,136 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
418
435
  assert_empty @error_collector.errors
419
436
  end
420
437
 
438
+ def test_captures_attributes_on_notice_error
439
+ error = StandardError.new('wat')
440
+ attributes = Object.new
441
+ @error_collector.notice_error(error, :attributes => attributes)
442
+
443
+ noticed = @error_collector.errors.first
444
+ assert_equal attributes, noticed.attributes
445
+ end
446
+
447
+ module Winner
448
+ def winner
449
+ 'yay'
450
+ end
451
+ end
452
+
453
+ def test_sense_method
454
+ object = Object.new
455
+ object.extend(Winner)
456
+ assert_equal nil, @error_collector.sense_method(object, 'blab')
457
+ assert_equal 'yay', @error_collector.sense_method(object, 'winner')
458
+ end
459
+
460
+ def test_extract_stack_trace
461
+ exception = mock('exception', :original_exception => nil,
462
+ :backtrace => nil)
463
+
464
+ assert_equal('<no stack trace>', @error_collector.extract_stack_trace(exception))
465
+ end
466
+
467
+ def test_extract_stack_trace_positive
468
+ orig = mock('original', :backtrace => "STACK STACK STACK")
469
+ exception = mock('exception', :original_exception => orig)
470
+
471
+ assert_equal('STACK STACK STACK', @error_collector.extract_stack_trace(exception))
472
+ end
473
+
474
+ def test_over_queue_limit_negative
475
+ refute @error_collector.over_queue_limit?(nil)
476
+ end
477
+
478
+ def test_over_queue_limit_positive
479
+ expects_logging(:warn, includes('The error reporting queue has reached 20'))
480
+ 21.times do
481
+ @error_collector.notice_error("", {})
482
+ end
483
+
484
+ assert @error_collector.over_queue_limit?('hooray')
485
+ end
486
+
487
+ def test_skip_notice_error_is_true_if_the_error_collector_is_disabled
488
+ error = StandardError.new
489
+ with_config(:'error_collector.enabled' => false) do
490
+ assert @error_collector.skip_notice_error?(NewRelic::Agent::TransactionState.tl_get, error)
491
+ end
492
+ end
493
+
494
+ def test_skip_notice_error_is_true_if_the_error_is_nil
495
+ error = nil
496
+ with_config(:'error_collector.enabled' => true) do
497
+ @error_collector.expects(:error_is_ignored?).with(error).returns(false)
498
+ assert @error_collector.skip_notice_error?(NewRelic::Agent::TransactionState.tl_get, error)
499
+ end
500
+ end
501
+
502
+ def test_skip_notice_error_is_true_if_the_error_is_ignored
503
+ error = StandardError.new
504
+ with_config(:'error_collector.enabled' => true) do
505
+ @error_collector.expects(:error_is_ignored?).with(error).returns(true)
506
+ assert @error_collector.skip_notice_error?(NewRelic::Agent::TransactionState.tl_get, error)
507
+ end
508
+ end
509
+
510
+ def test_skip_notice_error_returns_false_for_non_nil_unignored_errors_with_an_enabled_error_collector
511
+ error = StandardError.new
512
+ with_config(:'error_collector.enabled' => true) do
513
+ @error_collector.expects(:error_is_ignored?).with(error).returns(false)
514
+ refute @error_collector.skip_notice_error?(NewRelic::Agent::TransactionState.tl_get, error)
515
+ end
516
+ end
517
+
518
+ class ::AnError
519
+ end
520
+
521
+ def test_filtered_error_positive
522
+ with_config(:'error_collector.ignore_errors' => 'AnError') do
523
+ error = AnError.new
524
+ assert @error_collector.filtered_error?(error)
525
+ end
526
+ end
527
+
528
+ def test_filtered_error_negative
529
+ error = AnError.new
530
+ refute @error_collector.filtered_error?(error)
531
+ end
532
+
533
+ def test_filtered_by_error_filter_empty
534
+ # should return right away when there's no filter
535
+ refute @error_collector.filtered_by_error_filter?(nil)
536
+ end
537
+
538
+ def test_filtered_by_error_filter_positive
539
+ saw_error = nil
540
+ NewRelic::Agent::ErrorCollector.ignore_error_filter = Proc.new do |e|
541
+ saw_error = e
542
+ false
543
+ end
544
+
545
+ error = StandardError.new
546
+ assert @error_collector.filtered_by_error_filter?(error)
547
+
548
+ assert_equal error, saw_error
549
+ end
550
+
551
+ def test_filtered_by_error_filter_negative
552
+ saw_error = nil
553
+ NewRelic::Agent::ErrorCollector.ignore_error_filter = Proc.new do |e|
554
+ saw_error = e
555
+ true
556
+ end
557
+
558
+ error = StandardError.new
559
+ refute @error_collector.filtered_by_error_filter?(error)
560
+
561
+ assert_equal error, saw_error
562
+ end
563
+
564
+ def test_error_is_ignored_no_error
565
+ refute @error_collector.error_is_ignored?(nil)
566
+ end
567
+
421
568
  private
422
569
 
423
570
  def expects_error_count_increase(increase)
@@ -0,0 +1,34 @@
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 'new_relic/agent/hash_extensions'
7
+
8
+ class HashExtensionsTest < Minitest::Test
9
+
10
+ def test_stringify_keys_in_object_with_nested_hash
11
+ hash = {:foo => {:bar => [{:baz => "qux"}, "quux"]}}
12
+ expected = {"foo" => {"bar" => [{"baz" => "qux"}, "quux"]}}
13
+
14
+ actual = NewRelic::Agent::HashExtensions.stringify_keys_in_object(hash)
15
+
16
+ assert_equal expected, actual
17
+ end
18
+
19
+ def test_stringify_keys_in_object_with_array
20
+ array = ["foo", {:bar => [{:baz => "qux"}, "quux"]}]
21
+ expected = ["foo", {"bar" => [{"baz" => "qux"}, "quux"]}]
22
+
23
+ actual = NewRelic::Agent::HashExtensions.stringify_keys_in_object(array)
24
+
25
+ assert_equal expected, actual
26
+ end
27
+
28
+ def test_stringify_keys_in_object_does_not_mutate_argument
29
+ arg = {:foo => "bar"}
30
+ result = NewRelic::Agent::HashExtensions.stringify_keys_in_object(arg)
31
+ refute_same arg, result
32
+ assert_includes arg.keys, :foo
33
+ end
34
+ end
@@ -27,7 +27,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
27
27
  def setup
28
28
  freeze_time
29
29
  @subscriber = NewRelic::Agent::Instrumentation::ActionControllerSubscriber.new
30
- NewRelic::Agent.instance.stats_engine.clear_stats
30
+ NewRelic::Agent.drop_buffered_data
31
31
  @entry_payload = {
32
32
  :controller => TestController.to_s,
33
33
  :action => 'index',
@@ -193,16 +193,15 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
193
193
  end
194
194
 
195
195
  def test_creates_transaction
196
- NewRelic::Agent.instance.transaction_sampler.reset!
197
196
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
198
197
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
199
198
 
200
199
  assert_equal('Controller/test/index',
201
200
  NewRelic::Agent.instance.transaction_sampler \
202
- .last_sample.params[:path])
201
+ .last_sample.transaction_name)
203
202
  assert_equal('Controller/test/index',
204
203
  NewRelic::Agent.instance.transaction_sampler \
205
- .last_sample.root_segment.called_segments[0].metric_name)
204
+ .last_sample.root_node.called_nodes[0].metric_name)
206
205
  end
207
206
 
208
207
  def test_applies_txn_name_rules
@@ -264,36 +263,34 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Minites
264
263
  end
265
264
 
266
265
  def test_records_request_params_in_txn
267
- NewRelic::Agent.instance.transaction_sampler.reset!
268
- @entry_payload[:params]['number'] = '666'
269
- @subscriber.start('process_action.action_controller', :id, @entry_payload)
270
- @subscriber.finish('process_action.action_controller', :id, @exit_payload)
266
+ with_config(:capture_params => true) do
267
+ @entry_payload[:params]['number'] = '666'
268
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
269
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
270
+ end
271
271
 
272
- assert_equal('666',
273
- NewRelic::Agent.instance.transaction_sampler \
274
- .last_sample.params[:request_params]['number'])
272
+ sample = NewRelic::Agent.instance.transaction_sampler.last_sample
273
+ assert_equal('666', attributes_for(sample, :agent)['request.parameters.number'])
275
274
  end
276
275
 
277
276
  def test_records_filtered_request_params_in_txn
278
- NewRelic::Agent.instance.transaction_sampler.reset!
279
- @entry_payload[:params]['password'] = 'secret'
280
- @subscriber.start('process_action.action_controller', :id, @entry_payload)
281
- @subscriber.finish('process_action.action_controller', :id, @exit_payload)
277
+ with_config(:capture_params => true) do
278
+ @entry_payload[:params]['password'] = 'secret'
279
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
280
+ @subscriber.finish('process_action.action_controller', :id, @exit_payload)
281
+ end
282
282
 
283
- assert_equal('[FILTERED]',
284
- NewRelic::Agent.instance.transaction_sampler \
285
- .last_sample.params[:request_params]['password'])
283
+ sample = NewRelic::Agent.instance.transaction_sampler.last_sample
284
+ assert_equal('[FILTERED]', attributes_for(sample, :agent)['request.parameters.password'])
286
285
  end
287
286
 
288
287
  def test_records_custom_parameters_in_txn
289
- NewRelic::Agent.instance.transaction_sampler.reset!
290
288
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
291
- NewRelic::Agent.add_custom_parameters('number' => '666')
289
+ NewRelic::Agent.add_custom_attributes('number' => '666')
292
290
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
293
291
 
294
- assert_equal('666',
295
- NewRelic::Agent.instance.transaction_sampler \
296
- .last_sample.params[:custom_params]['number'])
292
+ sample = NewRelic::Agent.instance.transaction_sampler.last_sample
293
+ assert_equal('666', attributes_for(sample, :custom)['number'])
297
294
  end
298
295
  end if ::Rails::VERSION::MAJOR.to_i >= 4
299
296