newrelic_rpm 4.8.0.341 → 6.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- data/.github/actions/annotate/README.md +79 -0
- data/.github/actions/annotate/action.yml +6 -0
- data/.github/actions/annotate/dist/index.js +433 -0
- data/.github/actions/annotate/index.js +25 -0
- data/.github/actions/annotate/package-lock.json +172 -0
- data/.github/actions/annotate/package.json +30 -0
- data/.github/actions/annotate/pre-commit +5 -0
- data/.github/actions/build-ruby/README.md +79 -0
- data/.github/actions/build-ruby/action.yml +15 -0
- data/.github/actions/build-ruby/dist/index.js +52683 -0
- data/.github/actions/build-ruby/index.js +514 -0
- data/.github/actions/build-ruby/package-lock.json +581 -0
- data/.github/actions/build-ruby/package.json +32 -0
- data/.github/actions/build-ruby/pre-commit +5 -0
- data/.github/pull_request_template.md +16 -0
- data/.github/workflows/ci.yml +212 -0
- data/.github/workflows/pr_review_checklist.yml +22 -0
- data/.github/workflows/release.yml +78 -0
- data/.github/workflows/scripts/rubygems-authenticate.py +13 -0
- data/.github/workflows/scripts/rubygems-publish.rb +32 -0
- data/.github/workflows/snyk.yml +27 -0
- data/.github/workflows/stale.yml +21 -0
- data/.gitignore +9 -0
- data/.yardopts +4 -1
- data/CHANGELOG.md +868 -3
- data/CONTRIBUTING.md +106 -19
- data/Gemfile +6 -2
- data/Guardfile +18 -1
- data/LICENSE +208 -38
- data/README.md +81 -88
- data/ROADMAP.md +24 -0
- data/Rakefile +2 -0
- data/THIRD_PARTY_NOTICES.md +213 -0
- data/bin/nrdebug +1 -1
- data/config.dot +3 -12
- data/init.rb +1 -1
- data/install.rb +1 -1
- data/lib/new_relic/agent.rb +145 -31
- data/lib/new_relic/agent/adaptive_sampler.rb +104 -0
- data/lib/new_relic/agent/agent.rb +192 -190
- data/lib/new_relic/agent/agent_logger.rb +5 -1
- data/lib/new_relic/agent/attribute_filter.rb +85 -25
- data/lib/new_relic/agent/attribute_processing.rb +1 -1
- data/lib/new_relic/agent/attributes.rb +152 -0
- data/lib/new_relic/agent/audit_logger.rb +1 -1
- data/lib/new_relic/agent/autostart.rb +20 -15
- data/lib/new_relic/agent/chained_call.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command_router.rb +3 -22
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
- data/lib/new_relic/agent/configuration.rb +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +375 -67
- data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
- data/lib/new_relic/agent/configuration/environment_source.rb +5 -3
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
- data/lib/new_relic/agent/configuration/high_security_source.rb +2 -3
- data/lib/new_relic/agent/configuration/manager.rb +54 -43
- data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
- data/lib/new_relic/agent/configuration/security_policy_source.rb +238 -0
- data/lib/new_relic/agent/configuration/server_source.rb +46 -5
- data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
- data/lib/new_relic/agent/connect/request_builder.rb +61 -0
- data/lib/new_relic/agent/connect/response_handler.rb +61 -0
- data/lib/new_relic/agent/custom_event_aggregator.rb +17 -6
- data/lib/new_relic/agent/database.rb +21 -3
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +12 -1
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
- data/lib/new_relic/agent/database/obfuscator.rb +1 -1
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
- data/lib/new_relic/agent/datastores.rb +12 -11
- data/lib/new_relic/agent/datastores/metric_helper.rb +2 -3
- data/lib/new_relic/agent/datastores/mongo.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +1 -1
- data/lib/new_relic/agent/deprecator.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing.rb +216 -0
- data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +44 -0
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +248 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +165 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
- data/lib/new_relic/agent/error_collector.rb +51 -20
- data/lib/new_relic/agent/error_event_aggregator.rb +14 -7
- data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
- data/lib/new_relic/agent/event_aggregator.rb +34 -15
- data/lib/new_relic/agent/event_buffer.rb +1 -1
- data/lib/new_relic/agent/event_listener.rb +1 -1
- data/lib/new_relic/agent/event_loop.rb +1 -1
- data/lib/new_relic/agent/external.rb +31 -29
- data/lib/new_relic/agent/guid_generator.rb +28 -0
- data/lib/new_relic/agent/harvester.rb +1 -1
- data/lib/new_relic/agent/heap.rb +140 -0
- data/lib/new_relic/agent/hostname.rb +16 -2
- data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
- data/lib/new_relic/agent/http_clients/uri_util.rb +12 -11
- data/lib/new_relic/agent/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +26 -43
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +56 -74
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +82 -56
- data/lib/new_relic/agent/instrumentation/active_job.rb +19 -17
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +82 -24
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +168 -0
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +102 -31
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +47 -57
- data/lib/new_relic/agent/instrumentation/active_storage.rb +23 -0
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +63 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +24 -8
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/bunny.rb +115 -44
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +18 -12
- data/lib/new_relic/agent/instrumentation/curb.rb +121 -35
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +6 -4
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +61 -25
- data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +8 -5
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +4 -3
- data/lib/new_relic/agent/instrumentation/grape.rb +46 -35
- data/lib/new_relic/agent/instrumentation/http.rb +8 -5
- data/lib/new_relic/agent/instrumentation/httpclient.rb +7 -5
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +5 -3
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +10 -6
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +13 -5
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +20 -11
- data/lib/new_relic/agent/instrumentation/mongo.rb +11 -5
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +39 -7
- data/lib/new_relic/agent/instrumentation/net.rb +60 -23
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +100 -0
- data/lib/new_relic/agent/instrumentation/padrino.rb +40 -16
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rack.rb +36 -13
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
- data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_cable.rb +8 -5
- data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_controller.rb +4 -4
- data/lib/new_relic/agent/instrumentation/{rails4 → rails_notifications}/action_view.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rake.rb +56 -22
- data/lib/new_relic/agent/instrumentation/redis.rb +141 -56
- data/lib/new_relic/agent/instrumentation/resque.rb +21 -37
- data/lib/new_relic/agent/instrumentation/sequel.rb +2 -3
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
- data/lib/new_relic/agent/instrumentation/sinatra.rb +62 -23
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +27 -10
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +19 -16
- data/lib/new_relic/agent/log_once.rb +1 -1
- data/lib/new_relic/agent/logging.rb +139 -0
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +15 -59
- data/lib/new_relic/agent/method_tracer.rb +42 -25
- data/lib/new_relic/agent/method_tracer_helpers.rb +5 -5
- data/lib/new_relic/agent/monitors.rb +27 -0
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
- data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +4 -4
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +4 -7
- data/lib/new_relic/agent/new_relic_service.rb +174 -63
- data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -2
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +6 -27
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +61 -0
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/null_logger.rb +1 -1
- data/lib/new_relic/agent/obfuscator.rb +1 -1
- data/lib/new_relic/agent/parameter_filtering.rb +19 -6
- data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/pipe_service.rb +5 -1
- data/lib/new_relic/agent/prepend_supportability.rb +1 -1
- data/lib/new_relic/agent/priority_sampled_buffer.rb +95 -0
- data/lib/new_relic/agent/range_extensions.rb +1 -1
- data/lib/new_relic/agent/rules_engine.rb +1 -1
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
- data/lib/new_relic/agent/sampler.rb +1 -1
- data/lib/new_relic/agent/sampler_collection.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
- data/lib/new_relic/agent/span_event_aggregator.rb +49 -0
- data/lib/new_relic/agent/span_event_primitive.rb +206 -0
- data/lib/new_relic/agent/sql_sampler.rb +23 -7
- data/lib/new_relic/agent/stats.rb +1 -1
- data/lib/new_relic/agent/stats_engine.rb +4 -4
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
- data/lib/new_relic/agent/supported_versions.rb +3 -3
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -13
- data/lib/new_relic/agent/system_info.rb +18 -8
- data/lib/new_relic/agent/threading/agent_thread.rb +6 -4
- data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_service.rb +4 -4
- data/lib/new_relic/agent/threading/thread_profile.rb +10 -24
- data/lib/new_relic/agent/timestamp_sampled_buffer.rb +19 -0
- data/lib/new_relic/agent/tracer.rb +509 -0
- data/lib/new_relic/agent/transaction.rb +191 -278
- data/lib/new_relic/agent/transaction/abstract_segment.rb +38 -5
- data/lib/new_relic/agent/transaction/datastore_segment.rb +30 -5
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +123 -71
- data/lib/new_relic/agent/transaction/external_request_segment.rb +41 -89
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +7 -8
- data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
- data/lib/new_relic/agent/transaction/segment.rb +42 -2
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/trace.rb +7 -23
- data/lib/new_relic/agent/transaction/trace_builder.rb +1 -2
- data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +12 -8
- data/lib/new_relic/agent/transaction/tracing.rb +2 -100
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction_error_primitive.rb +13 -22
- data/lib/new_relic/agent/transaction_event_aggregator.rb +7 -16
- data/lib/new_relic/agent/transaction_event_primitive.rb +31 -42
- data/lib/new_relic/agent/transaction_event_recorder.rb +8 -16
- data/lib/new_relic/agent/transaction_metrics.rb +1 -1
- data/lib/new_relic/agent/transaction_sampler.rb +3 -14
- data/lib/new_relic/agent/transaction_time_aggregator.rb +155 -0
- data/lib/new_relic/agent/utilization/aws.rb +1 -1
- data/lib/new_relic/agent/utilization/azure.rb +1 -1
- data/lib/new_relic/agent/utilization/gcp.rb +1 -1
- data/lib/new_relic/agent/utilization/pcf.rb +1 -1
- data/lib/new_relic/agent/utilization/vendor.rb +1 -1
- data/lib/new_relic/agent/utilization_data.rb +37 -2
- data/lib/new_relic/agent/vm.rb +1 -1
- data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
- data/lib/new_relic/agent/vm/mri_vm.rb +1 -1
- data/lib/new_relic/agent/vm/snapshot.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/cli/command.rb +1 -1
- data/lib/new_relic/cli/commands/deployments.rb +2 -2
- data/lib/new_relic/cli/commands/install.rb +4 -3
- data/lib/new_relic/coerce.rb +32 -7
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/constants.rb +38 -0
- data/lib/new_relic/control.rb +1 -1
- data/lib/new_relic/control/class_methods.rb +8 -2
- data/lib/new_relic/control/frameworks.rb +1 -1
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/merb.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +1 -1
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/control/frameworks/rails4.rb +1 -1
- data/lib/new_relic/control/frameworks/{rails5.rb → rails_notifications.rb} +2 -2
- data/lib/new_relic/control/frameworks/ruby.rb +1 -1
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +30 -4
- data/lib/new_relic/control/instrumentation.rb +1 -1
- data/lib/new_relic/control/server_methods.rb +1 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/dependency_detection.rb +5 -5
- data/lib/new_relic/environment_report.rb +6 -2
- data/lib/new_relic/helper.rb +1 -1
- data/lib/new_relic/language_support.rb +1 -1
- data/lib/new_relic/latest_changes.rb +4 -4
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/metric_spec.rb +1 -1
- data/lib/new_relic/noticed_error.rb +39 -18
- data/lib/new_relic/rack.rb +1 -1
- data/lib/new_relic/rack/agent_hooks.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +2 -2
- data/lib/new_relic/rack/browser_monitoring.rb +16 -9
- data/lib/new_relic/recipes.rb +1 -1
- data/lib/new_relic/recipes/capistrano3.rb +6 -3
- data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
- data/lib/new_relic/supportability_helper.rb +15 -1
- data/lib/new_relic/version.rb +4 -4
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +3 -3
- data/lib/sequel/plugins/newrelic_instrumentation.rb +2 -2
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/config.rake +1 -2
- data/lib/tasks/multiverse.rb +35 -1
- data/lib/tasks/newrelic.rb +1 -1
- data/lib/tasks/tests.rake +6 -1
- data/newrelic_rpm.gemspec +23 -17
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +357 -78
- metadata +154 -60
- data/.travis.yml +0 -173
- data/lib/new_relic/agent/busy_calculator.rb +0 -117
- data/lib/new_relic/agent/commands/xray_session.rb +0 -55
- data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
- data/lib/new_relic/agent/cross_app_monitor.rb +0 -140
- data/lib/new_relic/agent/cross_app_tracing.rb +0 -143
- data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -29
- data/lib/new_relic/agent/distributed_trace_payload.rb +0 -223
- data/lib/new_relic/agent/distributed_trace_priority_sampled_buffer.rb +0 -72
- data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
- data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
- data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -36
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
- data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
- data/lib/new_relic/agent/sampled_buffer.rb +0 -68
- data/lib/new_relic/agent/sized_buffer.rb +0 -23
- data/lib/new_relic/agent/synthetics_event_buffer.rb +0 -40
- data/lib/new_relic/agent/throughput_monitor.rb +0 -59
- data/lib/new_relic/agent/transaction/attributes.rb +0 -153
- data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
- data/lib/new_relic/agent/transaction_state.rb +0 -145
- data/lib/new_relic/agent/transaction_timings.rb +0 -57
- data/lib/new_relic/metrics.rb +0 -13
- data/lib/tasks/versions.html.erb +0 -28
- data/lib/tasks/versions.postface.html +0 -8
- data/lib/tasks/versions.preface.html +0 -9
- data/lib/tasks/versions.rake +0 -65
- data/lib/tasks/versions.txt.erb +0 -14
data/lib/new_relic/rack.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# @api public
|
6
6
|
module NewRelic
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'new_relic/agent/event_listener'
|
6
6
|
require 'new_relic/rack/agent_middleware'
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
|
-
require 'new_relic/agent/
|
5
|
+
require 'new_relic/agent/tracer'
|
6
6
|
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
7
7
|
require 'new_relic/agent/instrumentation/middleware_tracing'
|
8
8
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'rack'
|
6
6
|
require 'new_relic/rack/agent_middleware'
|
@@ -21,6 +21,7 @@ module NewRelic::Rack
|
|
21
21
|
|
22
22
|
CONTENT_TYPE = 'Content-Type'.freeze
|
23
23
|
CONTENT_DISPOSITION = 'Content-Disposition'.freeze
|
24
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
24
25
|
ATTACHMENT = 'attachment'.freeze
|
25
26
|
TEXT_HTML = 'text/html'.freeze
|
26
27
|
|
@@ -29,15 +30,20 @@ module NewRelic::Rack
|
|
29
30
|
GT = ">".freeze
|
30
31
|
|
31
32
|
def traced_call(env)
|
32
|
-
result = @app.call(env)
|
33
|
+
result = @app.call(env)
|
34
|
+
(status, headers, response) = result
|
33
35
|
|
34
36
|
js_to_inject = NewRelic::Agent.browser_timing_header
|
35
|
-
if (js_to_inject != "") && should_instrument?(env,
|
36
|
-
response_string = autoinstrument_source(
|
37
|
+
if (js_to_inject != "") && should_instrument?(env, status, headers)
|
38
|
+
response_string = autoinstrument_source(response, headers, js_to_inject)
|
39
|
+
if headers.key?(CONTENT_LENGTH)
|
40
|
+
content_length = response_string ? response_string.bytesize : 0
|
41
|
+
headers[CONTENT_LENGTH] = content_length.to_s
|
42
|
+
end
|
37
43
|
|
38
44
|
env[ALREADY_INSTRUMENTED_KEY] = true
|
39
45
|
if response_string
|
40
|
-
response = Rack::Response.new(response_string,
|
46
|
+
response = Rack::Response.new(response_string, status, headers)
|
41
47
|
response.finish
|
42
48
|
else
|
43
49
|
result
|
@@ -55,7 +61,7 @@ module NewRelic::Rack
|
|
55
61
|
!env[ALREADY_INSTRUMENTED_KEY] &&
|
56
62
|
is_html?(headers) &&
|
57
63
|
!is_attachment?(headers) &&
|
58
|
-
!is_streaming?(env)
|
64
|
+
!is_streaming?(env, headers)
|
59
65
|
end
|
60
66
|
|
61
67
|
def is_html?(headers)
|
@@ -66,10 +72,11 @@ module NewRelic::Rack
|
|
66
72
|
headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
|
67
73
|
end
|
68
74
|
|
69
|
-
def is_streaming?(env)
|
70
|
-
return
|
75
|
+
def is_streaming?(env, headers)
|
76
|
+
return true if headers && headers['Transfer-Encoding'] == 'chunked'
|
71
77
|
|
72
|
-
|
78
|
+
defined?(ActionController::Live) &&
|
79
|
+
env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
|
73
80
|
end
|
74
81
|
|
75
82
|
CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
|
data/lib/new_relic/recipes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# When installed as a plugin, this is loaded automatically.
|
6
6
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'capistrano/framework'
|
6
6
|
|
@@ -34,7 +34,10 @@ namespace :newrelic do
|
|
34
34
|
user = fetch(:newrelic_user)
|
35
35
|
license_key = fetch(:newrelic_license_key)
|
36
36
|
|
37
|
-
|
37
|
+
has_scm_from_plugin = respond_to?(:scm_plugin_installed?) && scm_plugin_installed?
|
38
|
+
has_scm_from_config = defined?(scm) && !scm.nil? && scm != :none
|
39
|
+
|
40
|
+
if has_scm_from_plugin || has_scm_from_config
|
38
41
|
changelog ||= lookup_changelog
|
39
42
|
rev ||= fetch(:current_revision)
|
40
43
|
end
|
@@ -69,7 +72,7 @@ namespace :newrelic do
|
|
69
72
|
|
70
73
|
debug "Retrieving changelog for New Relic Deployment details"
|
71
74
|
|
72
|
-
if
|
75
|
+
if Rake::Task.task_defined?("git:check")
|
73
76
|
log_command = "git --no-pager log --no-color --pretty=format:' * %an: %s' " +
|
74
77
|
"--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
|
75
78
|
`#{log_command}`
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
make_notify_task = Proc.new do
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
module NewRelic
|
6
6
|
module SupportabilityHelper
|
@@ -11,6 +11,8 @@ module NewRelic
|
|
11
11
|
# transaction, just to eke out a bit less performance hit
|
12
12
|
#
|
13
13
|
API_SUPPORTABILITY_METRICS = [
|
14
|
+
:accept_distributed_trace_headers,
|
15
|
+
:create_distributed_trace_headers,
|
14
16
|
:add_custom_attributes,
|
15
17
|
:add_instrumentation,
|
16
18
|
:add_method_tracer,
|
@@ -64,5 +66,17 @@ module NewRelic
|
|
64
66
|
NewRelic::Agent.logger.debug "API supportability metric not found for :#{method_name}"
|
65
67
|
end
|
66
68
|
end
|
69
|
+
|
70
|
+
def valid_api_argument_class? arg, name, klass
|
71
|
+
return true if arg.is_a?(klass)
|
72
|
+
|
73
|
+
caller_location = caller_locations.first.label
|
74
|
+
|
75
|
+
message = "Bad argument passed to ##{caller_location}. " \
|
76
|
+
"Expected #{klass} for `#{name}` but got #{headers.class}"
|
77
|
+
|
78
|
+
NewRelic::Agent.logger.warn message
|
79
|
+
nil
|
80
|
+
end
|
67
81
|
end
|
68
82
|
end
|
data/lib/new_relic/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
# This file is distributed under New Relic's license terms.
|
4
|
-
# See https://github.com/newrelic/
|
4
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
5
5
|
|
6
6
|
|
7
7
|
module NewRelic
|
@@ -10,9 +10,9 @@ module NewRelic
|
|
10
10
|
parts.compact.join('.')
|
11
11
|
end
|
12
12
|
|
13
|
-
MAJOR =
|
14
|
-
MINOR =
|
15
|
-
TINY =
|
13
|
+
MAJOR = 6
|
14
|
+
MINOR = 13
|
15
|
+
TINY = 1
|
16
16
|
|
17
17
|
begin
|
18
18
|
require File.join(File.dirname(__FILE__), 'build')
|
data/lib/newrelic_rpm.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# == New Relic Initialization
|
6
6
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# encoding: utf-8
|
3
3
|
# This file is distributed under New Relic's license terms.
|
4
|
-
# See https://github.com/newrelic/
|
4
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
5
5
|
|
6
6
|
require 'sequel' unless defined?( Sequel )
|
7
7
|
require 'newrelic_rpm' unless defined?( NewRelic )
|
@@ -47,7 +47,7 @@ module Sequel
|
|
47
47
|
|
48
48
|
product = NewRelic::Agent::Instrumentation::SequelHelper.product_name_from_adapter(self.class.adapter_scheme)
|
49
49
|
operation = NewRelic::Agent::Datastores::MetricHelper.operation_from_sql(sql)
|
50
|
-
segment = NewRelic::Agent::
|
50
|
+
segment = NewRelic::Agent::Tracer.start_datastore_segment(
|
51
51
|
product: product,
|
52
52
|
operation: operation
|
53
53
|
)
|
@@ -67,7 +67,7 @@ module Sequel
|
|
67
67
|
# statement, otherwise we would end up ovewriting the sql statement with the
|
68
68
|
# last one executed.
|
69
69
|
def notice_sql sql
|
70
|
-
return unless txn = NewRelic::Agent::
|
70
|
+
return unless txn = NewRelic::Agent::Tracer.current_transaction
|
71
71
|
|
72
72
|
current_segment = txn.current_segment
|
73
73
|
return unless current_segment.is_a?(NewRelic::Agent::Transaction::DatastoreSegment)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# encoding: utf-8
|
3
3
|
# This file is distributed under New Relic's license terms.
|
4
|
-
# See https://github.com/newrelic/
|
4
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
5
5
|
|
6
6
|
require 'sequel' unless defined?( Sequel )
|
7
7
|
require 'newrelic_rpm' unless defined?( NewRelic )
|
@@ -23,7 +23,7 @@ module Sequel
|
|
23
23
|
define_method(method_name) do |*args, &block|
|
24
24
|
klass = self.is_a?(Class) ? self : self.class
|
25
25
|
product = NewRelic::Agent::Instrumentation::SequelHelper.product_name_from_adapter(db.adapter_scheme)
|
26
|
-
segment = NewRelic::Agent::
|
26
|
+
segment = NewRelic::Agent::Tracer.start_datastore_segment(
|
27
27
|
product: product,
|
28
28
|
operation: operation_name,
|
29
29
|
collection: klass.name
|
data/lib/tasks/all.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# This is required to load in task definitions from merb
|
6
6
|
Dir.glob(File.join(File.dirname(__FILE__),'*.rake')) do |file|
|
data/lib/tasks/config.rake
CHANGED
data/lib/tasks/multiverse.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
#
|
5
5
|
# Rake task for running Ruby agent multiverse tests. This file may be required
|
6
6
|
# from third party gems. It is also used by the agent itself to run multiverse.
|
@@ -43,11 +43,45 @@ namespace :test do
|
|
43
43
|
|
44
44
|
namespace :multiverse do
|
45
45
|
|
46
|
+
def remove_local_multiverse_databases
|
47
|
+
list_databases_command = %{echo "show databases" | mysql -u root}
|
48
|
+
databases = `#{list_databases_command}`.chomp!.split("\n").select{|s| s =~ /multiverse/}
|
49
|
+
databases.each do |database|
|
50
|
+
puts "Dropping #{database}"
|
51
|
+
`echo "drop database #{database}" | mysql -u root`
|
52
|
+
end
|
53
|
+
rescue => error
|
54
|
+
puts "ERROR: Cannot get MySQL databases..."
|
55
|
+
puts error.message
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_generated_gemfiles
|
59
|
+
file_path = File.expand_path "test/multiverse/suites"
|
60
|
+
Dir.glob(File.join file_path, "**", "Gemfile*").each do |fn|
|
61
|
+
puts "Removing #{fn.gsub(file_path,'.../suites')}"
|
62
|
+
FileUtils.rm fn
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_generated_gemfile_lockfiles
|
67
|
+
file_path = File.expand_path "test/environments"
|
68
|
+
Dir.glob(File.join file_path, "**", "Gemfile.lock").each do |fn|
|
69
|
+
puts "Removing #{fn.gsub(file_path,'.../environments')}"
|
70
|
+
FileUtils.rm fn
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
46
74
|
task :env do
|
47
75
|
# ENV['SUITES_DIRECTORY'] = File.expand_path('../../test/multiverse/suites', __FILE__)
|
48
76
|
require File.expand_path('../../../test/multiverse/lib/multiverse', __FILE__)
|
49
77
|
end
|
50
78
|
|
79
|
+
task :clobber do
|
80
|
+
remove_local_multiverse_databases
|
81
|
+
remove_generated_gemfiles
|
82
|
+
remove_generated_gemfile_lockfiles
|
83
|
+
end
|
84
|
+
|
51
85
|
desc "Clean cached gemfiles from Bundler.bundle_path"
|
52
86
|
task :clean_gemfile_cache do
|
53
87
|
glob = File.expand_path 'multiverse-cache/Gemfile.*.lock', Bundler.bundle_path
|
data/lib/tasks/newrelic.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
#
|
5
5
|
# If you are looking to instrument rake tasks in a Rails environment, but the
|
6
6
|
# task doesn't depend on :environment, this task may be included to ensure that
|
data/lib/tasks/tests.rake
CHANGED
@@ -26,9 +26,14 @@ if defined? Rake::TestTask
|
|
26
26
|
agent_home = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
|
27
27
|
|
28
28
|
Rake::TestTask.new(:newrelic) do |t|
|
29
|
+
|
30
|
+
file_pattern = ENV["file"]
|
31
|
+
file_pattern = file_pattern.split(",").map{|f| "#{agent_home}/#{f}".gsub("//", "/")} if file_pattern
|
32
|
+
file_pattern ||= "#{agent_home}/test/new_relic/**/*_test.rb"
|
33
|
+
|
29
34
|
t.libs << "#{agent_home}/test"
|
30
35
|
t.libs << "#{agent_home}/lib"
|
31
|
-
t.pattern =
|
36
|
+
t.pattern = Array(file_pattern)
|
32
37
|
t.verbose = true
|
33
38
|
end
|
34
39
|
|
data/newrelic_rpm.gemspec
CHANGED
@@ -10,16 +10,16 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.version = NewRelic::VERSION::STRING
|
11
11
|
s.required_ruby_version = '>= 2.0.0'
|
12
12
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
13
|
-
s.authors = [ "
|
13
|
+
s.authors = [ "Rachel Klein", "Tanna McClure", "Michael Lang" ]
|
14
14
|
s.date = Time.now.strftime('%Y-%m-%d')
|
15
|
-
s.licenses = ['
|
15
|
+
s.licenses = ['Apache-2.0']
|
16
16
|
s.description = <<-EOS
|
17
17
|
New Relic is a performance management system, developed by New Relic,
|
18
18
|
Inc (http://www.newrelic.com). New Relic provides you with deep
|
19
19
|
information about the performance of your web application as it runs
|
20
|
-
in production. The New Relic Ruby
|
20
|
+
in production. The New Relic Ruby agent is dual-purposed as a either a
|
21
21
|
Gem or plugin, hosted on
|
22
|
-
https://github.com/newrelic/
|
22
|
+
https://github.com/newrelic/newrelic-ruby-agent/
|
23
23
|
EOS
|
24
24
|
s.email = "support@newrelic.com"
|
25
25
|
s.executables = [ "mongrel_rpm", "newrelic_cmd", "newrelic", "nrdebug" ]
|
@@ -31,7 +31,15 @@ EOS
|
|
31
31
|
"newrelic.yml"
|
32
32
|
]
|
33
33
|
|
34
|
-
|
34
|
+
s.metadata = {
|
35
|
+
'bug_tracker_uri' => 'https://github.com/newrelic/newrelic-ruby-agent/issues',
|
36
|
+
'changelog_uri' => 'https://github.com/newrelic/newrelic-ruby-agent/blob/main/CHANGELOG.md',
|
37
|
+
'documentation_uri' => 'https://docs.newrelic.com/docs/agents/ruby-agent',
|
38
|
+
'source_code_uri' => 'https://github.com/newrelic/newrelic-ruby-agent',
|
39
|
+
"homepage_uri" => "https://newrelic.com/ruby",
|
40
|
+
}
|
41
|
+
|
42
|
+
file_list = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|infinite_tracing)/(?!agent_helper.rb)}) }
|
35
43
|
build_file_path = 'lib/new_relic/build.rb'
|
36
44
|
file_list << build_file_path if File.exist?(build_file_path)
|
37
45
|
s.files = file_list
|
@@ -41,18 +49,16 @@ EOS
|
|
41
49
|
s.rubygems_version = Gem::VERSION
|
42
50
|
s.summary = "New Relic Ruby Agent"
|
43
51
|
|
44
|
-
s.add_development_dependency 'rake', '
|
45
|
-
s.add_development_dependency '
|
46
|
-
s.add_development_dependency '
|
52
|
+
s.add_development_dependency 'rake', '12.3.3'
|
53
|
+
s.add_development_dependency 'rb-inotify', '0.9.10' # locked to support < Ruby 2.3 (and listen 3.0.8)
|
54
|
+
s.add_development_dependency 'listen', '3.0.8' # locked to support < Ruby 2.3
|
55
|
+
s.add_development_dependency 'minitest', '4.7.5'
|
56
|
+
s.add_development_dependency 'mocha', '~> 1.9.0'
|
47
57
|
s.add_development_dependency 'yard'
|
48
|
-
s.add_development_dependency '
|
49
|
-
s.add_development_dependency '
|
50
|
-
s.add_development_dependency '
|
58
|
+
s.add_development_dependency 'pry-nav', '~> 0.3.0'
|
59
|
+
s.add_development_dependency 'pry-stack_explorer', '~> 0.4.9'
|
60
|
+
s.add_development_dependency 'guard', '~> 2.16.0'
|
61
|
+
s.add_development_dependency 'guard-minitest', '~> 2.4.0'
|
51
62
|
s.add_development_dependency 'hometown', '~> 0.2.5'
|
52
|
-
|
53
|
-
if RUBY_PLATFORM == 'java'
|
54
|
-
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
|
55
|
-
else
|
56
|
-
s.add_development_dependency 'sqlite3'
|
57
|
-
end
|
63
|
+
s.add_development_dependency 'bundler'
|
58
64
|
end
|
data/recipes/newrelic.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# The capistrano recipes in plugins are automatically
|
6
6
|
# loaded from here. From gems, they are available from
|
data/test/agent_helper.rb
CHANGED
@@ -1,30 +1,61 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# These helpers should not have any gem dependencies except on newrelic_rpm
|
6
6
|
# itself, and should be usable from within any multiverse suite.
|
7
7
|
|
8
8
|
require 'json'
|
9
|
+
require 'net/http'
|
10
|
+
begin
|
11
|
+
require 'net/http/status'
|
12
|
+
rescue LoadError
|
13
|
+
# NOP -- Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
14
|
+
end
|
15
|
+
|
16
|
+
module MiniTest
|
17
|
+
module Assertions
|
18
|
+
# The failure message is backwards. This patch reverses the message
|
19
|
+
# Note: passing +msg+ caused two failure messages to be shown on failure
|
20
|
+
# and was more confusing than patching here.
|
21
|
+
def assert_match matcher, obj, msg = nil
|
22
|
+
msg = message(msg) { "Expected #{mu_pp obj} to match #{mu_pp matcher}" }
|
23
|
+
assert_respond_to matcher, :"=~"
|
24
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
25
|
+
assert matcher =~ obj, msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
9
29
|
|
10
30
|
class ArrayLogDevice
|
11
|
-
def initialize
|
31
|
+
def initialize array=[]
|
12
32
|
@array = array
|
13
33
|
end
|
14
34
|
attr_reader :array
|
15
35
|
|
16
|
-
def write
|
36
|
+
def write message
|
17
37
|
@array << message
|
18
38
|
end
|
19
39
|
|
20
40
|
def close; end
|
21
41
|
end
|
22
42
|
|
23
|
-
def
|
43
|
+
def fake_guid length=16
|
44
|
+
NewRelic::Agent::GuidGenerator.generate_guid length
|
45
|
+
end
|
46
|
+
|
47
|
+
def assert_match matcher, obj, msg = nil
|
48
|
+
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
49
|
+
assert_respond_to matcher, :"=~"
|
50
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
51
|
+
assert matcher =~ obj, msg
|
52
|
+
end
|
53
|
+
|
54
|
+
def assert_between floor, ceiling, value, message="expected #{floor} <= #{value} <= #{ceiling}"
|
24
55
|
assert((floor <= value && value <= ceiling), message)
|
25
56
|
end
|
26
57
|
|
27
|
-
def assert_in_delta
|
58
|
+
def assert_in_delta expected, actual, delta
|
28
59
|
assert_between((expected - delta), (expected + delta), actual)
|
29
60
|
end
|
30
61
|
|
@@ -36,7 +67,7 @@ def reset_error_traces!
|
|
36
67
|
NewRelic::Agent.instance.error_collector.error_trace_aggregator.reset!
|
37
68
|
end
|
38
69
|
|
39
|
-
def assert_has_traced_error
|
70
|
+
def assert_has_traced_error error_class
|
40
71
|
errors = harvest_error_traces!
|
41
72
|
assert \
|
42
73
|
errors.find {|e| e.exception_class_name == error_class.name} != nil, \
|
@@ -55,6 +86,14 @@ def last_transaction_event
|
|
55
86
|
harvest_transaction_events!.last.last
|
56
87
|
end
|
57
88
|
|
89
|
+
def harvest_span_events!
|
90
|
+
NewRelic::Agent.instance.span_event_aggregator.harvest!
|
91
|
+
end
|
92
|
+
|
93
|
+
def last_span_event
|
94
|
+
harvest_span_events!.last.last
|
95
|
+
end
|
96
|
+
|
58
97
|
def harvest_error_events!
|
59
98
|
NewRelic::Agent.instance.error_collector.error_event_aggregator.harvest!
|
60
99
|
end
|
@@ -63,38 +102,44 @@ def last_error_event
|
|
63
102
|
harvest_error_events!.last.last
|
64
103
|
end
|
65
104
|
|
66
|
-
unless defined?
|
67
|
-
def assert_block
|
105
|
+
unless defined? assert_block
|
106
|
+
def assert_block *msgs
|
68
107
|
assert yield, *msgs
|
69
108
|
end
|
70
109
|
end
|
71
110
|
|
72
|
-
unless defined?
|
73
|
-
def assert_includes
|
111
|
+
unless defined? assert_includes
|
112
|
+
def assert_includes collection, member, msg=nil
|
74
113
|
msg = "Expected #{collection.inspect} to include #{member.inspect}"
|
75
114
|
assert_block( msg ) { collection.include?(member) }
|
76
115
|
end
|
77
116
|
end
|
78
117
|
|
79
|
-
unless defined?
|
80
|
-
def assert_not_includes
|
118
|
+
unless defined? assert_not_includes
|
119
|
+
def assert_not_includes collection, member, msg=nil
|
81
120
|
msg = "Expected #{collection.inspect} not to include #{member.inspect}"
|
82
121
|
assert !collection.include?(member), msg
|
83
122
|
end
|
84
123
|
end
|
85
124
|
|
86
|
-
unless defined?
|
87
|
-
def assert_empty
|
125
|
+
unless defined? assert_empty
|
126
|
+
def assert_empty collection, msg=nil
|
88
127
|
assert collection.empty?, msg
|
89
128
|
end
|
90
129
|
end
|
91
130
|
|
92
|
-
def assert_equal_unordered
|
131
|
+
def assert_equal_unordered left, right
|
93
132
|
assert_equal(left.length, right.length, "Lengths don't match. #{left.length} != #{right.length}")
|
94
133
|
left.each { |element| assert_includes(right, element) }
|
95
134
|
end
|
96
135
|
|
97
|
-
def
|
136
|
+
def assert_log_contains(log, message)
|
137
|
+
lines = log.array
|
138
|
+
failure_message = "Did not find '#{message}' in log. Log contained:\n#{lines.join('')}"
|
139
|
+
assert (lines.any? { |line| line.match(message) }), failure_message
|
140
|
+
end
|
141
|
+
|
142
|
+
def assert_audit_log_contains audit_log_contents, needle
|
98
143
|
# Original request bodies dumped to the log have symbol keys, but once
|
99
144
|
# they go through a dump/load, they're strings again, so we strip
|
100
145
|
# double-quotes and colons from the log, and the strings we searching for.
|
@@ -112,7 +157,7 @@ end
|
|
112
157
|
# orderings of the key/value pairs in Hashes that were embedded in the request
|
113
158
|
# body). So, this method traverses an object graph and only makes assertions
|
114
159
|
# about the terminal (non-Array-or-Hash) nodes therein.
|
115
|
-
def assert_audit_log_contains_object
|
160
|
+
def assert_audit_log_contains_object audit_log_contents, o, format = :json
|
116
161
|
case o
|
117
162
|
when Hash
|
118
163
|
o.each do |k,v|
|
@@ -130,12 +175,12 @@ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
|
|
130
175
|
end
|
131
176
|
end
|
132
177
|
|
133
|
-
def compare_metrics
|
178
|
+
def compare_metrics expected, actual
|
134
179
|
actual.delete_if {|a| a.include?('GC/Transaction/') }
|
135
180
|
assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
|
136
181
|
end
|
137
182
|
|
138
|
-
def metric_spec_from_specish
|
183
|
+
def metric_spec_from_specish specish
|
139
184
|
spec = case specish
|
140
185
|
when String then NewRelic::MetricSpec.new(specish)
|
141
186
|
when Array then NewRelic::MetricSpec.new(*specish)
|
@@ -143,7 +188,7 @@ def metric_spec_from_specish(specish)
|
|
143
188
|
spec
|
144
189
|
end
|
145
190
|
|
146
|
-
def _normalize_metric_expectations
|
191
|
+
def _normalize_metric_expectations expectations
|
147
192
|
case expectations
|
148
193
|
when Array
|
149
194
|
hash = {}
|
@@ -157,7 +202,7 @@ def _normalize_metric_expectations(expectations)
|
|
157
202
|
end
|
158
203
|
end
|
159
204
|
|
160
|
-
def dump_stats
|
205
|
+
def dump_stats stats
|
161
206
|
str = " Call count: #{stats.call_count}\n"
|
162
207
|
str << " Total call time: #{stats.total_call_time}\n"
|
163
208
|
str << " Total exclusive time: #{stats.total_exclusive_time}\n"
|
@@ -170,7 +215,7 @@ def dump_stats(stats)
|
|
170
215
|
str
|
171
216
|
end
|
172
217
|
|
173
|
-
def assert_stats_has_values
|
218
|
+
def assert_stats_has_values stats, expected_spec, expected_attrs
|
174
219
|
expected_attrs.each do |attr, expected_value|
|
175
220
|
actual_value = stats.send(attr)
|
176
221
|
if attr == :call_count
|
@@ -183,7 +228,7 @@ def assert_stats_has_values(stats, expected_spec, expected_attrs)
|
|
183
228
|
end
|
184
229
|
end
|
185
230
|
|
186
|
-
def assert_metrics_recorded
|
231
|
+
def assert_metrics_recorded expected
|
187
232
|
expected = _normalize_metric_expectations(expected)
|
188
233
|
expected.each do |specish, expected_attrs|
|
189
234
|
expected_spec = metric_spec_from_specish(specish)
|
@@ -212,9 +257,9 @@ end
|
|
212
257
|
#
|
213
258
|
# If you want to *allow* unexpected metrics matching certain patterns, use
|
214
259
|
# the :ignore_filter option. This will allow you to specify a Regex that
|
215
|
-
#
|
260
|
+
# allowlists broad swathes of metric territory (e.g. 'Supportability/').
|
216
261
|
#
|
217
|
-
def assert_metrics_recorded_exclusive
|
262
|
+
def assert_metrics_recorded_exclusive expected, options={}
|
218
263
|
expected = _normalize_metric_expectations(expected)
|
219
264
|
assert_metrics_recorded(expected)
|
220
265
|
|
@@ -252,7 +297,7 @@ def clear_metrics!
|
|
252
297
|
NewRelic::Agent.instance.stats_engine.reset_for_test!
|
253
298
|
end
|
254
299
|
|
255
|
-
def assert_metrics_not_recorded
|
300
|
+
def assert_metrics_not_recorded not_expected
|
256
301
|
not_expected = _normalize_metric_expectations(not_expected)
|
257
302
|
found_but_not_expected = []
|
258
303
|
not_expected.each do |specish, _|
|
@@ -266,7 +311,7 @@ end
|
|
266
311
|
|
267
312
|
alias :refute_metrics_recorded :assert_metrics_not_recorded
|
268
313
|
|
269
|
-
def assert_no_metrics_match
|
314
|
+
def assert_no_metrics_match regex
|
270
315
|
matching_metrics = []
|
271
316
|
NewRelic::Agent.instance.stats_engine.to_h.keys.map(&:to_s).each do |metric|
|
272
317
|
matching_metrics << metric if metric.match regex
|
@@ -281,30 +326,30 @@ end
|
|
281
326
|
|
282
327
|
alias :refute_metrics_match :assert_no_metrics_match
|
283
328
|
|
284
|
-
def format_metric_spec_list
|
329
|
+
def format_metric_spec_list specs
|
285
330
|
spec_strings = specs.map do |spec|
|
286
331
|
"#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
|
287
332
|
end
|
288
333
|
"[\n #{spec_strings.join(",\n ")}\n]"
|
289
334
|
end
|
290
335
|
|
291
|
-
def assert_truthy
|
336
|
+
def assert_truthy expected, msg=nil
|
292
337
|
msg ||= "Expected #{expected.inspect} to be truthy"
|
293
338
|
assert !!expected, msg
|
294
339
|
end
|
295
340
|
|
296
|
-
def assert_falsy
|
341
|
+
def assert_falsy expected, msg=nil
|
297
342
|
msg ||= "Expected #{expected.inspect} to be falsy"
|
298
343
|
assert !expected, msg
|
299
344
|
end
|
300
345
|
|
301
|
-
unless defined?
|
302
|
-
def assert_false
|
346
|
+
unless defined? assert_false
|
347
|
+
def assert_false expected
|
303
348
|
assert_equal false, expected
|
304
349
|
end
|
305
350
|
end
|
306
351
|
|
307
|
-
unless defined?
|
352
|
+
unless defined? refute
|
308
353
|
alias refute assert_false
|
309
354
|
end
|
310
355
|
|
@@ -326,7 +371,7 @@ end
|
|
326
371
|
# With a transaction name plus category:
|
327
372
|
# in_transaction('foobar', :category => :controller) { ... }
|
328
373
|
#
|
329
|
-
def in_transaction
|
374
|
+
def in_transaction *args, &blk
|
330
375
|
opts = (args.last && args.last.is_a?(Hash)) ? args.pop : {}
|
331
376
|
category = (opts && opts.delete(:category)) || :other
|
332
377
|
|
@@ -334,10 +379,10 @@ def in_transaction(*args, &blk)
|
|
334
379
|
name = opts.key?(:transaction_name) ? opts.delete(:transaction_name) :
|
335
380
|
args.first || 'dummy'
|
336
381
|
|
337
|
-
state = NewRelic::Agent::
|
382
|
+
state = NewRelic::Agent::Tracer.state
|
338
383
|
txn = nil
|
339
384
|
|
340
|
-
NewRelic::Agent::
|
385
|
+
NewRelic::Agent::Tracer.in_transaction(name: name, category: category, options: opts) do
|
341
386
|
txn = state.current_transaction
|
342
387
|
yield state.current_transaction
|
343
388
|
end
|
@@ -345,25 +390,70 @@ def in_transaction(*args, &blk)
|
|
345
390
|
txn
|
346
391
|
end
|
347
392
|
|
348
|
-
|
393
|
+
# Temporarily disables default transformer so tests with invalid inputs can be tried
|
394
|
+
def with_disabled_defaults_transformer key
|
395
|
+
begin
|
396
|
+
transformer = NewRelic::Agent::Configuration::DEFAULTS[key][:transform]
|
397
|
+
NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = nil
|
398
|
+
yield
|
399
|
+
ensure
|
400
|
+
NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = transformer
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
# Convenience wrapper to stand up a transaction and provide a segment within
|
405
|
+
# that transaction to work with. The same arguements as provided to in_transaction
|
406
|
+
# may be supplied.
|
407
|
+
def with_segment *args, &blk
|
408
|
+
segment = nil
|
409
|
+
txn = in_transaction(*args) do |txn|
|
410
|
+
segment = txn.current_segment
|
411
|
+
yield segment, txn
|
412
|
+
end
|
413
|
+
[segment, txn]
|
414
|
+
end
|
415
|
+
|
416
|
+
# building error attributes on segments are deferred until it's time
|
417
|
+
# to publish/harvest them as spans, so for testing, we'll explicitly
|
418
|
+
# build 'em as appropriate so we can test 'em
|
419
|
+
def build_deferred_error_attributes segment
|
420
|
+
return unless segment.noticed_error
|
421
|
+
segment.noticed_error.build_error_attributes
|
422
|
+
end
|
423
|
+
|
424
|
+
def capture_segment_with_error
|
425
|
+
begin
|
426
|
+
segment_with_error = nil
|
427
|
+
with_segment do |segment|
|
428
|
+
segment_with_error = segment
|
429
|
+
raise "oops!"
|
430
|
+
end
|
431
|
+
rescue Exception => exception
|
432
|
+
assert segment_with_error, "expected to have a segment_with_error"
|
433
|
+
build_deferred_error_attributes segment_with_error
|
434
|
+
return segment_with_error, exception
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
def stub_transaction_guid guid
|
349
439
|
NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
|
350
440
|
end
|
351
441
|
|
352
442
|
# Convenience wrapper around in_transaction that sets the category so that it
|
353
443
|
# looks like we are in a web transaction
|
354
|
-
def in_web_transaction
|
444
|
+
def in_web_transaction name='dummy'
|
355
445
|
in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
|
356
446
|
yield txn
|
357
447
|
end
|
358
448
|
end
|
359
449
|
|
360
|
-
def in_background_transaction
|
450
|
+
def in_background_transaction name='silly'
|
361
451
|
in_transaction(name, :category => :task) do |txn|
|
362
452
|
yield txn
|
363
453
|
end
|
364
454
|
end
|
365
455
|
|
366
|
-
def refute_contains_request_params
|
456
|
+
def refute_contains_request_params attributes
|
367
457
|
attributes.keys.each do |key|
|
368
458
|
refute_match(/^request\.parameters\./, key.to_s)
|
369
459
|
end
|
@@ -382,7 +472,7 @@ def last_transaction_trace_request_params
|
|
382
472
|
end
|
383
473
|
end
|
384
474
|
|
385
|
-
def find_sql_trace
|
475
|
+
def find_sql_trace metric_name
|
386
476
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
|
387
477
|
trace.database_metric_name == metric_name
|
388
478
|
end
|
@@ -392,7 +482,7 @@ def last_sql_trace
|
|
392
482
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
|
393
483
|
end
|
394
484
|
|
395
|
-
def find_last_transaction_node
|
485
|
+
def find_last_transaction_node transaction_sample=nil
|
396
486
|
if transaction_sample
|
397
487
|
root_node = transaction_sample.root_node
|
398
488
|
else
|
@@ -405,7 +495,7 @@ def find_last_transaction_node(transaction_sample=nil)
|
|
405
495
|
return last_node
|
406
496
|
end
|
407
497
|
|
408
|
-
def find_node_with_name
|
498
|
+
def find_node_with_name transaction_sample, name
|
409
499
|
transaction_sample.root_node.each_node do |node|
|
410
500
|
if node.metric_name == name
|
411
501
|
return node
|
@@ -415,7 +505,7 @@ def find_node_with_name(transaction_sample, name)
|
|
415
505
|
nil
|
416
506
|
end
|
417
507
|
|
418
|
-
def find_node_with_name_matching
|
508
|
+
def find_node_with_name_matching transaction_sample, regex
|
419
509
|
transaction_sample.root_node.each_node do |node|
|
420
510
|
if node.metric_name.match regex
|
421
511
|
return node
|
@@ -425,7 +515,7 @@ def find_node_with_name_matching(transaction_sample, regex)
|
|
425
515
|
nil
|
426
516
|
end
|
427
517
|
|
428
|
-
def find_all_nodes_with_name_matching
|
518
|
+
def find_all_nodes_with_name_matching transaction_sample, regexes
|
429
519
|
regexes = [regexes].flatten
|
430
520
|
matching_nodes = []
|
431
521
|
|
@@ -440,7 +530,7 @@ def find_all_nodes_with_name_matching(transaction_sample, regexes)
|
|
440
530
|
matching_nodes
|
441
531
|
end
|
442
532
|
|
443
|
-
def with_config
|
533
|
+
def with_config config_hash, at_start=true
|
444
534
|
config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
|
445
535
|
NewRelic::Agent.config.add_config_for_testing(config, at_start)
|
446
536
|
NewRelic::Agent.instance.refresh_attribute_filter
|
@@ -452,13 +542,20 @@ def with_config(config_hash, at_start=true)
|
|
452
542
|
end
|
453
543
|
end
|
454
544
|
|
455
|
-
def
|
545
|
+
def with_server_source config_hash, at_start=true
|
546
|
+
with_config config_hash, at_start do
|
547
|
+
NewRelic::Agent.config.notify_server_source_added
|
548
|
+
yield
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
def with_config_low_priority config_hash
|
456
553
|
with_config(config_hash, false) do
|
457
554
|
yield
|
458
555
|
end
|
459
556
|
end
|
460
557
|
|
461
|
-
def with_transaction_renaming_rules
|
558
|
+
def with_transaction_renaming_rules rule_specs
|
462
559
|
original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
|
463
560
|
begin
|
464
561
|
new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
|
@@ -484,7 +581,7 @@ unless Time.respond_to?(:__original_now)
|
|
484
581
|
end
|
485
582
|
end
|
486
583
|
|
487
|
-
def nr_freeze_time
|
584
|
+
def nr_freeze_time now=Time.now
|
488
585
|
Time.__frozen_now = now
|
489
586
|
end
|
490
587
|
|
@@ -492,11 +589,11 @@ def nr_unfreeze_time
|
|
492
589
|
Time.__frozen_now = nil
|
493
590
|
end
|
494
591
|
|
495
|
-
def advance_time
|
592
|
+
def advance_time seconds
|
496
593
|
Time.__frozen_now = Time.now + seconds
|
497
594
|
end
|
498
595
|
|
499
|
-
def with_constant_defined
|
596
|
+
def with_constant_defined constant_symbol, implementation=Module.new
|
500
597
|
const_path = constant_path(constant_symbol.to_s)
|
501
598
|
|
502
599
|
if const_path
|
@@ -516,12 +613,12 @@ def with_constant_defined(constant_symbol, implementation=Module.new)
|
|
516
613
|
end
|
517
614
|
end
|
518
615
|
|
519
|
-
def constant_path
|
616
|
+
def constant_path name, opts={}
|
520
617
|
allow_partial = opts[:allow_partial]
|
521
618
|
path = [Object]
|
522
619
|
parts = name.gsub(/^::/, '').split('::')
|
523
620
|
parts.each do |part|
|
524
|
-
if !path.last.
|
621
|
+
if !path.last.constants.include?(part.to_sym)
|
525
622
|
return allow_partial ? path : nil
|
526
623
|
end
|
527
624
|
path << path.last.const_get(part)
|
@@ -529,11 +626,17 @@ def constant_path(name, opts={})
|
|
529
626
|
path
|
530
627
|
end
|
531
628
|
|
532
|
-
def
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
629
|
+
def get_parent constant_name
|
630
|
+
parent_name = constant_name.gsub(/::[^:]*$/, '')
|
631
|
+
const_path = constant_path(parent_name)
|
632
|
+
const_path ? const_path[-1] : nil
|
633
|
+
end
|
634
|
+
|
635
|
+
def undefine_constant constant_symbol
|
636
|
+
const_str = constant_symbol.to_s
|
637
|
+
parent = get_parent(const_str)
|
638
|
+
const_name = const_str.gsub(/.*::/, '')
|
639
|
+
return yield unless parent && parent.constants.include?(const_name.to_sym)
|
537
640
|
removed_constant = parent.send(:remove_const, const_name)
|
538
641
|
yield
|
539
642
|
ensure
|
@@ -553,11 +656,11 @@ ensure
|
|
553
656
|
NewRelic::Agent.logger = orig_logger
|
554
657
|
end
|
555
658
|
|
556
|
-
def create_agent_command
|
659
|
+
def create_agent_command args={}
|
557
660
|
NewRelic::Agent::Commands::AgentCommand.new([-1, { "name" => "command_name", "arguments" => args}])
|
558
661
|
end
|
559
662
|
|
560
|
-
def wait_for_backtrace_service_poll
|
663
|
+
def wait_for_backtrace_service_poll opts={}
|
561
664
|
defaults = {
|
562
665
|
:timeout => 10.0,
|
563
666
|
:service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
|
@@ -583,7 +686,7 @@ def wait_for_backtrace_service_poll(opts={})
|
|
583
686
|
end
|
584
687
|
end
|
585
688
|
|
586
|
-
def with_array_logger
|
689
|
+
def with_array_logger level=:info
|
587
690
|
orig_logger = NewRelic::Agent.logger
|
588
691
|
config = { :log_level => level }
|
589
692
|
logdev = ArrayLogDevice.new
|
@@ -599,20 +702,90 @@ ensure
|
|
599
702
|
NewRelic::Agent.logger = orig_logger
|
600
703
|
end
|
601
704
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
705
|
+
# The EnvUpdater was introduced due to random fails in JRuby environment
|
706
|
+
# whereby attempting to set ENV[key] = some_value randomly failed.
|
707
|
+
# It is conjectured that this is thread related, but may also be
|
708
|
+
# a core bug in the JVM implementation of Ruby. Root cause was not
|
709
|
+
# discovered, but it was found that a combination of retrying and using
|
710
|
+
# mutex lock around the update operation was the only consistently working
|
711
|
+
# solution as the error continued to surface without the mutex and
|
712
|
+
# retry alone wasn't enough, either.
|
713
|
+
#
|
714
|
+
# JRUBY: oraclejdk8 + jruby-9.2.6.0
|
715
|
+
#
|
716
|
+
# NOTE: Singleton pattern to ensure one mutex lock for all threads
|
717
|
+
class EnvUpdater
|
718
|
+
MAX_RETRIES = 5
|
719
|
+
|
720
|
+
def initialize
|
721
|
+
@mutex = Mutex.new
|
607
722
|
end
|
608
|
-
|
723
|
+
|
724
|
+
# Will attempt the given block up to MAX_RETRIES before
|
725
|
+
# surfacing the exception down the chain.
|
726
|
+
def with_retry retry_limit=MAX_RETRIES
|
727
|
+
retries ||= 0
|
728
|
+
sleep(retries)
|
609
729
|
yield
|
610
|
-
|
611
|
-
|
730
|
+
rescue
|
731
|
+
(retries += 1) < retry_limit ? retry : raise
|
732
|
+
end
|
733
|
+
|
734
|
+
# Locks and updates the ENV
|
735
|
+
def safe_update env
|
736
|
+
with_retry do
|
737
|
+
@mutex.synchronize do
|
738
|
+
env.each{ |key, val| ENV[key] = val.to_s }
|
739
|
+
end
|
740
|
+
end
|
741
|
+
end
|
742
|
+
|
743
|
+
# Locks and restores the ENV
|
744
|
+
def safe_restore old_env
|
745
|
+
with_retry do
|
746
|
+
@mutex.synchronize do
|
747
|
+
old_env.each{ |key, val| val ? ENV[key] = val : ENV.delete(key) }
|
748
|
+
end
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
# Singleton pattern implemented via @@instance
|
753
|
+
def self.instance
|
754
|
+
@@instance ||= EnvUpdater.new
|
755
|
+
end
|
756
|
+
|
757
|
+
def self.safe_update env
|
758
|
+
instance.safe_update env
|
612
759
|
end
|
760
|
+
|
761
|
+
def self.safe_restore old_env
|
762
|
+
instance.safe_restore old_env
|
763
|
+
end
|
764
|
+
|
765
|
+
# Effectively saves current ENV settings for given env's key/values,
|
766
|
+
# runs given block, then restores ENV to original state before returning.
|
767
|
+
def self.inject env, &block
|
768
|
+
old_env = {}
|
769
|
+
env.each{ |key, val| old_env[key] = ENV[key] }
|
770
|
+
begin
|
771
|
+
safe_update(env)
|
772
|
+
yield
|
773
|
+
ensure
|
774
|
+
safe_restore(old_env)
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
# must call instance here to ensure only one @mutex for all threads.
|
779
|
+
instance
|
780
|
+
end
|
781
|
+
|
782
|
+
# Changes ENV settings to given and runs given block and restores ENV
|
783
|
+
# to original values before returning.
|
784
|
+
def with_environment env, &block
|
785
|
+
EnvUpdater.inject(env) { yield }
|
613
786
|
end
|
614
787
|
|
615
|
-
def with_argv
|
788
|
+
def with_argv argv
|
616
789
|
old_argv = ARGV.dup
|
617
790
|
ARGV.clear
|
618
791
|
ARGV.concat(argv)
|
@@ -625,7 +798,7 @@ def with_argv(argv)
|
|
625
798
|
end
|
626
799
|
end
|
627
800
|
|
628
|
-
def with_ignore_error_filter
|
801
|
+
def with_ignore_error_filter filter, &blk
|
629
802
|
original_filter = NewRelic::Agent.ignore_error_filter
|
630
803
|
NewRelic::Agent.ignore_error_filter(&filter)
|
631
804
|
|
@@ -634,7 +807,7 @@ ensure
|
|
634
807
|
NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
|
635
808
|
end
|
636
809
|
|
637
|
-
def json_dump_and_encode
|
810
|
+
def json_dump_and_encode object
|
638
811
|
Base64.encode64(::JSON.dump(object))
|
639
812
|
end
|
640
813
|
|
@@ -642,7 +815,7 @@ def get_last_analytics_event
|
|
642
815
|
NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
|
643
816
|
end
|
644
817
|
|
645
|
-
def swap_instance_method
|
818
|
+
def swap_instance_method target, method_name, new_method_implementation, &blk
|
646
819
|
old_method_implementation = target.instance_method(method_name)
|
647
820
|
target.send(:define_method, method_name, new_method_implementation)
|
648
821
|
yield
|
@@ -657,7 +830,7 @@ def cross_agent_tests_dir
|
|
657
830
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
|
658
831
|
end
|
659
832
|
|
660
|
-
def load_cross_agent_test
|
833
|
+
def load_cross_agent_test name
|
661
834
|
test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
|
662
835
|
data = File.read(test_file_path)
|
663
836
|
data.gsub!('callCount', 'call_count')
|
@@ -666,13 +839,13 @@ def load_cross_agent_test(name)
|
|
666
839
|
data
|
667
840
|
end
|
668
841
|
|
669
|
-
def each_cross_agent_test
|
842
|
+
def each_cross_agent_test options
|
670
843
|
options = {:dir => nil, :pattern => "*"}.update(options)
|
671
844
|
path = File.join [cross_agent_tests_dir, options[:dir], options[:pattern]].compact
|
672
845
|
Dir.glob(path).each { |file| yield file}
|
673
846
|
end
|
674
847
|
|
675
|
-
def assert_event_attributes
|
848
|
+
def assert_event_attributes event, test_name, expected_attributes, non_expected_attributes
|
676
849
|
incorrect_attributes = []
|
677
850
|
|
678
851
|
event_attrs = event[0]
|
@@ -696,10 +869,116 @@ def assert_event_attributes(event, test_name, expected_attributes, non_expected_
|
|
696
869
|
assert(incorrect_attributes.empty?, msg)
|
697
870
|
|
698
871
|
non_expected_attributes.each do |name|
|
699
|
-
|
872
|
+
refute event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}"
|
700
873
|
end
|
701
874
|
end
|
702
875
|
|
703
|
-
def attributes_for
|
876
|
+
def attributes_for sample, type
|
704
877
|
sample.attributes.instance_variable_get("@#{type}_attributes")
|
705
878
|
end
|
879
|
+
|
880
|
+
def uncache_trusted_account_key
|
881
|
+
NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set :@trace_state_entry_key, nil
|
882
|
+
end
|
883
|
+
|
884
|
+
def reset_buffers_and_caches
|
885
|
+
NewRelic::Agent.drop_buffered_data
|
886
|
+
uncache_trusted_account_key
|
887
|
+
end
|
888
|
+
|
889
|
+
def message_for_status_code code
|
890
|
+
# Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
891
|
+
if defined?(Net::HTTP::STATUS_CODES)
|
892
|
+
return Net::HTTP::STATUS_CODES[code]
|
893
|
+
end
|
894
|
+
|
895
|
+
case code
|
896
|
+
when 200 then "OK"
|
897
|
+
when 404 then "Not Found"
|
898
|
+
when 403 then "Forbidden"
|
899
|
+
else "Unknown"
|
900
|
+
end
|
901
|
+
end
|
902
|
+
|
903
|
+
# wraps the given headers in a Net::HTTPResponse which has accompanying
|
904
|
+
# http status code associated with it.
|
905
|
+
# a "status_code" may be passed in the headers to alter the HTTP Status Code
|
906
|
+
# that is wrapped in the response.
|
907
|
+
def mock_http_response headers, wrap_it=true
|
908
|
+
status_code = (headers.delete("status_code") || 200).to_i
|
909
|
+
net_http_resp = Net::HTTPResponse.new(1.0, status_code, message_for_status_code(status_code))
|
910
|
+
headers.each do |key, value|
|
911
|
+
net_http_resp.add_field key.to_s, value
|
912
|
+
end
|
913
|
+
return net_http_resp unless wrap_it
|
914
|
+
NewRelic::Agent::HTTPClients::NetHTTPResponse.new(net_http_resp)
|
915
|
+
end
|
916
|
+
|
917
|
+
# +expected+ can be a string or regular expression
|
918
|
+
def assert_match_or_equal expected, value
|
919
|
+
if expected.is_a?(Regexp)
|
920
|
+
assert_match expected, value
|
921
|
+
else
|
922
|
+
assert_equal expected, value
|
923
|
+
end
|
924
|
+
end
|
925
|
+
|
926
|
+
# selects the last segment with a noticed_error and checks
|
927
|
+
# the expectations against it.
|
928
|
+
def assert_segment_noticed_error txn, segment_name, error_classes, error_message
|
929
|
+
error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
|
930
|
+
assert error_segment, "Expected at least one segment with a noticed_error"
|
931
|
+
|
932
|
+
assert_match_or_equal segment_name, error_segment.name
|
933
|
+
|
934
|
+
noticed_error = error_segment.noticed_error
|
935
|
+
|
936
|
+
assert_match_or_equal error_classes, noticed_error.exception_class_name
|
937
|
+
assert_match_or_equal error_message, noticed_error.message
|
938
|
+
end
|
939
|
+
|
940
|
+
def assert_transaction_noticed_error txn, error_classes
|
941
|
+
refute_empty txn.exceptions, "Expected transaction to notice the error"
|
942
|
+
assert_match_or_equal error_classes, txn.exceptions.keys.first.class.name
|
943
|
+
end
|
944
|
+
|
945
|
+
def refute_transaction_noticed_error txn, error_class
|
946
|
+
error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
|
947
|
+
assert error_segment, "Expected at least one segment with a noticed_error"
|
948
|
+
assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
|
949
|
+
end
|
950
|
+
|
951
|
+
def refute_raises *exp
|
952
|
+
msg = "#{exp.pop}.\n" if String === exp.last
|
953
|
+
|
954
|
+
begin
|
955
|
+
yield
|
956
|
+
rescue MiniTest::Skip => e
|
957
|
+
puts "SKIP REPORTS: #{e.inspect}"
|
958
|
+
return e if exp.include? MiniTest::Skip
|
959
|
+
raise e
|
960
|
+
rescue Exception => e
|
961
|
+
puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
|
962
|
+
exp = exp.first if exp.size == 1
|
963
|
+
flunk msg || "unexpected exception raised: #{e}"
|
964
|
+
end
|
965
|
+
end
|
966
|
+
|
967
|
+
def assert_implements instance, method, *args
|
968
|
+
fail_message = "expected #{instance.class}##{method} method to be implemented"
|
969
|
+
refute_raises NotImplementedError, fail_message do
|
970
|
+
instance.send(method, *args)
|
971
|
+
end
|
972
|
+
end
|
973
|
+
|
974
|
+
def defer_testing_to_min_supported_rails test_file, min_rails_version, supports_jruby=true
|
975
|
+
if defined?(::Rails) &&
|
976
|
+
defined?(::Rails::VERSION::STRING) &&
|
977
|
+
(::Rails::VERSION::STRING.to_f >= min_rails_version) &&
|
978
|
+
(supports_jruby || !NewRelic::LanguageSupport.jruby?)
|
979
|
+
|
980
|
+
yield
|
981
|
+
else
|
982
|
+
puts "Skipping tests in #{test_file} because Rails >= #{min_rails_version} is unavailable"
|
983
|
+
end
|
984
|
+
end
|