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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/.yardopts +2 -0
- data/CHANGELOG +39 -4
- data/README.md +4 -2
- data/lib/new_relic/agent.rb +229 -214
- data/lib/new_relic/agent/agent.rb +23 -12
- data/lib/new_relic/agent/attribute_filter.rb +242 -0
- data/lib/new_relic/agent/attribute_processing.rb +62 -0
- data/lib/new_relic/agent/commands/xray_session_collection.rb +4 -1
- data/lib/new_relic/agent/configuration/default_source.rb +284 -30
- data/lib/new_relic/agent/configuration/high_security_source.rb +0 -8
- data/lib/new_relic/agent/configuration/manager.rb +1 -1
- data/lib/new_relic/agent/configuration/server_source.rb +86 -31
- data/lib/new_relic/agent/configuration/yaml_source.rb +1 -1
- data/lib/new_relic/agent/cross_app_monitor.rb +8 -13
- data/lib/new_relic/agent/cross_app_tracing.rb +15 -15
- data/lib/new_relic/agent/custom_event_aggregator.rb +6 -2
- data/lib/new_relic/agent/database.rb +15 -2
- data/lib/new_relic/agent/datastores.rb +52 -38
- data/lib/new_relic/agent/datastores/metric_helper.rb +2 -1
- data/lib/new_relic/agent/encoding_normalizer.rb +82 -0
- data/lib/new_relic/agent/error_collector.rb +125 -169
- data/lib/new_relic/agent/hash_extensions.rb +26 -0
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +13 -11
- data/lib/new_relic/agent/http_clients/uri_util.rb +9 -0
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -3
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +12 -5
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +6 -7
- data/lib/new_relic/agent/instrumentation/curb.rb +6 -6
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +4 -4
- data/lib/new_relic/agent/instrumentation/grape.rb +4 -3
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -3
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +9 -3
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +9 -7
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +8 -6
- data/lib/new_relic/agent/instrumentation/resque.rb +2 -3
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -3
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
- data/lib/new_relic/agent/javascript_instrumentor.rb +24 -16
- data/lib/new_relic/agent/parameter_filtering.rb +8 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
- data/lib/new_relic/agent/sql_sampler.rb +1 -0
- data/lib/new_relic/agent/stats.rb +0 -4
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -3
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -0
- data/lib/new_relic/agent/supported_versions.rb +2 -2
- data/lib/new_relic/agent/traced_method_stack.rb +3 -3
- data/lib/new_relic/agent/transaction.rb +141 -118
- data/lib/new_relic/agent/transaction/attributes.rb +161 -0
- data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +4 -4
- data/lib/new_relic/agent/transaction/trace.rb +150 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +190 -0
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +2 -2
- data/lib/new_relic/agent/transaction_event_aggregator.rb +23 -7
- data/lib/new_relic/agent/transaction_sample_builder.rb +37 -62
- data/lib/new_relic/agent/transaction_sampler.rb +29 -66
- data/lib/new_relic/cli/commands/install.rb +2 -2
- data/lib/new_relic/coerce.rb +15 -28
- data/lib/new_relic/json_wrapper.rb +14 -73
- data/lib/new_relic/noticed_error.rb +81 -5
- data/lib/new_relic/rack/browser_monitoring.rb +14 -19
- data/lib/new_relic/rack/developer_mode.rb +68 -14
- data/lib/new_relic/rack/developer_mode/segment_summary.rb +56 -0
- data/lib/new_relic/version.rb +2 -2
- data/newrelic.yml +19 -196
- data/test/agent_helper.rb +42 -36
- data/test/config/newrelic.yml +0 -1
- data/test/environments/rails40/Gemfile +1 -1
- data/test/environments/rails41/Gemfile +1 -1
- data/test/environments/rails42/Gemfile +1 -1
- data/test/fixtures/cross_agent_tests/attribute_configuration.json +35 -0
- data/test/fixtures/cross_agent_tests/sql_obfuscation/README.md +19 -12
- data/test/fixtures/cross_agent_tests/sql_obfuscation/sql_obfuscation.json +365 -0
- data/test/multiverse/lib/multiverse/suite.rb +5 -1
- data/test/multiverse/suites/active_record/active_record_test.rb +8 -8
- data/test/multiverse/suites/agent_only/agent_attributes_test.rb +145 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +8 -0
- data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +5 -1
- data/test/multiverse/suites/agent_only/encoding_handling_test.rb +6 -6
- data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +2 -3
- data/test/multiverse/suites/agent_only/synthetics_test.rb +3 -3
- data/test/multiverse/suites/agent_only/testing_app.rb +4 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -1
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +9 -7
- data/test/multiverse/suites/curb/Envfile +5 -6
- data/test/multiverse/suites/curb/curb_test.rb +4 -5
- data/test/multiverse/suites/datamapper/datamapper_test.rb +2 -2
- data/test/multiverse/suites/excon/Envfile +11 -4
- data/test/multiverse/suites/excon/excon_test.rb +5 -5
- data/test/multiverse/suites/grape/config/newrelic.yml +1 -0
- data/test/multiverse/suites/grape/grape_test.rb +76 -12
- data/test/multiverse/suites/grape/grape_test_api.rb +16 -0
- data/test/multiverse/suites/high_security/config/newrelic.yml +43 -3
- data/test/multiverse/suites/high_security/high_security_test.rb +165 -9
- data/test/multiverse/suites/httpclient/Envfile +5 -1
- data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
- data/test/multiverse/suites/memcached/Envfile +1 -1
- data/test/multiverse/suites/mongo/Envfile +8 -1
- data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +29 -29
- data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +43 -8
- data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +13 -3
- data/test/multiverse/suites/rails/Envfile +3 -3
- data/test/multiverse/suites/rails/error_tracing_test.rb +52 -31
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +1 -1
- data/test/multiverse/suites/rails/ignore_test.rb +1 -1
- data/test/multiverse/suites/rails/parameter_capture_test.rb +108 -40
- data/test/multiverse/suites/rails/request_statistics_test.rb +10 -4
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +24 -24
- data/test/multiverse/suites/resque/instrumentation_test.rb +46 -12
- data/test/multiverse/suites/sequel/sequel_extension_test.rb +8 -8
- data/test/multiverse/suites/sequel/sequel_helpers.rb +11 -11
- data/test/multiverse/suites/sequel/sequel_plugin_test.rb +11 -11
- data/test/multiverse/suites/sidekiq/Envfile +1 -4
- data/test/multiverse/suites/sidekiq/after_suite.rb +9 -0
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +49 -16
- data/test/multiverse/suites/sidekiq/test_worker.rb +1 -2
- data/test/multiverse/suites/sinatra/Envfile +1 -1
- data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -4
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -4
- data/test/multiverse/suites/sinatra/sinatra_parameter_capture_test.rb +65 -0
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -11
- data/test/multiverse/suites/typhoeus/Envfile +8 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +4 -4
- data/test/new_relic/agent/agent/connect_test.rb +13 -9
- data/test/new_relic/agent/agent_test.rb +34 -24
- data/test/new_relic/agent/attribute_filter_test.rb +218 -0
- data/test/new_relic/agent/attribute_processing_test.rb +160 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +88 -0
- data/test/new_relic/agent/configuration/manager_test.rb +3 -4
- data/test/new_relic/agent/configuration/orphan_configuration_test.rb +3 -1
- data/test/new_relic/agent/configuration/server_source_test.rb +39 -0
- data/test/new_relic/agent/cross_app_monitor_test.rb +6 -30
- data/test/new_relic/agent/cross_app_tracing_test.rb +12 -12
- data/test/new_relic/agent/database/sql_obfuscation_test.rb +39 -65
- data/test/new_relic/agent/datastores/metric_helper_test.rb +36 -0
- data/test/new_relic/agent/encoding_normalizer_test.rb +66 -0
- data/test/new_relic/agent/error_collector_test.rb +181 -34
- data/test/new_relic/agent/hash_extensions_test.rb +34 -0
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +20 -23
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +12 -12
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +5 -5
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +4 -4
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +21 -11
- data/test/new_relic/agent/javascript_instrumentor_test.rb +69 -45
- data/test/new_relic/agent/pipe_service_test.rb +2 -2
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +8 -7
- data/test/new_relic/agent/stats_engine/stats_hash_test.rb +2 -2
- data/test/new_relic/agent/threading/backtrace_node_test.rb +2 -2
- data/test/new_relic/agent/transaction/attributes_test.rb +276 -0
- data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +10 -10
- data/test/new_relic/agent/transaction/trace_node_test.rb +361 -0
- data/test/new_relic/agent/transaction/trace_test.rb +394 -0
- data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +127 -57
- data/test/new_relic/agent/transaction_sample_builder_test.rb +70 -78
- data/test/new_relic/agent/transaction_sampler_test.rb +76 -185
- data/test/new_relic/agent/transaction_test.rb +283 -135
- data/test/new_relic/agent_test.rb +27 -12
- data/test/new_relic/cli/commands/install_test.rb +27 -0
- data/test/new_relic/coerce_test.rb +0 -59
- data/test/new_relic/data_container_tests.rb +5 -5
- data/test/new_relic/fake_collector.rb +27 -9
- data/test/new_relic/filtering_test_app.rb +2 -1
- data/test/new_relic/http_client_test_cases.rb +16 -16
- data/test/new_relic/json_wrapper_test.rb +0 -54
- data/test/new_relic/marshalling_test_cases.rb +1 -0
- data/test/new_relic/multiverse_helpers.rb +144 -0
- data/test/new_relic/noticed_error_test.rb +112 -9
- data/test/new_relic/rack/browser_monitoring_test.rb +12 -7
- data/test/new_relic/{transaction_analysis → rack/developer_mode}/segment_summary_test.rb +5 -4
- data/test/new_relic/rack/developer_mode_test.rb +17 -3
- data/test/new_relic/rack/error_collector_test.rb +1 -1
- data/test/performance/lib/performance/instrumentation/stackprof.rb +1 -1
- data/test/performance/script/runner +2 -2
- data/test/performance/suites/active_record.rb +3 -3
- data/test/performance/suites/agent_attributes.rb +62 -0
- data/test/performance/suites/rack_middleware.rb +78 -28
- data/test/performance/suites/transaction_tracing.rb +35 -0
- data/test/test_helper.rb +9 -1
- data/ui/helpers/developer_mode_helper.rb +16 -23
- data/ui/views/newrelic/_sample.rhtml +3 -3
- data/ui/views/newrelic/_segment.rhtml +1 -1
- data/ui/views/newrelic/_show_sample_summary.rhtml +1 -1
- data/ui/views/newrelic/show_sample.rhtml +5 -4
- metadata +23 -80
- data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +0 -25
- data/lib/new_relic/transaction_analysis.rb +0 -80
- data/lib/new_relic/transaction_analysis/segment_summary.rb +0 -53
- data/lib/new_relic/transaction_sample.rb +0 -207
- data/lib/new_relic/transaction_sample/composite_segment.rb +0 -31
- data/lib/new_relic/transaction_sample/fake_segment.rb +0 -13
- data/lib/new_relic/transaction_sample/segment.rb +0 -197
- data/lib/new_relic/transaction_sample/summary_segment.rb +0 -25
- data/lib/new_relic/url_rule.rb +0 -18
- data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.obfuscated +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.sql +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.obfuscated +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.sql +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.sql +0 -4
- data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_double_quoted_string.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_single_quoted_string.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/README.md +0 -4
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.sql +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.sql +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.sql +0 -4
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.sql +0 -3
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.sql +0 -4
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.sql +0 -2
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.sql +0 -4
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.sql +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.obfuscated +0 -1
- data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.sql +0 -1
- data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -261
- data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +0 -52
- data/test/new_relic/transaction_analysis_test.rb +0 -125
- data/test/new_relic/transaction_sample/composite_segment_test.rb +0 -38
- data/test/new_relic/transaction_sample/fake_segment_test.rb +0 -18
- data/test/new_relic/transaction_sample/segment_test.rb +0 -361
- data/test/new_relic/transaction_sample/summary_segment_test.rb +0 -34
- data/test/new_relic/transaction_sample_subtest_test.rb +0 -41
- data/test/new_relic/transaction_sample_test.rb +0 -361
@@ -102,7 +102,7 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
|
|
102
102
|
|
103
103
|
hash1.merge!(hash2)
|
104
104
|
|
105
|
-
assert_equal(4, hash1.keys.size)
|
105
|
+
assert_equal(4, hash1.to_h.keys.size)
|
106
106
|
assert_equal(2, hash1[specs[0]].call_count)
|
107
107
|
assert_equal(2, hash1[specs[1]].call_count)
|
108
108
|
assert_equal(1, hash1[specs[2]].call_count)
|
@@ -140,7 +140,7 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
|
|
140
140
|
|
141
141
|
hash.merge_transaction_metrics!(txn_metrics, 'a_scope')
|
142
142
|
|
143
|
-
assert_equal(4, hash.keys.size)
|
143
|
+
assert_equal(4, hash.to_h.keys.size)
|
144
144
|
assert_equal(2, hash[specs[0]].call_count)
|
145
145
|
assert_equal(2, hash[specs[1]].call_count)
|
146
146
|
assert_equal(1, hash[specs[2]].call_count)
|
@@ -74,12 +74,12 @@ module NewRelic::Agent::Threading
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_nodes_without_line_numbers
|
77
|
-
line = "transaction_sample_buffer.rb:in `
|
77
|
+
line = "transaction_sample_buffer.rb:in `visit_node'"
|
78
78
|
node = create_node(line)
|
79
79
|
convert_nodes_to_array([node])
|
80
80
|
|
81
81
|
assert_equal([
|
82
|
-
["transaction_sample_buffer.rb", "
|
82
|
+
["transaction_sample_buffer.rb", "visit_node", -1],
|
83
83
|
0, 0,
|
84
84
|
[]],
|
85
85
|
node.as_array)
|
@@ -0,0 +1,276 @@
|
|
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/transaction/attributes'
|
7
|
+
require 'new_relic/agent/attribute_filter'
|
8
|
+
|
9
|
+
class AttributesTest < Minitest::Test
|
10
|
+
|
11
|
+
Attributes = NewRelic::Agent::Transaction::Attributes
|
12
|
+
AttributeFilter = NewRelic::Agent::AttributeFilter
|
13
|
+
|
14
|
+
def setup
|
15
|
+
# Lots of tests that just want the default behavior, so make sure filter
|
16
|
+
# is updated to that base
|
17
|
+
NewRelic::Agent.instance.refresh_attribute_filter
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_adds_custom_attribute
|
21
|
+
attributes = create_attributes
|
22
|
+
attributes.merge_custom_attributes(:foo => "bar")
|
23
|
+
|
24
|
+
assert_equal({"foo" => "bar"}, attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_disable_custom_attributes
|
28
|
+
with_config({:'transaction_tracer.attributes.enabled' => false}) do
|
29
|
+
attributes = create_attributes
|
30
|
+
attributes.merge_custom_attributes(:foo => "bar")
|
31
|
+
|
32
|
+
assert_empty attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_disable_custom_attributes_in_high_security_mode
|
37
|
+
with_config(:high_security => true) do
|
38
|
+
attributes = create_attributes
|
39
|
+
attributes.merge_custom_attributes(:foo => "bar")
|
40
|
+
|
41
|
+
assert_empty attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_disable_merging_custom_attributes_in_high_security_mode
|
46
|
+
with_config(:high_security => true) do
|
47
|
+
attributes = create_attributes
|
48
|
+
attributes.merge_custom_attributes(:foo => "bar")
|
49
|
+
|
50
|
+
assert_empty attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_merge_custom_attributes
|
55
|
+
attributes = create_attributes
|
56
|
+
params = {:foo => {:bar => "baz"}}
|
57
|
+
attributes.merge_custom_attributes(params)
|
58
|
+
assert_equal({"foo.bar" => "baz"}, attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_adds_agent_attribute
|
62
|
+
attributes = create_attributes
|
63
|
+
attributes.add_agent_attribute(:foo, "bar", AttributeFilter::DST_ALL)
|
64
|
+
|
65
|
+
assert_equal({:foo => "bar"}, attributes.agent_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_disable_agent_attributes
|
69
|
+
with_config({:'transaction_tracer.attributes.enabled' => false}) do
|
70
|
+
attributes = create_attributes
|
71
|
+
attributes.add_agent_attribute(:foo, "bar", AttributeFilter::DST_ALL)
|
72
|
+
|
73
|
+
assert_empty attributes.agent_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_agent_attributes_obey_default_destinations
|
78
|
+
attributes = create_attributes
|
79
|
+
attributes.add_agent_attribute(:foo, "bar", AttributeFilter::DST_ERROR_COLLECTOR)
|
80
|
+
|
81
|
+
assert_empty attributes.agent_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_adds_intrinsic_attribute_to_only_traces_and_errors
|
85
|
+
attributes = create_attributes
|
86
|
+
attributes.add_intrinsic_attribute(:foo, "bar")
|
87
|
+
|
88
|
+
expected = {:foo => "bar"}
|
89
|
+
assert_equal(expected, attributes.intrinsic_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER))
|
90
|
+
assert_equal(expected, attributes.intrinsic_attributes_for(AttributeFilter::DST_ERROR_COLLECTOR))
|
91
|
+
|
92
|
+
assert_empty(attributes.intrinsic_attributes_for(AttributeFilter::DST_TRANSACTION_EVENTS))
|
93
|
+
assert_empty(attributes.intrinsic_attributes_for(AttributeFilter::DST_BROWSER_MONITORING))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_intrinsic_attributes_arent_disabled_for_traces_and_errors
|
97
|
+
with_config({:'transaction_tracer.attributes.enabled' => false}) do
|
98
|
+
attributes = create_attributes
|
99
|
+
attributes.add_intrinsic_attribute(:foo, "bar")
|
100
|
+
|
101
|
+
expected = {:foo => "bar"}
|
102
|
+
assert_equal(expected, attributes.intrinsic_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER))
|
103
|
+
assert_equal(expected, attributes.intrinsic_attributes_for(AttributeFilter::DST_ERROR_COLLECTOR))
|
104
|
+
|
105
|
+
assert_empty(attributes.intrinsic_attributes_for(AttributeFilter::DST_TRANSACTION_EVENTS))
|
106
|
+
assert_empty(attributes.intrinsic_attributes_for(AttributeFilter::DST_BROWSER_MONITORING))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
MULTIBYTE_CHARACTER = "七"
|
111
|
+
|
112
|
+
def test_truncates_multibyte_string
|
113
|
+
# Leading single byte character makes byteslice yield invalid string
|
114
|
+
value = "j" + MULTIBYTE_CHARACTER * 1000
|
115
|
+
|
116
|
+
attributes = create_attributes
|
117
|
+
attributes.merge_custom_attributes(:key => value)
|
118
|
+
|
119
|
+
custom_attributes = attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
120
|
+
result = custom_attributes["key"]
|
121
|
+
if RUBY_VERSION >= "1.9.3"
|
122
|
+
assert result.valid_encoding?
|
123
|
+
assert result.bytesize < NewRelic::Agent::Transaction::Attributes::VALUE_LIMIT
|
124
|
+
else
|
125
|
+
assert_equal NewRelic::Agent::Transaction::Attributes::VALUE_LIMIT, result.bytesize
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_truncates_multibyte_symbol
|
130
|
+
# Leading single byte character makes byteslice yield invalid string
|
131
|
+
value = ("j" + MULTIBYTE_CHARACTER * 1000).to_sym
|
132
|
+
|
133
|
+
attributes = create_attributes
|
134
|
+
attributes.merge_custom_attributes(:key => value)
|
135
|
+
|
136
|
+
custom_attributes = attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
137
|
+
result = custom_attributes["key"]
|
138
|
+
if RUBY_VERSION >= "1.9.3"
|
139
|
+
assert result.valid_encoding?
|
140
|
+
assert result.bytesize < NewRelic::Agent::Transaction::Attributes::VALUE_LIMIT
|
141
|
+
else
|
142
|
+
assert_equal NewRelic::Agent::Transaction::Attributes::VALUE_LIMIT, result.bytesize
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_limits_key_length
|
147
|
+
key = "x" * (Attributes::KEY_LIMIT + 1)
|
148
|
+
expects_logging(:warn, includes(key))
|
149
|
+
|
150
|
+
attributes = create_attributes
|
151
|
+
attributes.merge_custom_attributes(key => "")
|
152
|
+
|
153
|
+
assert_custom_attributes_empty(attributes)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_limits_key_length_by_bytes
|
157
|
+
key = MULTIBYTE_CHARACTER * Attributes::KEY_LIMIT
|
158
|
+
expects_logging(:warn, includes(key))
|
159
|
+
|
160
|
+
attributes = create_attributes
|
161
|
+
attributes.merge_custom_attributes(key => "")
|
162
|
+
|
163
|
+
assert_custom_attributes_empty(attributes)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_limits_key_length_symbol
|
167
|
+
key = ("x" * (Attributes::KEY_LIMIT + 1)).to_sym
|
168
|
+
expects_logging(:warn, includes(key.to_s))
|
169
|
+
|
170
|
+
attributes = create_attributes
|
171
|
+
attributes.merge_custom_attributes(key => "")
|
172
|
+
|
173
|
+
assert_custom_attributes_empty(attributes)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_limits_key_length_on_merge_custom_attributes
|
177
|
+
key = ("x" * (Attributes::KEY_LIMIT + 1)).to_sym
|
178
|
+
expects_logging(:warn, includes(key.to_s))
|
179
|
+
|
180
|
+
attributes = create_attributes
|
181
|
+
attributes.merge_custom_attributes(key => "")
|
182
|
+
|
183
|
+
assert_custom_attributes_empty(attributes)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_allows_non_string_key_type
|
187
|
+
attributes = create_attributes
|
188
|
+
attributes.merge_custom_attributes(1 => "value")
|
189
|
+
|
190
|
+
assert_equal "value", custom_attributes(attributes)["1"]
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_truncates_string_values
|
194
|
+
value = "x" * 1000
|
195
|
+
|
196
|
+
attributes = create_attributes
|
197
|
+
attributes.merge_custom_attributes(:key => value)
|
198
|
+
|
199
|
+
assert_equal Attributes::VALUE_LIMIT, custom_attributes(attributes)["key"].length
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_truncates_symbol_values
|
203
|
+
value = ("x" * 1000).to_sym
|
204
|
+
|
205
|
+
attributes = create_attributes
|
206
|
+
attributes.merge_custom_attributes(:key => value)
|
207
|
+
|
208
|
+
assert_equal Attributes::VALUE_LIMIT, custom_attributes(attributes)["key"].length
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_leaves_numbers_alone
|
212
|
+
attributes = create_attributes
|
213
|
+
attributes.merge_custom_attributes(:key => 42)
|
214
|
+
|
215
|
+
assert_equal 42, custom_attributes(attributes)["key"]
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_limits_attribute_count
|
219
|
+
::NewRelic::Agent.logger.expects(:warn).once
|
220
|
+
|
221
|
+
attributes = create_attributes
|
222
|
+
100.times do |i|
|
223
|
+
attributes.merge_custom_attributes(i.to_s => i)
|
224
|
+
end
|
225
|
+
|
226
|
+
assert_equal Attributes::COUNT_LIMIT, custom_attributes(attributes).length
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_merge_untrusted_agent_attributes
|
230
|
+
with_config(:'attributes.include' => "request.parameters.*") do
|
231
|
+
attributes = create_attributes
|
232
|
+
params = {:foo => {:bar => "baz"}}
|
233
|
+
attributes.merge_untrusted_agent_attributes(params, 'request.parameters', AttributeFilter::DST_NONE)
|
234
|
+
assert_equal({"request.parameters.foo.bar" => "baz"}, agent_attributes(attributes))
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_merge_untrusted_agent_attributes_drops_long_keys
|
239
|
+
with_config(:'attributes.include' => "request.parameters.*") do
|
240
|
+
attributes = create_attributes
|
241
|
+
params = {
|
242
|
+
"a"*256 => "too long",
|
243
|
+
"foo" => "bar"
|
244
|
+
}
|
245
|
+
attributes.merge_untrusted_agent_attributes(params, 'request.parameters', AttributeFilter::DST_NONE)
|
246
|
+
assert_equal({"request.parameters.foo" => "bar"}, agent_attributes(attributes))
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_merge_untrusted_agent_attributes_disallowed_in_high_security
|
251
|
+
with_config(:high_security => true, :'attributes.include' => "request.parameters.*") do
|
252
|
+
attributes = create_attributes
|
253
|
+
params = { "sneaky" => "code" }
|
254
|
+
|
255
|
+
attributes.merge_untrusted_agent_attributes('request.parameters', params, AttributeFilter::DST_NONE)
|
256
|
+
assert_empty agent_attributes(attributes)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def create_attributes
|
261
|
+
filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
|
262
|
+
NewRelic::Agent::Transaction::Attributes.new(filter)
|
263
|
+
end
|
264
|
+
|
265
|
+
def custom_attributes(attributes)
|
266
|
+
attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
267
|
+
end
|
268
|
+
|
269
|
+
def assert_custom_attributes_empty(attributes)
|
270
|
+
assert_empty custom_attributes(attributes)
|
271
|
+
end
|
272
|
+
|
273
|
+
def agent_attributes(attributes)
|
274
|
+
attributes.agent_attributes_for(AttributeFilter::DST_TRANSACTION_TRACER)
|
275
|
+
end
|
276
|
+
end
|
@@ -43,25 +43,25 @@ class NewRelic::Agent::Transaction
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def test_visit_node_takes_backtraces_in_dev_mode
|
47
47
|
with_config(:developer_mode => true) do
|
48
|
-
|
49
|
-
@buffer.
|
50
|
-
assert
|
48
|
+
node = {}
|
49
|
+
@buffer.visit_node(node)
|
50
|
+
assert node[:backtrace].any? {|trace_line| trace_line.include?(__FILE__)}
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
54
|
+
def test_visit_node_takes_backtraces_not_in_dev_mode
|
55
55
|
with_config(:developer_mode => false) do
|
56
|
-
|
57
|
-
@buffer.
|
58
|
-
assert_nil
|
56
|
+
node = {}
|
57
|
+
@buffer.visit_node(node)
|
58
|
+
assert_nil node[:backtrace]
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def test_visit_node_safe_against_nils
|
63
63
|
with_config(:developer_mode => true) do
|
64
|
-
@buffer.
|
64
|
+
@buffer.visit_node(nil)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -0,0 +1,361 @@
|
|
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/transaction/trace_node'
|
7
|
+
|
8
|
+
class NewRelic::Agent::Transaction::TraceNodeTest < Minitest::Test
|
9
|
+
def test_node_creation
|
10
|
+
# basic smoke test
|
11
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
12
|
+
assert_equal NewRelic::Agent::Transaction::TraceNode, s.class
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_readers
|
16
|
+
t = Time.now
|
17
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(t, 'Custom/test/metric')
|
18
|
+
assert_equal(t, s.entry_timestamp)
|
19
|
+
assert_equal(nil, s.exit_timestamp)
|
20
|
+
assert_equal(nil, s.parent_node)
|
21
|
+
assert_equal('Custom/test/metric', s.metric_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_end_trace
|
25
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
26
|
+
t = Time.now
|
27
|
+
s.end_trace(t)
|
28
|
+
assert_equal(t, s.exit_timestamp)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_called_node
|
32
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
33
|
+
assert_equal [], s.called_nodes
|
34
|
+
fake_node = mock('node')
|
35
|
+
fake_node.expects(:parent_node=).with(s)
|
36
|
+
s.add_called_node(fake_node)
|
37
|
+
assert_equal([fake_node], s.called_nodes)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_to_s
|
41
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
42
|
+
s.expects(:to_debug_str).with(0)
|
43
|
+
s.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_to_array
|
47
|
+
parent = NewRelic::Agent::Transaction::TraceNode.new(1, 'Custom/test/parent')
|
48
|
+
parent.params[:test] = 'value'
|
49
|
+
child = NewRelic::Agent::Transaction::TraceNode.new(2, 'Custom/test/child')
|
50
|
+
child.end_trace(3)
|
51
|
+
parent.add_called_node(child)
|
52
|
+
parent.end_trace(4)
|
53
|
+
expected_array = [1000, 4000, 'Custom/test/parent', {:test => 'value'},
|
54
|
+
[[2000, 3000, 'Custom/test/child', {}, []]]]
|
55
|
+
assert_equal(expected_array, parent.to_array)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_to_array_with_bad_values
|
59
|
+
node = NewRelic::Agent::Transaction::TraceNode.new(nil, nil)
|
60
|
+
node.end_trace(Rational(10, 1))
|
61
|
+
expected = [0, 10_000.0, "<unknown>", {}, []]
|
62
|
+
assert_equal(expected, node.to_array)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_path_string
|
66
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
67
|
+
assert_equal("Custom/test/metric[]", s.path_string)
|
68
|
+
|
69
|
+
fake_node = mock('node')
|
70
|
+
fake_node.expects(:parent_node=).with(s)
|
71
|
+
fake_node.expects(:path_string).returns('Custom/other/metric[]')
|
72
|
+
|
73
|
+
|
74
|
+
s.add_called_node(fake_node)
|
75
|
+
assert_equal("Custom/test/metric[Custom/other/metric[]]", s.path_string)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_to_s_compact
|
79
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
80
|
+
assert_equal("Custom/test/metric", s.to_s_compact)
|
81
|
+
|
82
|
+
fake_node = mock('node')
|
83
|
+
fake_node.expects(:parent_node=).with(s)
|
84
|
+
fake_node.expects(:to_s_compact).returns('Custom/other/metric')
|
85
|
+
s.add_called_node(fake_node)
|
86
|
+
|
87
|
+
assert_equal("Custom/test/metric{Custom/other/metric}", s.to_s_compact)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_to_debug_str_basic
|
91
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
92
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n<< n/a Custom/test/metric\n", s.to_debug_str(0))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_to_debug_str_with_params
|
96
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
97
|
+
s.params = {:whee => 'a param'}
|
98
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n -whee : a param\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_to_debug_str_closed
|
102
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
103
|
+
s.end_trace(0.1)
|
104
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n<< 100 ms Custom/test/metric\n", s.to_debug_str(0))
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_to_debug_str_closed_with_nonnumeric
|
108
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
109
|
+
s.end_trace("0.1")
|
110
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n<< 0.1 Custom/test/metric\n", s.to_debug_str(0))
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_to_debug_str_one_child
|
114
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
115
|
+
s.add_called_node(NewRelic::Agent::Transaction::TraceNode.new(0.1, 'Custom/test/other'))
|
116
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/other \n << n/a Custom/test/other\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
|
117
|
+
# try closing it
|
118
|
+
s.called_nodes.first.end_trace(0.15)
|
119
|
+
s.end_trace(0.2)
|
120
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/other \n << 150 ms Custom/test/other\n<< 200 ms Custom/test/metric\n", s.to_debug_str(0))
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_to_debug_str_multichild
|
124
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
125
|
+
s.add_called_node(NewRelic::Agent::Transaction::TraceNode.new(0.1, 'Custom/test/other'))
|
126
|
+
s.add_called_node(NewRelic::Agent::Transaction::TraceNode.new(0.11, 'Custom/test/extra'))
|
127
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/other \n << n/a Custom/test/other\n >> 110 ms [TraceNode] Custom/test/extra \n << n/a Custom/test/extra\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
|
128
|
+
ending = 0.12
|
129
|
+
s.called_nodes.each { |x| x.end_trace(ending += 0.01) }
|
130
|
+
s.end_trace(0.2)
|
131
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/other \n << 130 ms Custom/test/other\n >> 110 ms [TraceNode] Custom/test/extra \n << 140 ms Custom/test/extra\n<< 200 ms Custom/test/metric\n", s.to_debug_str(0))
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_to_debug_str_nested
|
135
|
+
inner = NewRelic::Agent::Transaction::TraceNode.new(0.2, 'Custom/test/inner')
|
136
|
+
middle = NewRelic::Agent::Transaction::TraceNode.new(0.1, 'Custom/test/middle')
|
137
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(0.0, 'Custom/test/metric')
|
138
|
+
middle.add_called_node(inner)
|
139
|
+
s.add_called_node(middle)
|
140
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/middle \n >> 200 ms [TraceNode] Custom/test/inner \n << n/a Custom/test/inner\n << n/a Custom/test/middle\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
|
141
|
+
|
142
|
+
# close them
|
143
|
+
inner.end_trace(0.21)
|
144
|
+
middle.end_trace(0.22)
|
145
|
+
s.end_trace(0.23)
|
146
|
+
assert_equal(">> 0 ms [TraceNode] Custom/test/metric \n >> 100 ms [TraceNode] Custom/test/middle \n >> 200 ms [TraceNode] Custom/test/inner \n << 210 ms Custom/test/inner\n << 220 ms Custom/test/middle\n<< 230 ms Custom/test/metric\n", s.to_debug_str(0))
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_called_nodes_default
|
150
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
151
|
+
assert_equal([], s.called_nodes)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_called_nodes_with_nodes
|
155
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
156
|
+
fake_node = mock('node')
|
157
|
+
fake_node.expects(:parent_node=).with(s)
|
158
|
+
s.add_called_node(fake_node)
|
159
|
+
|
160
|
+
assert_equal([fake_node], s.called_nodes)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_duration
|
164
|
+
fake_entry_timestamp = mock('entry timestamp')
|
165
|
+
fake_exit_timestamp = mock('exit timestamp')
|
166
|
+
fake_result = mock('numeric')
|
167
|
+
fake_exit_timestamp.expects(:-).with(fake_entry_timestamp).returns(fake_result)
|
168
|
+
fake_result.expects(:to_f).returns(0.5)
|
169
|
+
|
170
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(fake_entry_timestamp, 'Custom/test/metric')
|
171
|
+
s.end_trace(fake_exit_timestamp)
|
172
|
+
assert_equal(0.5, s.duration)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_exclusive_duration_no_children
|
176
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
177
|
+
s.expects(:duration).returns(0.5)
|
178
|
+
assert_equal(0.5, s.exclusive_duration)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_exclusive_duration_with_children
|
182
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
183
|
+
|
184
|
+
s.expects(:duration).returns(0.5)
|
185
|
+
|
186
|
+
fake_node = mock('node')
|
187
|
+
fake_node.expects(:parent_node=).with(s)
|
188
|
+
fake_node.expects(:duration).returns(0.1)
|
189
|
+
|
190
|
+
s.add_called_node(fake_node)
|
191
|
+
|
192
|
+
assert_equal(0.4, s.exclusive_duration)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_count_nodes_default
|
196
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
197
|
+
assert_equal(1, s.count_nodes)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_count_nodes_with_children
|
201
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
202
|
+
|
203
|
+
fake_node = mock('node')
|
204
|
+
fake_node.expects(:parent_node=).with(s)
|
205
|
+
fake_node.expects(:count_nodes).returns(1)
|
206
|
+
|
207
|
+
s.add_called_node(fake_node)
|
208
|
+
|
209
|
+
assert_equal(2, s.count_nodes)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_key_equals
|
213
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
214
|
+
# doing this to hold the reference to the hash
|
215
|
+
params = {}
|
216
|
+
s.params = params
|
217
|
+
assert_equal(params, s.params)
|
218
|
+
|
219
|
+
# should delegate to the same hash we have above
|
220
|
+
s[:foo] = 'correct'
|
221
|
+
|
222
|
+
assert_equal('correct', params[:foo])
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_key
|
226
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
227
|
+
s.params = {:foo => 'correct'}
|
228
|
+
assert_equal('correct', s[:foo])
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_params
|
232
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
233
|
+
|
234
|
+
# should have a default value
|
235
|
+
assert_equal(nil, s.instance_eval { @params })
|
236
|
+
assert_equal({}, s.params)
|
237
|
+
|
238
|
+
# should otherwise take the value from the @params var
|
239
|
+
s.instance_eval { @params = {:foo => 'correct'} }
|
240
|
+
assert_equal({:foo => 'correct'}, s.params)
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_each_node_default
|
244
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
245
|
+
# in the base case it just yields the block to itself
|
246
|
+
count = 0
|
247
|
+
s.each_node do |x|
|
248
|
+
count += 1
|
249
|
+
assert_equal(s, x)
|
250
|
+
end
|
251
|
+
# should only run once
|
252
|
+
assert_equal(1, count)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_each_node_with_children
|
256
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
257
|
+
|
258
|
+
fake_node = mock('node')
|
259
|
+
fake_node.expects(:parent_node=).with(s)
|
260
|
+
fake_node.expects(:each_node).yields(fake_node)
|
261
|
+
|
262
|
+
s.add_called_node(fake_node)
|
263
|
+
|
264
|
+
count = 0
|
265
|
+
s.each_node do |x|
|
266
|
+
count += 1
|
267
|
+
end
|
268
|
+
|
269
|
+
assert_equal(2, count)
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_each_node_with_nest_tracking
|
273
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
274
|
+
|
275
|
+
summary = mock('summary')
|
276
|
+
summary.expects(:current_nest_count).twice.returns(0).then.returns(1)
|
277
|
+
summary.expects(:current_nest_count=).twice
|
278
|
+
s.each_node_with_nest_tracking do |x|
|
279
|
+
summary
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_find_node_default
|
284
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
285
|
+
id_to_find = s.object_id
|
286
|
+
# should return itself in the base case
|
287
|
+
assert_equal(s, s.find_node(id_to_find))
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_find_node_not_found
|
291
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
292
|
+
assert_equal(nil, s.find_node(-1))
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_find_node_with_children
|
296
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
297
|
+
id_to_find = s.object_id
|
298
|
+
# should return itself in the base case
|
299
|
+
assert_equal(s, s.find_node(id_to_find))
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_explain_sql_raising_an_error
|
303
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
304
|
+
config = { :adapter => 'mysql' }
|
305
|
+
statement = NewRelic::Agent::Database::Statement.new('SELECT')
|
306
|
+
statement.config = config
|
307
|
+
statement.explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
|
308
|
+
s.params = {:sql => statement}
|
309
|
+
NewRelic::Agent::Database.expects(:get_connection).with(config).raises(RuntimeError.new("whee"))
|
310
|
+
s.explain_sql
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_explain_sql_can_handle_missing_config
|
314
|
+
# If TT node came over from Resque child, might not be a Statement
|
315
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
316
|
+
s.params = { :sql => "SELECT * FROM galaxy" }
|
317
|
+
s.explain_sql
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_explain_sql_can_use_already_existing_plan
|
321
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
322
|
+
s.params = {
|
323
|
+
:sql => "SELECT * FROM galaxy",
|
324
|
+
:explain_plan => "EXPLAIN IT!"
|
325
|
+
}
|
326
|
+
|
327
|
+
assert_equal("EXPLAIN IT!", s.explain_sql)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_params_equal
|
331
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
332
|
+
assert_equal(nil, s.instance_eval { @params })
|
333
|
+
|
334
|
+
params = {:foo => 'correct'}
|
335
|
+
|
336
|
+
s.params = params
|
337
|
+
assert_equal(params, s.instance_eval { @params })
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_obfuscated_sql
|
341
|
+
sql = 'select * from table where id = 1'
|
342
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
343
|
+
s[:sql] = sql
|
344
|
+
assert_equal('select * from table where id = ?', s.obfuscated_sql)
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_called_nodes_equals
|
348
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
349
|
+
assert_equal(nil, s.instance_eval { @called_nodes })
|
350
|
+
s.called_nodes = [1, 2, 3]
|
351
|
+
assert_equal([1, 2, 3], s.instance_eval { @called_nodes })
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_parent_node_equals
|
355
|
+
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
356
|
+
assert_equal(nil, s.instance_eval { @parent_node })
|
357
|
+
fake_node = mock('node')
|
358
|
+
s.send(:parent_node=, fake_node)
|
359
|
+
assert_equal(fake_node, s.parent_node)
|
360
|
+
end
|
361
|
+
end
|