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,394 @@
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('../../../../test_helper.rb', __FILE__)
6
+ require 'new_relic/agent/transaction/trace'
7
+
8
+ class NewRelic::Agent::Transaction::TraceTest < Minitest::Test
9
+ def setup
10
+ freeze_time
11
+ @start_time = Time.now
12
+ @trace = NewRelic::Agent::Transaction::Trace.new(@start_time)
13
+ @trace.root_node.end_trace(@start_time)
14
+
15
+ filter = NewRelic::Agent.instance.attribute_filter
16
+ @fake_attributes = NewRelic::Agent::Transaction::Attributes.new(filter)
17
+
18
+ @trace.attributes = @fake_attributes
19
+ end
20
+
21
+ def test_start_time
22
+ assert_equal @start_time, @trace.start_time
23
+ end
24
+
25
+ def test_node_count
26
+ assert_equal 0, @trace.node_count
27
+ end
28
+
29
+ def test_sample_id_is_the_object_id
30
+ assert_equal @trace.object_id, @trace.sample_id
31
+ end
32
+
33
+ def test_create_node_increases_node_count
34
+ @trace.create_node(0.0, 'foo')
35
+ assert_equal 1, @trace.node_count
36
+ end
37
+
38
+ def test_duration_is_the_root_node_duration
39
+ assert_equal @trace.duration, @trace.root_node.duration
40
+ end
41
+
42
+ def test_create_node
43
+ result = @trace.create_node(0.0, 'goo')
44
+ assert_equal 0.0, result.entry_timestamp
45
+ assert_equal 'goo', result.metric_name
46
+ end
47
+
48
+ def test_each_node_delegates_to_root_node
49
+ block = Proc.new {}
50
+ @trace.root_node.expects(:each_node)
51
+ @trace.each_node(&block)
52
+ end
53
+
54
+ def test_collector_array_contains_start_time
55
+ expected = NewRelic::Helper.time_to_millis(@start_time)
56
+ assert_collector_array_contains(:start_time, expected)
57
+ end
58
+
59
+ def test_root_node
60
+ assert_equal 0.0, @trace.root_node.entry_timestamp
61
+ assert_equal "ROOT", @trace.root_node.metric_name
62
+ end
63
+
64
+ def test_prepare_to_send_returns_self
65
+ result = @trace.prepare_to_send!
66
+ assert_equal @trace, result
67
+ end
68
+
69
+ def test_prepare_to_send_returns_self_if_already_prepared
70
+ @trace.prepare_to_send!
71
+
72
+ result = @trace.prepare_to_send!
73
+ assert_equal @trace, result
74
+ end
75
+
76
+ def test_prepare_to_send_is_idempotent
77
+ NewRelic::Agent::Database.stubs(:should_record_sql?).returns true
78
+ @trace.expects(:collect_explain_plans!).once
79
+ @trace.expects(:prepare_sql_for_transmission!).once
80
+ @trace.prepare_to_send!
81
+ @trace.prepare_to_send!
82
+ end
83
+
84
+ def test_prepare_to_send_handles_sql_and_does_not_strip_if_should_record_sql_is_true
85
+ NewRelic::Agent::Database.stubs(:should_record_sql?).returns true
86
+ @trace.expects(:collect_explain_plans!).once
87
+ @trace.expects(:prepare_sql_for_transmission!).once
88
+ @trace.expects(:strip_sql!).never
89
+ @trace.prepare_to_send!
90
+ end
91
+
92
+ def test_prepare_to_send_strips_and_does_not_handle_sql_if_should_record_sql_is_false
93
+ NewRelic::Agent::Database.stubs(:should_record_sql?).returns false
94
+ @trace.expects(:collect_explain_plans!).never
95
+ @trace.expects(:prepare_sql_for_transmission!).never
96
+ @trace.expects(:strip_sql!).once
97
+ @trace.prepare_to_send!
98
+ end
99
+
100
+ def test_prepare_to_send_collects_explain_plans
101
+ node = @trace.create_node(0.0, 'has_sql')
102
+ node.stubs(:duration).returns(2)
103
+ node.stubs(:explain_sql).returns('')
104
+ node[:sql] = ''
105
+
106
+ @trace.root_node.add_called_node(node)
107
+
108
+ with_config(:'transaction_tracer.explain_threshold' => 1) do
109
+ @trace.prepare_to_send!
110
+ end
111
+
112
+ assert node[:explain_plan]
113
+ end
114
+
115
+ def test_prepare_to_send_prepares_sql_for_transmission
116
+ NewRelic::Agent::Database.stubs(:record_sql_method).returns :obfuscated
117
+
118
+ node = @trace.create_node(0.0, 'has_sql')
119
+ node.stubs(:duration).returns(2)
120
+ node[:sql] = "select * from pelicans where name = '1337807';"
121
+ @trace.root_node.add_called_node(node)
122
+
123
+ @trace.prepare_to_send!
124
+ assert_equal "select * from pelicans where name = ?;", node[:sql]
125
+ end
126
+
127
+ def test_prepare_to_send_strips_sql
128
+ NewRelic::Agent::Database.stubs(:should_record_sql?).returns false
129
+ node = @trace.create_node(0.0, 'has_sql')
130
+ node.stubs(:duration).returns(2)
131
+ node.stubs(:explain_sql).returns('')
132
+ node[:sql] = 'select * from pelicans;'
133
+
134
+ @trace.root_node.add_called_node(node)
135
+ @trace.prepare_to_send!
136
+
137
+ refute node[:sql]
138
+ end
139
+
140
+ def test_collect_explain_plans!
141
+ node = @trace.create_node(0.0, 'has_sql')
142
+ node.stubs(:duration).returns(2)
143
+ node.stubs(:explain_sql).returns('')
144
+ node[:sql] = ''
145
+
146
+ @trace.root_node.add_called_node(node)
147
+
148
+ with_config(:'transaction_tracer.explain_threshold' => 1) do
149
+ @trace.collect_explain_plans!
150
+ end
151
+
152
+ assert node[:explain_plan]
153
+ end
154
+
155
+ def test_collect_explain_plans_does_not_attach_explain_plans_if_duration_is_too_short
156
+ node = @trace.create_node(0.0, 'has_sql')
157
+ node.stubs(:duration).returns(1)
158
+ node.stubs(:explain_sql).returns('')
159
+ node[:sql] = ''
160
+
161
+ @trace.root_node.add_called_node(node)
162
+
163
+ with_config(:'transaction_tracer.explain_threshold' => 2) do
164
+ @trace.collect_explain_plans!
165
+ end
166
+
167
+ refute node[:explain_plan]
168
+ end
169
+
170
+ def test_collect_explain_plans_does_not_attach_explain_plans_without_sql
171
+ node = @trace.create_node(0.0, 'nope_sql')
172
+ node.stubs(:duration).returns(2)
173
+ node.stubs(:explain_sql).returns('')
174
+ node[:sql] = nil
175
+
176
+ @trace.root_node.add_called_node(node)
177
+
178
+ with_config(:'transaction_tracer.explain_threshold' => 1) do
179
+ @trace.collect_explain_plans!
180
+ end
181
+
182
+ refute node[:explain_plan]
183
+ end
184
+
185
+ def test_collect_explain_plans_does_not_attach_explain_plans_if_db_says_not_to
186
+ node = @trace.create_node(0.0, 'has_sql')
187
+ node.stubs(:duration).returns(2)
188
+ node.stubs(:explain_sql).returns('')
189
+ node[:sql] = ''
190
+
191
+ NewRelic::Agent::Database.stubs(:should_collect_explain_plans?).returns(false)
192
+
193
+ @trace.root_node.add_called_node(node)
194
+
195
+ with_config(:'transaction_tracer.explain_threshold' => 1) do
196
+ @trace.collect_explain_plans!
197
+ end
198
+
199
+ refute node[:explain_plan]
200
+ end
201
+
202
+ def test_prepare_sql_for_transmission_obfuscates_sql_if_record_sql_method_is_obfuscated
203
+ NewRelic::Agent::Database.stubs(:record_sql_method).returns :obfuscated
204
+
205
+ node = @trace.create_node(0.0, 'has_sql')
206
+ node[:sql] = "select * from pelicans where name = '1337807';"
207
+ @trace.root_node.add_called_node(node)
208
+
209
+ @trace.prepare_sql_for_transmission!
210
+ assert_equal "select * from pelicans where name = ?;", node[:sql]
211
+ end
212
+
213
+ def test_prepare_sql_for_transmission_does_not_modify_sql_if_record_sql_method_is_raw
214
+ NewRelic::Agent::Database.stubs(:record_sql_method).returns :raw
215
+
216
+ node = @trace.create_node(0.0, 'has_sql')
217
+ node[:sql] = "select * from pelicans where name = '1337807';"
218
+ @trace.root_node.add_called_node(node)
219
+
220
+ @trace.prepare_sql_for_transmission!
221
+ assert_equal "select * from pelicans where name = '1337807';", node[:sql]
222
+ end
223
+
224
+ def test_prepare_sql_for_transmission_removes_sql_if_record_sql_method_is_off
225
+ NewRelic::Agent::Database.stubs(:record_sql_method).returns :off
226
+
227
+ node = @trace.create_node(0.0, 'has_sql')
228
+ node[:sql] = "select * from pelicans where name = '1337807';"
229
+ @trace.root_node.add_called_node(node)
230
+
231
+ @trace.prepare_sql_for_transmission!
232
+ refute node[:sql]
233
+ end
234
+
235
+ def test_strip_sql!
236
+ node = @trace.create_node(0.0, 'has_sql')
237
+ node.stubs(:duration).returns(2)
238
+ node.stubs(:explain_sql).returns('')
239
+ node[:sql] = 'select * from pelicans;'
240
+
241
+ @trace.root_node.add_called_node(node)
242
+ @trace.strip_sql!
243
+
244
+ refute node[:sql]
245
+ end
246
+
247
+ def test_collector_array_contains_root_node_duration
248
+ @trace.root_node.end_trace(1)
249
+ assert_collector_array_contains(:duration, 1000)
250
+ end
251
+
252
+ def test_collector_array_contains_transaction_name
253
+ @trace.transaction_name = 'zork'
254
+ assert_collector_array_contains(:transaction_name, 'zork')
255
+ end
256
+
257
+ def test_transaction_name_gets_coerced_into_a_string
258
+ @trace.transaction_name = 1337807
259
+ assert_collector_array_contains(:transaction_name, '1337807')
260
+ end
261
+
262
+ def test_collector_array_contains_uri
263
+ @trace.uri = 'http://windows95tips.com/'
264
+ assert_collector_array_contains(:uri, 'http://windows95tips.com/')
265
+ end
266
+
267
+ def test_uri_gets_coerced_into_a_string
268
+ @trace.uri = 95
269
+ assert_collector_array_contains(:uri, '95')
270
+ end
271
+
272
+ def test_collector_array_contains_trace_tree
273
+ assert_collector_array_contains(:trace_tree, @trace.trace_tree)
274
+ end
275
+
276
+ def test_collector_array_contains_guid
277
+ @trace.guid = 'DEADBEEF8BADF00D'
278
+ assert_collector_array_contains(:guid, 'DEADBEEF8BADF00D')
279
+ end
280
+
281
+ def test_guid_gets_coerced_into_a_string
282
+ @trace.guid = 42
283
+ assert_collector_array_contains(:guid, '42')
284
+ end
285
+
286
+ def test_collector_array_contains_nil_for_reserved
287
+ assert_collector_array_contains(:reserved, nil)
288
+ end
289
+
290
+ def test_collector_array_contains_forced_true_if_in_an_xray_session
291
+ @trace.xray_session_id = 7
292
+ assert_collector_array_contains(:forced?, true)
293
+ end
294
+
295
+ def test_collector_array_contains_forced_false_if_not_in_an_xray_session
296
+ @trace.xray_session_id = nil
297
+ assert_collector_array_contains(:forced?, false)
298
+ end
299
+
300
+ def test_collector_array_contains_xray_session_id
301
+ @trace.xray_session_id = 112357
302
+ assert_collector_array_contains(:xray_session_id, 112357)
303
+ end
304
+
305
+ def test_xray_session_id_gets_coerced_to_an_integer
306
+ @trace.xray_session_id = '112357'
307
+ assert_collector_array_contains(:xray_session_id, 112357)
308
+ end
309
+
310
+ def test_xray_session_id_does_not_coerce_nil_to_an_integer
311
+ @trace.xray_session_id = nil
312
+ assert_collector_array_contains(:xray_session_id, nil)
313
+ end
314
+
315
+ def test_collector_array_contains_synthetics_resource_id
316
+ @fake_attributes.add_intrinsic_attribute(:synthetics_resource_id, '31415926')
317
+ assert_collector_array_contains(:synthetics_resource_id, '31415926')
318
+ end
319
+
320
+ def test_to_collector_array_encodes_trace_tree_with_given_encoder
321
+ fake_encoder = mock
322
+ fake_encoder.expects(:encode).with(@trace.trace_tree)
323
+ @trace.to_collector_array(fake_encoder)
324
+ end
325
+
326
+ def test_synthetics_resource_id_gets_coerced_to_a_string
327
+ @fake_attributes.add_intrinsic_attribute(:synthetics_resource_id, 31415926)
328
+ assert_collector_array_contains(:synthetics_resource_id, '31415926')
329
+ end
330
+
331
+ def test_trace_tree_coerces_start_time_to_a_float
332
+ assert_kind_of Float, @trace.trace_tree.first
333
+ end
334
+
335
+ def test_trace_tree_includes_start_time
336
+ assert_trace_tree_contains(:start_time, @start_time.to_f)
337
+ end
338
+
339
+ def test_trace_tree_includes_unused_legacy_request_params
340
+ assert_trace_tree_contains(:unused_legacy_request_params, {})
341
+ end
342
+
343
+ def test_trace_tree_includes_unused_legacy_custom_params
344
+ assert_trace_tree_contains(:unused_legacy_custom_params, {})
345
+ end
346
+
347
+ def test_trace_tree_contains_serialized_root_node
348
+ assert_trace_tree_contains(:root_node, @trace.root_node.to_array)
349
+ end
350
+
351
+ def test_trace_tree_contains_attributes
352
+ @fake_attributes.add_agent_attribute(:foo, 'bar', NewRelic::Agent::AttributeFilter::DST_ALL)
353
+ @fake_attributes.add_intrinsic_attribute(:foo, 'bar')
354
+ @fake_attributes.merge_custom_attributes(:foo => 'bar')
355
+
356
+ expected = {
357
+ 'agentAttributes' => { :foo => 'bar' },
358
+ 'userAttributes' => { "foo" => 'bar' },
359
+ 'intrinsics' => { :foo => 'bar' }
360
+ }
361
+
362
+ assert_trace_tree_contains(:attributes, expected)
363
+ end
364
+
365
+ def assert_trace_tree_contains(key, expected)
366
+ indices = [
367
+ :start_time,
368
+ :unused_legacy_request_params,
369
+ :unused_legacy_custom_params,
370
+ :root_node,
371
+ :attributes
372
+ ]
373
+
374
+ assert_equal expected, @trace.trace_tree[indices.index(key)]
375
+ end
376
+
377
+ def assert_collector_array_contains(key, expected)
378
+ indices = [
379
+ :start_time,
380
+ :duration,
381
+ :transaction_name,
382
+ :uri,
383
+ :trace_tree,
384
+ :guid,
385
+ :reserved,
386
+ :forced?,
387
+ :xray_session_id,
388
+ :synthetics_resource_id
389
+ ]
390
+
391
+ encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
392
+ assert_equal expected, @trace.to_collector_array(encoder)[indices.index(key)]
393
+ end
394
+ end
@@ -62,7 +62,7 @@ class NewRelic::Agent::Transaction
62
62
  end
63
63
 
64
64
  def sample_with(opts={})
65
- sample = NewRelic::TransactionSample.new
65
+ sample = NewRelic::Agent::Transaction::Trace.new(Time.now)
66
66
  sample.transaction_name = opts[:transaction_name]
67
67
  sample
68
68
  end
@@ -6,19 +6,22 @@
6
6
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
7
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..','data_container_tests'))
8
8
  require 'new_relic/agent/transaction_event_aggregator'
9
+ require 'new_relic/agent/transaction/attributes'
9
10
 
10
11
  class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
11
12
 
12
13
  def setup
13
14
  freeze_time
14
15
  @event_listener = NewRelic::Agent::EventListener.new
15
- @sampler = NewRelic::Agent::TransactionEventAggregator.new(@event_listener)
16
+ @event_aggregator = NewRelic::Agent::TransactionEventAggregator.new(@event_listener)
17
+
18
+ @attributes = nil
16
19
  end
17
20
 
18
21
  # Helpers for DataContainerTests
19
22
 
20
23
  def create_container
21
- @sampler
24
+ @event_aggregator
22
25
  end
23
26
 
24
27
  def populate_container(sampler, n)
@@ -34,52 +37,111 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
34
37
  def test_samples_on_transaction_finished_event
35
38
  with_sampler_config do
36
39
  generate_request
37
- assert_equal 1, @sampler.samples.length
40
+ assert_equal 1, @event_aggregator.samples.length
38
41
  end
39
42
  end
40
43
 
41
44
  EVENT_DATA_INDEX = 0
42
45
  CUSTOM_ATTRIBUTES_INDEX = 1
46
+ AGENT_ATTRIBUTES_INDEX = 2
43
47
 
44
- def test_custom_parameters_in_event_are_normalized_to_string_keys
48
+ def test_custom_attributes_in_event_are_normalized_to_string_keys
45
49
  with_sampler_config do
46
- generate_request('whatever', :custom_params => {:bing => 2, 1 => 3})
47
- custom_attrs = single_sample[CUSTOM_ATTRIBUTES_INDEX]
48
- assert_equal 2, custom_attrs['bing']
49
- assert_equal 3, custom_attrs['1']
50
+ attributes.merge_custom_attributes(:bing => 2, 1 => 3)
51
+ generate_request('whatever')
52
+
53
+ result = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
54
+ assert_equal 2, result['bing']
55
+ assert_equal 3, result['1']
50
56
  end
51
57
  end
52
58
 
53
- def test_includes_custom_parameters_in_event
59
+ def test_agent_attributes_in_event_are_normalized_to_string_keys
54
60
  with_sampler_config do
55
- generate_request('whatever', :custom_params => {'bing' => 2})
56
- custom_attrs = single_sample[CUSTOM_ATTRIBUTES_INDEX]
61
+ attributes.add_agent_attribute(:yahoo, 7, NewRelic::Agent::AttributeFilter::DST_ALL)
62
+ attributes.add_agent_attribute(4, 2, NewRelic::Agent::AttributeFilter::DST_ALL)
63
+ generate_request('puce')
64
+
65
+ result = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
66
+ assert_equal 7, result[:yahoo]
67
+ assert_equal 2, result[4]
68
+ end
69
+ end
70
+
71
+ def test_includes_custom_attributes_in_event
72
+ with_sampler_config do
73
+ attributes.merge_custom_attributes('bing' => 2)
74
+ generate_request('whatever')
75
+
76
+ custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
57
77
  assert_equal 2, custom_attrs['bing']
58
78
  end
59
79
  end
60
80
 
61
- def test_doesnt_include_custom_parameters_in_event_when_configured_not_to
81
+ def test_includes_agent_attributes_in_event
82
+ with_sampler_config do
83
+ attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
84
+ generate_request('whatever')
85
+
86
+ agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
87
+ assert_equal 2, agent_attrs['bing']
88
+ end
89
+ end
90
+
91
+ def test_doesnt_include_custom_attributes_in_event_when_configured_not_to
92
+ with_sampler_config('transaction_events.attributes.enabled' => false) do
93
+ attributes.merge_custom_attributes('bing' => 2)
94
+ generate_request('whatever')
95
+
96
+ custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
97
+ assert_empty custom_attrs
98
+ end
99
+ end
100
+
101
+ def test_doesnt_include_agent_attributes_in_event_when_configured_not_to
102
+ with_sampler_config('transaction_events.attributes.enabled' => false) do
103
+ attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
104
+ generate_request('whatever')
105
+
106
+ agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
107
+ assert_empty agent_attrs
108
+ end
109
+ end
110
+
111
+
112
+ def test_doesnt_include_custom_attributes_in_event_when_configured_not_to_with_legacy_setting
113
+ with_sampler_config('analytics_events.capture_attributes' => false) do
114
+ attributes.merge_custom_attributes('bing' => 2)
115
+ generate_request('whatever')
116
+
117
+ custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
118
+ assert_empty custom_attrs
119
+ end
120
+ end
121
+
122
+ def test_doesnt_include_agent_attributes_in_event_when_configured_not_to_with_legacy_setting
62
123
  with_sampler_config('analytics_events.capture_attributes' => false) do
63
- generate_request('whatever', :custom_params => {'bing' => 2})
64
- custom_attrs = single_sample[CUSTOM_ATTRIBUTES_INDEX]
65
- assert_equal nil, custom_attrs['bing']
124
+ attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
125
+ generate_request('whatever')
126
+
127
+ agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
128
+ assert_empty agent_attrs
66
129
  end
67
130
  end
68
131
 
69
- def test_custom_parameters_in_event_cant_override_reserved_attributes
132
+ def test_custom_attributes_in_event_cant_override_reserved_attributes
70
133
  with_sampler_config do
71
134
  metrics = NewRelic::Agent::TransactionMetrics.new()
72
135
  metrics.record_unscoped('HttpDispatcher', 0.01)
73
136
 
74
- generate_request('whatever',
75
- :metrics => metrics,
76
- :custom_params => {'type' => 'giraffe', 'duration' => 'hippo'}
77
- )
78
- txn_event = single_sample[EVENT_DATA_INDEX]
137
+ attributes.merge_custom_attributes('type' => 'giraffe', 'duration' => 'hippo')
138
+ generate_request('whatever', :metrics => metrics)
139
+
140
+ txn_event = captured_transaction_event[EVENT_DATA_INDEX]
79
141
  assert_equal 'Transaction', txn_event['type']
80
142
  assert_equal 0.1, txn_event['duration']
81
143
 
82
- custom_attrs = single_sample[CUSTOM_ATTRIBUTES_INDEX]
144
+ custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
83
145
  assert_equal 'giraffe', custom_attrs['type']
84
146
  assert_equal 'hippo', custom_attrs['duration']
85
147
  end
@@ -94,7 +156,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
94
156
 
95
157
  with_sampler_config do
96
158
  generate_request('name', :metrics => txn_metrics)
97
- event_data = single_sample[EVENT_DATA_INDEX]
159
+ event_data = captured_transaction_event[EVENT_DATA_INDEX]
98
160
  assert_equal 13, event_data["queueDuration"]
99
161
  assert_equal 14, event_data["externalDuration"]
100
162
  assert_equal 15, event_data["databaseDuration"]
@@ -114,7 +176,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
114
176
  with_sampler_config do
115
177
  generate_request('name', :metrics => txn_metrics)
116
178
 
117
- event_data = single_sample[EVENT_DATA_INDEX]
179
+ event_data = captured_transaction_event[EVENT_DATA_INDEX]
118
180
  assert_equal 12, event_data["externalDuration"]
119
181
  assert_equal 13, event_data["databaseDuration"]
120
182
  assert_equal 14, event_data["gcCumulative"]
@@ -128,7 +190,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
128
190
  with_sampler_config do
129
191
  generate_request('name', :apdex_perf_zone => 'S')
130
192
 
131
- event_data = single_sample[EVENT_DATA_INDEX]
193
+ event_data = captured_transaction_event[EVENT_DATA_INDEX]
132
194
  assert_equal 'S', event_data['nr.apdexPerfZone']
133
195
  end
134
196
  end
@@ -136,14 +198,14 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
136
198
  def test_samples_on_transaction_finished_event_includes_guid
137
199
  with_sampler_config do
138
200
  generate_request('name', :guid => "GUID")
139
- assert_equal "GUID", single_sample[EVENT_DATA_INDEX]["nr.guid"]
201
+ assert_equal "GUID", captured_transaction_event[EVENT_DATA_INDEX]["nr.guid"]
140
202
  end
141
203
  end
142
204
 
143
205
  def test_samples_on_transaction_finished_event_includes_referring_transaction_guid
144
206
  with_sampler_config do
145
207
  generate_request('name', :referring_transaction_guid=> "REFER")
146
- assert_equal "REFER", single_sample[EVENT_DATA_INDEX]["nr.referringTransactionGuid"]
208
+ assert_equal "REFER", captured_transaction_event[EVENT_DATA_INDEX]["nr.referringTransactionGuid"]
147
209
  end
148
210
  end
149
211
 
@@ -151,14 +213,14 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
151
213
  with_sampler_config do
152
214
  generate_request('a', :type => :controller)
153
215
  generate_request('b', :type => :background)
154
- assert_equal 2, @sampler.samples.size
216
+ assert_equal 2, @event_aggregator.samples.size
155
217
  end
156
218
  end
157
219
 
158
220
  def test_can_disable_sampling_for_analytics
159
221
  with_sampler_config( :'analytics_events.enabled' => false ) do
160
222
  generate_request
161
- assert @sampler.samples.empty?
223
+ assert @event_aggregator.samples.empty?
162
224
  end
163
225
  end
164
226
 
@@ -166,52 +228,52 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
166
228
  with_sampler_config do
167
229
  5.times { generate_request }
168
230
 
169
- old_samples = @sampler.harvest!
231
+ old_samples = @event_aggregator.harvest!
170
232
 
171
233
  assert_equal 5, old_samples.size
172
- assert_equal 0, @sampler.samples.size
234
+ assert_equal 0, @event_aggregator.samples.size
173
235
  end
174
236
  end
175
237
 
176
238
  def test_merge_merges_samples_back_into_buffer
177
239
  with_sampler_config do
178
240
  5.times { generate_request }
179
- old_samples = @sampler.harvest!
241
+ old_samples = @event_aggregator.harvest!
180
242
  5.times { generate_request }
181
243
 
182
- @sampler.merge!(old_samples)
183
- assert_equal(10, @sampler.samples.size)
244
+ @event_aggregator.merge!(old_samples)
245
+ assert_equal(10, @event_aggregator.samples.size)
184
246
  end
185
247
  end
186
248
 
187
249
  def test_merge_abides_by_max_samples_limit
188
250
  with_sampler_config(:'analytics_events.max_samples_stored' => 5) do
189
251
  4.times { generate_request }
190
- old_samples = @sampler.harvest!
252
+ old_samples = @event_aggregator.harvest!
191
253
  4.times { generate_request }
192
254
 
193
- @sampler.merge!(old_samples)
194
- assert_equal(5, @sampler.samples.size)
255
+ @event_aggregator.merge!(old_samples)
256
+ assert_equal(5, @event_aggregator.samples.size)
195
257
  end
196
258
  end
197
259
 
198
260
  def test_limits_total_number_of_samples_to_max_samples_stored
199
261
  with_sampler_config( :'analytics_events.max_samples_stored' => 100 ) do
200
262
  150.times { generate_request }
201
- assert_equal 100, @sampler.samples.size
263
+ assert_equal 100, @event_aggregator.samples.size
202
264
  end
203
265
  end
204
266
 
205
267
  def test_resets_limits_on_harvest
206
268
  with_sampler_config( :'analytics_events.max_samples_stored' => 100 ) do
207
269
  50.times { generate_request('before') }
208
- samples_before = @sampler.samples
270
+ samples_before = @event_aggregator.samples
209
271
  assert_equal 50, samples_before.size
210
272
 
211
- @sampler.harvest!
273
+ @event_aggregator.harvest!
212
274
 
213
275
  150.times { generate_request('after') }
214
- samples_after = @sampler.samples
276
+ samples_after = @event_aggregator.samples
215
277
  assert_equal 100, samples_after.size
216
278
 
217
279
  assert_equal 0, (samples_before & samples_after).size
@@ -228,13 +290,13 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
228
290
  end
229
291
  threads.each { |t| t.join }
230
292
 
231
- assert_equal(25 * 100, @sampler.samples.size)
293
+ assert_equal(25 * 100, @event_aggregator.samples.size)
232
294
  end
233
295
  end
234
296
 
235
297
  def test_includes_http_response_code_in_events
236
298
  generate_request('whatever', :http_response_code => 404)
237
- sample = single_sample
299
+ sample = captured_transaction_event
238
300
  code = sample[EVENT_DATA_INDEX]['httpResponseCode']
239
301
  assert_equal('404', code)
240
302
  end
@@ -246,7 +308,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
246
308
  generate_request('synthetic', :synthetics_resource_id => 100)
247
309
  end
248
310
 
249
- assert_equal 10, @sampler.samples.size
311
+ assert_equal 10, @event_aggregator.samples.size
250
312
  end
251
313
  end
252
314
 
@@ -256,7 +318,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
256
318
  generate_request('synthetic', :synthetics_resource_id => 100)
257
319
  end
258
320
 
259
- assert_equal 20, @sampler.samples.size
321
+ assert_equal 20, @event_aggregator.samples.size
260
322
  end
261
323
  end
262
324
 
@@ -269,8 +331,8 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
269
331
 
270
332
  generate_request('synthetic', :timestamp => 1, :synthetics_resource_id => 100)
271
333
 
272
- assert_equal 10, @sampler.samples.size
273
- timestamps = @sampler.samples.map do |(main, _)|
334
+ assert_equal 10, @event_aggregator.samples.size
335
+ timestamps = @event_aggregator.samples.map do |(main, _)|
274
336
  main["timestamp"]
275
337
  end.sort
276
338
 
@@ -286,7 +348,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
286
348
 
287
349
  generate_request('synthetic', :timestamp => 1, :synthetics_resource_id => 100)
288
350
 
289
- assert_equal 11, @sampler.samples.size
351
+ assert_equal 11, @event_aggregator.samples.size
290
352
  end
291
353
  end
292
354
 
@@ -295,13 +357,13 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
295
357
  20.times do
296
358
  generate_request('synthetic', :synthetics_resource_id => 100)
297
359
  end
298
- @sampler.harvest!
360
+ @event_aggregator.harvest!
299
361
  end
300
362
 
301
363
  with_sampler_config(:'synthetics.events_limit' => 10,
302
364
  :'analytics_events.max_samples_stored' => 0) do
303
- @sampler.merge!(samples)
304
- assert_equal 10, @sampler.samples.size
365
+ @event_aggregator.merge!(samples)
366
+ assert_equal 10, @event_aggregator.samples.size
305
367
  end
306
368
  end
307
369
 
@@ -311,7 +373,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
311
373
  generate_request('synthetic', :synthetics_resource_id => 100)
312
374
  end
313
375
 
314
- @sampler.harvest!
376
+ @event_aggregator.harvest!
315
377
 
316
378
  metric = 'Supportability/TransactionEventAggregator/synthetics_events_dropped'
317
379
  assert_metrics_not_recorded(metric)
@@ -324,7 +386,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
324
386
  generate_request('synthetic', :synthetics_resource_id => 100)
325
387
  end
326
388
 
327
- @sampler.harvest!
389
+ @event_aggregator.harvest!
328
390
 
329
391
  metric = 'Supportability/TransactionEventAggregator/synthetics_events_dropped'
330
392
  assert_metrics_recorded(metric => { :call_count => 10 })
@@ -341,7 +403,7 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
341
403
  :type => :controller,
342
404
  :start_timestamp => options[:timestamp] || Time.now.to_f,
343
405
  :duration => 0.1,
344
- :custom_params => {}
406
+ :attributes => attributes
345
407
  }.merge(options)
346
408
  @event_listener.notify(:transaction_finished, payload)
347
409
  end
@@ -355,9 +417,17 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
355
417
  end
356
418
  end
357
419
 
358
- def single_sample
359
- assert_equal 1, @sampler.samples.size
360
- @sampler.samples.first
420
+ def captured_transaction_event
421
+ assert_equal 1, @event_aggregator.samples.size
422
+ @event_aggregator.samples.first
361
423
  end
362
424
 
425
+ def attributes
426
+ if @attributes.nil?
427
+ filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
428
+ @attributes = NewRelic::Agent::Transaction::Attributes.new(filter)
429
+ end
430
+
431
+ @attributes
432
+ end
363
433
  end