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
@@ -1,34 +0,0 @@
|
|
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/transaction_sample/summary_segment'
|
7
|
-
class NewRelic::TransactionSample::SummarySegmentTest < Minitest::Test
|
8
|
-
def test_summary_segment_creation
|
9
|
-
fake_segment = mock_segment
|
10
|
-
NewRelic::TransactionSample::SummarySegment.new(fake_segment)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_add_segments
|
14
|
-
fake_segment = mock_segment
|
15
|
-
ss = NewRelic::TransactionSample::SummarySegment.new(fake_segment)
|
16
|
-
other_fake_segment = mock_segment
|
17
|
-
# with the new summary segment
|
18
|
-
ss.expects(:add_called_segment).with(instance_of(NewRelic::TransactionSample::SummarySegment))
|
19
|
-
ss.add_segments([other_fake_segment])
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
@@seg_count = 0
|
25
|
-
def mock_segment
|
26
|
-
@@seg_count += 1
|
27
|
-
segment = mock('segment ' + @@seg_count.to_s)
|
28
|
-
segment.expects(:entry_timestamp).returns(Time.now)
|
29
|
-
segment.expects(:exit_timestamp).returns(Time.now)
|
30
|
-
segment.expects(:metric_name).returns('Custom/test/metric')
|
31
|
-
segment.expects(:called_segments).returns([])
|
32
|
-
segment
|
33
|
-
end
|
34
|
-
end
|
@@ -1,41 +0,0 @@
|
|
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
|
-
class NewRelic::TransactionSample::SubTest < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@t = NewRelic::TransactionSample.new
|
8
|
-
|
9
|
-
@t.params[:test] = "hi"
|
10
|
-
|
11
|
-
s1 = @t.create_segment(1.0, "controller")
|
12
|
-
|
13
|
-
@t.root_segment.add_called_segment(s1)
|
14
|
-
|
15
|
-
s2 = @t.create_segment(2.0, "AR1")
|
16
|
-
|
17
|
-
s2.params[:test] = "test"
|
18
|
-
|
19
|
-
s1.add_called_segment(s2)
|
20
|
-
s2.end_trace 3.0
|
21
|
-
s1.end_trace 4.0
|
22
|
-
|
23
|
-
s3 = @t.create_segment(4.0, "post_filter")
|
24
|
-
@t.root_segment.add_called_segment(s3)
|
25
|
-
s3.end_trace 6.0
|
26
|
-
|
27
|
-
s4 = @t.create_segment(6.0, "post_filter")
|
28
|
-
@t.root_segment.add_called_segment(s4)
|
29
|
-
s4.end_trace 7.0
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_exclusive_duration
|
33
|
-
s1 = @t.root_segment.called_segments.first
|
34
|
-
assert_equal 3.0, s1.duration
|
35
|
-
assert_equal 2.0, s1.exclusive_duration
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_count_the_segments
|
39
|
-
assert_equal 4, @t.count_segments
|
40
|
-
end
|
41
|
-
end
|
@@ -1,361 +0,0 @@
|
|
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/rack/developer_mode'
|
7
|
-
|
8
|
-
class NewRelic::TransactionSampleTest < Minitest::Test
|
9
|
-
include TransactionSampleTestHelper
|
10
|
-
|
11
|
-
::SQL_STATEMENT = "SELECT * from sandwiches WHERE meat='bacon'"
|
12
|
-
::OBFUSCATED_SQL_STATEMENT = "SELECT * from sandwiches WHERE meat=?"
|
13
|
-
|
14
|
-
FORCE_PERSIST_POSITION = 7
|
15
|
-
SYNTHETICS_POSITION = 9
|
16
|
-
|
17
|
-
def setup
|
18
|
-
@test_config = { :developer_mode => true }
|
19
|
-
NewRelic::Agent.config.add_config_for_testing(@test_config)
|
20
|
-
|
21
|
-
NewRelic::Agent.agent.transaction_sampler.reset!
|
22
|
-
|
23
|
-
@connection_stub = Mocha::Mockery.instance.named_mock('connection')
|
24
|
-
@connection_stub.stubs(:execute).returns(dummy_mysql_explain_result({'foo' => 'bar'}))
|
25
|
-
|
26
|
-
NewRelic::Agent::Database.stubs(:get_connection).returns @connection_stub
|
27
|
-
@t = make_sql_transaction(::SQL_STATEMENT)
|
28
|
-
|
29
|
-
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
30
|
-
@marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
|
31
|
-
else
|
32
|
-
@marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def teardown
|
38
|
-
NewRelic::Agent.config.remove_config(@test_config)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_be_recorded
|
42
|
-
refute_nil @t
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_prepare_to_send_strips_sql_if_record_sql_is_off_or_none_or_false
|
46
|
-
record_sql_values = %w(off none false)
|
47
|
-
record_sql_values.each do |record_sql_value|
|
48
|
-
s = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
|
49
|
-
with_config(:'transaction_tracer.record_sql' => record_sql_value) do
|
50
|
-
s.prepare_to_send!
|
51
|
-
s.each_segment do |segment|
|
52
|
-
assert_nil segment.params[:explain_plan]
|
53
|
-
assert_nil segment.params[:sql]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_prepare_to_send_preserves_raw_sql_if_record_sql_set_to_raw
|
60
|
-
with_config(:'transaction_tracer.record_sql' => 'raw') do
|
61
|
-
@t.prepare_to_send!
|
62
|
-
end
|
63
|
-
|
64
|
-
sql_statements = extract_captured_sql(@t)
|
65
|
-
assert_equal([::SQL_STATEMENT], sql_statements)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_prepare_to_send_obfuscates_sql_if_record_sql_set_to_obfuscated
|
69
|
-
with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
|
70
|
-
@t.prepare_to_send!
|
71
|
-
end
|
72
|
-
|
73
|
-
sql_statements = extract_captured_sql(@t)
|
74
|
-
assert_equal([::OBFUSCATED_SQL_STATEMENT], sql_statements)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_have_sql_rows_when_sql_is_recorded
|
78
|
-
with_config(:'transaction_tracer.record_sql' => 'off') do
|
79
|
-
@t.prepare_to_send!
|
80
|
-
end
|
81
|
-
|
82
|
-
assert @t.sql_segments.empty?
|
83
|
-
@t.root_segment[:sql] = 'hello'
|
84
|
-
assert !@t.sql_segments.empty?
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_have_sql_rows_when_sql_is_obfuscated
|
88
|
-
with_config(:'transaction_tracer.record_sql' => 'off') do
|
89
|
-
@t.prepare_to_send!
|
90
|
-
end
|
91
|
-
|
92
|
-
assert @t.sql_segments.empty?
|
93
|
-
@t.root_segment[:sql_obfuscated] = 'hello'
|
94
|
-
assert !@t.sql_segments.empty?
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_have_sql_rows_when_recording_non_sql_keys
|
98
|
-
with_config(:'transaction_tracer.record_sql' => 'off') do
|
99
|
-
@t.prepare_to_send!
|
100
|
-
end
|
101
|
-
|
102
|
-
assert @t.sql_segments.empty?
|
103
|
-
@t.root_segment[:key] = 'hello'
|
104
|
-
assert !@t.sql_segments.empty?
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_catch_exceptions
|
108
|
-
config = {
|
109
|
-
:'transaction_tracer.record_sql' => 'obfuscated',
|
110
|
-
:'transaction_tracer.explain_enabled' => true,
|
111
|
-
:'transaction_tracer.explain_threshold' => 0.00000001
|
112
|
-
}
|
113
|
-
|
114
|
-
@connection_stub.expects(:execute).raises
|
115
|
-
with_config(config) do
|
116
|
-
@t.prepare_to_send!
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_have_explains
|
121
|
-
config = {
|
122
|
-
:'transaction_tracer.record_sql' => 'obfuscated',
|
123
|
-
:'transaction_tracer.explain_enabled' => true,
|
124
|
-
:'transaction_tracer.explain_threshold' => 0.00000001
|
125
|
-
}
|
126
|
-
|
127
|
-
with_config(config) do
|
128
|
-
@t.prepare_to_send!
|
129
|
-
end
|
130
|
-
|
131
|
-
@t.each_segment do |segment|
|
132
|
-
if segment.params[:explain_plan]
|
133
|
-
explanation = segment.params[:explain_plan]
|
134
|
-
|
135
|
-
assert_kind_of Array, explanation
|
136
|
-
assert_equal([['foo'], [['bar']]], explanation)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_not_record_transactions
|
142
|
-
NewRelic::Agent.instance.transaction_sampler.reset!
|
143
|
-
|
144
|
-
NewRelic::Agent.disable_transaction_tracing do
|
145
|
-
t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
|
146
|
-
assert t.nil?
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_path_string
|
151
|
-
s = @t.prepare_to_send!
|
152
|
-
fake_segment = mock('segment')
|
153
|
-
fake_segment.expects(:path_string).returns('a path string')
|
154
|
-
s.instance_eval do
|
155
|
-
@root_segment = fake_segment
|
156
|
-
end
|
157
|
-
|
158
|
-
assert_equal('a path string', s.path_string)
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_params_equals
|
162
|
-
s = @t.prepare_to_send!
|
163
|
-
s.params = {:params => 'hash' }
|
164
|
-
assert_equal({:params => 'hash'}, s.params, "should have the specified hash, but instead was #{s.params}")
|
165
|
-
end
|
166
|
-
|
167
|
-
class Hat
|
168
|
-
# just here to mess with the to_s logic in transaction samples
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_to_s_with_bad_object
|
172
|
-
@t.prepare_to_send!
|
173
|
-
@t.params[:fake] = Hat.new
|
174
|
-
assert_raises(RuntimeError) do
|
175
|
-
@t.to_s
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_to_s_includes_keys
|
180
|
-
@t.prepare_to_send!
|
181
|
-
@t.params[:fake_key] = 'a fake param'
|
182
|
-
assert(@t.to_s.include?('fake_key'), "should include 'fake_key' but instead was (#{@t.to_s})")
|
183
|
-
assert(@t.to_s.include?('a fake param'), "should include 'a fake param' but instead was (#{@t.to_s})")
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_find_segment
|
187
|
-
s = @t.prepare_to_send!
|
188
|
-
fake_segment = mock('segment')
|
189
|
-
fake_segment.expects(:find_segment).with(1).returns('a segment')
|
190
|
-
s.instance_eval do
|
191
|
-
@root_segment = fake_segment
|
192
|
-
end
|
193
|
-
|
194
|
-
assert_equal('a segment', s.find_segment(1))
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_timestamp
|
198
|
-
s = @t.prepare_to_send!
|
199
|
-
assert(s.timestamp.instance_of?(Float), "s.timestamp should be a Float, but is #{s.timestamp.class.inspect}")
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_xray_session_id
|
203
|
-
@t.xray_session_id = 123
|
204
|
-
s = @t.prepare_to_send!
|
205
|
-
assert_equal(123, s.xray_session_id)
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_prepare_to_send_marks_returned_sample_as_prepared
|
209
|
-
assert(!@t.prepared?)
|
210
|
-
prepared_sample = @t.prepare_to_send!
|
211
|
-
assert(prepared_sample.prepared?)
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_prepare_to_send_does_not_re_prepare
|
215
|
-
@t.prepare_to_send!
|
216
|
-
@t.expects(:collect_explain_plans!).never
|
217
|
-
@t.expects(:prepare_sql_for_transmission!).never
|
218
|
-
@t.prepare_to_send!
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_threshold_preserved_by_prepare_to_send
|
222
|
-
@t.threshold = 4.2
|
223
|
-
s = @t.prepare_to_send!
|
224
|
-
assert_equal(4.2, s.threshold)
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_count_segments
|
228
|
-
transaction = run_sample_trace do |sampler|
|
229
|
-
state = NewRelic::Agent::TransactionState.tl_get
|
230
|
-
sampler.notice_push_frame(state, "level0")
|
231
|
-
sampler.notice_push_frame(state, "level-1")
|
232
|
-
sampler.notice_push_frame(state, "level-2")
|
233
|
-
sampler.notice_sql(::SQL_STATEMENT, {}, 0, state)
|
234
|
-
sampler.notice_pop_frame(state, "level-2")
|
235
|
-
sampler.notice_pop_frame(state, "level-1")
|
236
|
-
sampler.notice_pop_frame(state, "level0")
|
237
|
-
end
|
238
|
-
|
239
|
-
assert_equal 6, transaction.count_segments
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_to_array
|
243
|
-
# Round-trip through Time.at makes minor rounding diffs in Rubinius
|
244
|
-
# Check each element separately so we can reconcile the delta
|
245
|
-
result = @t.to_array
|
246
|
-
assert_equal 4, result.length
|
247
|
-
|
248
|
-
assert_in_delta(@t.start_time.to_f, result[0], 0.000001)
|
249
|
-
assert_equal @t.params[:request_params], result[1]
|
250
|
-
assert_equal @t.params[:custom_params], result[2]
|
251
|
-
assert_equal @t.root_segment.to_array, result[3]
|
252
|
-
end
|
253
|
-
|
254
|
-
|
255
|
-
def test_to_array_with_bad_values
|
256
|
-
transaction = NewRelic::TransactionSample.new(nil)
|
257
|
-
expected = [0.0, {}, nil, [0, 0, "ROOT", {}, []]]
|
258
|
-
assert_equal expected, transaction.to_array
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_to_collector_array
|
262
|
-
expected_array = [(@t.start_time.to_f * 1000).round,
|
263
|
-
(@t.duration * 1000).round,
|
264
|
-
@t.params[:path], @t.params[:uri],
|
265
|
-
trace_tree,
|
266
|
-
@t.guid, nil, !!@t.force_persist,
|
267
|
-
@t.xray_session_id,
|
268
|
-
@t.synthetics_resource_id]
|
269
|
-
|
270
|
-
assert_collector_arrays_match expected_array, @t.to_collector_array(@marshaller.default_encoder)
|
271
|
-
|
272
|
-
end
|
273
|
-
|
274
|
-
def assert_collector_arrays_match(expected_array, actual_array)
|
275
|
-
expected_array[4] = expand_trace_tree(expected_array[4])
|
276
|
-
actual_array[4] = expand_trace_tree(actual_array[4])
|
277
|
-
|
278
|
-
assert_equal expected_array, actual_array
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_to_collector_array_forces_xrays
|
282
|
-
@t.force_persist = false
|
283
|
-
@t.xray_session_id = 123
|
284
|
-
result = @t.to_collector_array(@marshaller.default_encoder)
|
285
|
-
assert_equal true, result[FORCE_PERSIST_POSITION]
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_to_collector_array_uses_synthetics_resource_id
|
289
|
-
@t.synthetics_resource_id = '42'
|
290
|
-
result = @t.to_collector_array(@marshaller.default_encoder)
|
291
|
-
assert_equal '42', result[SYNTHETICS_POSITION]
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_to_collector_array_with_bad_values
|
295
|
-
transaction = NewRelic::TransactionSample.new(nil)
|
296
|
-
transaction.root_segment.end_trace(Rational(10, 1))
|
297
|
-
transaction.xray_session_id = "booooooo"
|
298
|
-
|
299
|
-
expected = [
|
300
|
-
0, 10_000,
|
301
|
-
nil, nil,
|
302
|
-
trace_tree(transaction),
|
303
|
-
transaction.guid,
|
304
|
-
nil, false, nil, nil]
|
305
|
-
|
306
|
-
actual = transaction.to_collector_array(@marshaller.default_encoder)
|
307
|
-
assert_collector_arrays_match expected, actual
|
308
|
-
end
|
309
|
-
|
310
|
-
INVALID_UTF8_STRING = (''.respond_to?(:force_encoding) ? "\x80".force_encoding('UTF-8') : "\x80")
|
311
|
-
|
312
|
-
def test_prepare_to_send_with_incorrectly_encoded_string_in_sql_query
|
313
|
-
query = "SELECT * FROM table WHERE col1=\"#{INVALID_UTF8_STRING}\" AND col2=\"whatev\""
|
314
|
-
|
315
|
-
t = nil
|
316
|
-
with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
|
317
|
-
t = make_sql_transaction(query)
|
318
|
-
t.prepare_to_send!
|
319
|
-
end
|
320
|
-
|
321
|
-
sql_statements = extract_captured_sql(t)
|
322
|
-
assert_equal(["SELECT * FROM table WHERE col1=? AND col2=?"], sql_statements)
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_multiple_calls_to_notice_sequel_appends_sql
|
326
|
-
queries = ["BEGIN", "INSERT items(title) VALUES('title')", "COMMIT"]
|
327
|
-
|
328
|
-
t = make_sql_transaction(*queries)
|
329
|
-
sql_statements = extract_captured_sql(t)
|
330
|
-
|
331
|
-
assert_equal [queries.join("\n")], sql_statements
|
332
|
-
end
|
333
|
-
|
334
|
-
def trace_tree(transaction=@t)
|
335
|
-
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
336
|
-
trace_tree = compress(JSON.dump(transaction.to_array))
|
337
|
-
else
|
338
|
-
trace_tree = transaction.to_array
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
def compress(string)
|
343
|
-
Base64.encode64(Zlib::Deflate.deflate(string, Zlib::DEFAULT_COMPRESSION))
|
344
|
-
end
|
345
|
-
|
346
|
-
def expand_trace_tree(encoded_tree)
|
347
|
-
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
348
|
-
JSON.load(Zlib::Inflate.inflate(Base64.decode64(encoded_tree)))
|
349
|
-
else
|
350
|
-
encoded_tree
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
def extract_captured_sql(trace)
|
355
|
-
sqls = []
|
356
|
-
trace.each_segment do |s|
|
357
|
-
sqls << s.params[:sql]
|
358
|
-
end
|
359
|
-
sqls.compact
|
360
|
-
end
|
361
|
-
end
|