newrelic_rpm 8.7.0 → 8.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.yml +68 -189
- data/.rubocop_todo.yml +52 -0
- data/.simplecov +15 -0
- data/.snyk +11 -0
- data/.yardopts +1 -0
- data/Brewfile +1 -0
- data/CHANGELOG.md +181 -23
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +0 -1
- data/Guardfile +1 -0
- data/README.md +1 -1
- data/Rakefile +13 -20
- data/Thorfile +5 -0
- data/bin/newrelic +2 -1
- data/bin/newrelic_cmd +1 -0
- data/bin/nrdebug +66 -45
- data/config.dot +5 -5
- data/init.rb +4 -4
- data/install.rb +2 -2
- data/lib/new_relic/agent/adaptive_sampler.rb +4 -4
- data/lib/new_relic/agent/agent/shutdown.rb +34 -0
- data/lib/new_relic/agent/agent/special_startup.rb +70 -0
- data/lib/new_relic/agent/agent/start_worker_thread.rb +163 -0
- data/lib/new_relic/agent/agent/startup.rb +196 -0
- data/lib/new_relic/agent/agent.rb +134 -534
- data/lib/new_relic/agent/agent_logger.rb +8 -10
- data/lib/new_relic/agent/attribute_filter.rb +40 -21
- data/lib/new_relic/agent/attribute_processing.rb +7 -7
- data/lib/new_relic/agent/attributes.rb +2 -2
- data/lib/new_relic/agent/audit_logger.rb +3 -3
- data/lib/new_relic/agent/autostart.rb +2 -2
- 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 +8 -8
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +105 -41
- data/lib/new_relic/agent/configuration/dotted_hash.rb +2 -2
- data/lib/new_relic/agent/configuration/environment_source.rb +5 -5
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
- data/lib/new_relic/agent/configuration/manager.rb +5 -5
- data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
- data/lib/new_relic/agent/configuration/mask_defaults.rb +3 -3
- data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -4
- data/lib/new_relic/agent/configuration/server_source.rb +7 -7
- data/lib/new_relic/agent/configuration/yaml_source.rb +6 -4
- data/lib/new_relic/agent/configuration.rb +1 -1
- data/lib/new_relic/agent/connect/request_builder.rb +3 -3
- data/lib/new_relic/agent/connect/response_handler.rb +5 -5
- data/lib/new_relic/agent/custom_event_aggregator.rb +5 -5
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscator.rb +2 -2
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
- data/lib/new_relic/agent/database.rb +21 -21
- data/lib/new_relic/agent/database_adapter.rb +1 -1
- data/lib/new_relic/agent/datastores/metric_helper.rb +12 -13
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +4 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +2 -4
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +3 -3
- data/lib/new_relic/agent/datastores.rb +4 -4
- data/lib/new_relic/agent/deprecator.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -17
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -10
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -19
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -10
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -3
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -40
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -15
- data/lib/new_relic/agent/distributed_tracing.rb +17 -18
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
- data/lib/new_relic/agent/error_collector.rb +6 -5
- data/lib/new_relic/agent/error_event_aggregator.rb +3 -4
- data/lib/new_relic/agent/error_filter.rb +5 -5
- data/lib/new_relic/agent/error_trace_aggregator.rb +3 -3
- data/lib/new_relic/agent/event_aggregator.rb +20 -20
- 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 +9 -9
- data/lib/new_relic/agent/external.rb +10 -10
- data/lib/new_relic/agent/guid_generator.rb +2 -2
- data/lib/new_relic/agent/harvester.rb +1 -1
- data/lib/new_relic/agent/heap.rb +5 -5
- data/lib/new_relic/agent/hostname.rb +4 -3
- data/lib/new_relic/agent/http_clients/abstract.rb +1 -2
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -6
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -5
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +2 -3
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +0 -1
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -2
- data/lib/new_relic/agent/http_clients/uri_util.rb +1 -2
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -5
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +31 -23
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +7 -6
- data/lib/new_relic/agent/instrumentation/active_job.rb +11 -4
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +4 -3
- data/lib/new_relic/agent/instrumentation/active_record.rb +9 -9
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +37 -21
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +21 -11
- data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -15
- data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -2
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
- data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
- data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -10
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -11
- data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/bunny.rb +1 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +25 -17
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -22
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +19 -16
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -3
- data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +44 -44
- data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -2
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -3
- data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -3
- data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
- data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -6
- data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -5
- data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
- data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
- data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
- data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
- data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
- data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -6
- data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
- data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -4
- data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httprb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -2
- data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -1
- data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/logger.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -3
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +24 -17
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -9
- data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -15
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +21 -15
- data/lib/new_relic/agent/instrumentation/memcache.rb +5 -6
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +0 -1
- data/lib/new_relic/agent/instrumentation/mongo.rb +2 -2
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +15 -14
- data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
- data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +6 -6
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino.rb +2 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -2
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -12
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -7
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -2
- data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
- data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -4
- data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -6
- data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -4
- data/lib/new_relic/agent/instrumentation/redis.rb +2 -2
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +0 -1
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -3
- data/lib/new_relic/agent/instrumentation/sequel.rb +8 -8
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -5
- data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -4
- data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/thread.rb +2 -2
- data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +8 -8
- data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
- data/lib/new_relic/agent/instrumentation.rb +1 -1
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +8 -8
- data/lib/new_relic/agent/linking_metadata.rb +2 -3
- data/lib/new_relic/agent/local_log_decorator.rb +0 -1
- data/lib/new_relic/agent/log_event_aggregator.rb +7 -7
- data/lib/new_relic/agent/log_once.rb +1 -1
- data/lib/new_relic/agent/log_priority.rb +1 -1
- data/lib/new_relic/agent/logging.rb +13 -13
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +19 -20
- data/lib/new_relic/agent/method_tracer.rb +15 -10
- data/lib/new_relic/agent/method_tracer_helpers.rb +83 -1
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -4
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -3
- data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
- data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -2
- data/lib/new_relic/agent/monitors.rb +5 -5
- data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -4
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
- data/lib/new_relic/agent/new_relic_service.rb +214 -166
- data/lib/new_relic/agent/{noticible_error.rb → noticeable_error.rb} +2 -3
- data/lib/new_relic/agent/null_logger.rb +1 -1
- data/lib/new_relic/agent/obfuscator.rb +3 -3
- data/lib/new_relic/agent/parameter_filtering.rb +1 -1
- data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +10 -5
- data/lib/new_relic/agent/pipe_service.rb +2 -2
- data/lib/new_relic/agent/prepend_supportability.rb +2 -2
- data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -4
- data/lib/new_relic/agent/range_extensions.rb +8 -28
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -2
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine.rb +2 -2
- 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 +2 -2
- data/lib/new_relic/agent/samplers/memory_sampler.rb +10 -10
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/vm_sampler.rb +3 -1
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
- data/lib/new_relic/agent/span_event_primitive.rb +24 -19
- data/lib/new_relic/agent/sql_sampler.rb +8 -8
- data/lib/new_relic/agent/stats.rb +15 -4
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -2
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -6
- data/lib/new_relic/agent/system_info.rb +68 -53
- data/lib/new_relic/agent/threading/agent_thread.rb +13 -9
- data/lib/new_relic/agent/threading/backtrace_node.rb +6 -4
- data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
- data/lib/new_relic/agent/threading/thread_profile.rb +4 -4
- data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
- data/lib/new_relic/agent/tracer.rb +19 -17
- data/lib/new_relic/agent/transaction/abstract_segment.rb +93 -34
- data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -12
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -48
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
- data/lib/new_relic/agent/transaction/external_request_segment.rb +37 -29
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -6
- data/lib/new_relic/agent/transaction/request_attributes.rb +29 -29
- data/lib/new_relic/agent/transaction/segment.rb +8 -8
- 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 +3 -3
- data/lib/new_relic/agent/transaction/trace_builder.rb +10 -10
- data/lib/new_relic/agent/transaction/trace_context.rb +22 -20
- data/lib/new_relic/agent/transaction/trace_node.rb +9 -9
- data/lib/new_relic/agent/transaction/tracing.rb +7 -7
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
- data/lib/new_relic/agent/transaction.rb +35 -31
- data/lib/new_relic/agent/transaction_error_primitive.rb +9 -9
- data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -5
- data/lib/new_relic/agent/transaction_event_primitive.rb +3 -4
- data/lib/new_relic/agent/transaction_event_recorder.rb +15 -14
- data/lib/new_relic/agent/transaction_metrics.rb +4 -4
- data/lib/new_relic/agent/transaction_sampler.rb +5 -5
- data/lib/new_relic/agent/transaction_time_aggregator.rb +14 -14
- data/lib/new_relic/agent/utilization/aws.rb +4 -4
- data/lib/new_relic/agent/utilization/azure.rb +2 -2
- data/lib/new_relic/agent/utilization/gcp.rb +7 -7
- data/lib/new_relic/agent/utilization/pcf.rb +4 -4
- data/lib/new_relic/agent/utilization/vendor.rb +28 -28
- data/lib/new_relic/agent/utilization_data.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 +36 -23
- data/lib/new_relic/agent/vm/snapshot.rb +2 -2
- data/lib/new_relic/agent/vm.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +2 -2
- data/lib/new_relic/agent.rb +27 -27
- data/lib/new_relic/cli/command.rb +6 -6
- data/lib/new_relic/cli/commands/deployments.rb +81 -29
- data/lib/new_relic/cli/commands/install.rb +6 -6
- data/lib/new_relic/coerce.rb +5 -6
- data/lib/new_relic/collection_helper.rb +4 -4
- data/lib/new_relic/constants.rb +0 -1
- data/lib/new_relic/control/class_methods.rb +1 -1
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +3 -3
- 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/rails_notifications.rb +1 -1
- 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/frameworks.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +20 -42
- data/lib/new_relic/control/instrumentation.rb +7 -7
- data/lib/new_relic/control/private_instance_methods.rb +48 -0
- data/lib/new_relic/control/server_methods.rb +2 -2
- data/lib/new_relic/control.rb +1 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/dependency_detection.rb +23 -22
- data/lib/new_relic/environment_report.rb +24 -14
- data/lib/new_relic/helper.rb +5 -5
- data/lib/new_relic/language_support.rb +8 -3
- data/lib/new_relic/latest_changes.rb +4 -4
- data/lib/new_relic/local_environment.rb +9 -11
- data/lib/new_relic/metric_data.rb +30 -24
- data/lib/new_relic/metric_spec.rb +3 -3
- data/lib/new_relic/noticed_error.rb +3 -6
- data/lib/new_relic/rack/agent_hooks.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +132 -123
- data/lib/new_relic/rack.rb +1 -1
- data/lib/new_relic/recipes/capistrano3.rb +3 -59
- data/lib/new_relic/recipes/capistrano_legacy.rb +13 -13
- data/lib/new_relic/recipes/helpers/send_deployment.rb +69 -0
- data/lib/new_relic/recipes.rb +1 -1
- data/lib/new_relic/supportability_helper.rb +6 -6
- data/lib/new_relic/traced_thread.rb +5 -7
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +8 -8
- data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/config.rake +8 -112
- data/lib/tasks/coverage_report.rake +28 -0
- data/lib/tasks/{config.html.erb → helpers/config.html.erb} +0 -0
- data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
- data/lib/tasks/helpers/format.rb +120 -0
- data/lib/tasks/helpers/matches.rb +12 -0
- data/lib/tasks/helpers/prompt.rb +24 -0
- data/lib/tasks/helpers/removers.rb +33 -0
- data/lib/tasks/install.rake +4 -0
- data/lib/tasks/instrumentation_generator/README.md +63 -0
- data/lib/tasks/instrumentation_generator/TODO.md +33 -0
- data/lib/tasks/instrumentation_generator/instrumentation.thor +102 -0
- data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
- data/lib/tasks/instrumentation_generator/templates/chain.tt +21 -0
- data/lib/tasks/instrumentation_generator/templates/chain_method.tt +7 -0
- data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
- data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +12 -0
- data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
- data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
- data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
- data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
- data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
- data/lib/tasks/multiverse.rake +4 -0
- data/lib/tasks/multiverse.rb +5 -30
- data/lib/tasks/newrelic.rb +1 -1
- data/lib/tasks/tests.rake +7 -8
- data/newrelic.yml +514 -483
- data/newrelic_rpm.gemspec +16 -21
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +125 -147
- metadata +82 -90
- data/bin/mongrel_rpm +0 -32
data/test/agent_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# This file is distributed under New Relic's license terms.
|
3
2
|
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
3
|
+
# frozen_string_literal: true
|
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.
|
@@ -13,49 +13,28 @@ rescue LoadError
|
|
13
13
|
# NOP -- Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
14
14
|
end
|
15
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
|
29
|
-
|
30
16
|
class ArrayLogDevice
|
31
|
-
def initialize
|
17
|
+
def initialize(array = [])
|
32
18
|
@array = array
|
33
19
|
end
|
34
20
|
attr_reader :array
|
35
21
|
|
36
|
-
def write
|
22
|
+
def write(message)
|
37
23
|
@array << message
|
38
24
|
end
|
39
25
|
|
40
26
|
def close; end
|
41
27
|
end
|
42
28
|
|
43
|
-
def fake_guid
|
44
|
-
NewRelic::Agent::GuidGenerator.generate_guid
|
29
|
+
def fake_guid(length = 16)
|
30
|
+
NewRelic::Agent::GuidGenerator.generate_guid(length)
|
45
31
|
end
|
46
32
|
|
47
|
-
def
|
48
|
-
|
49
|
-
assert_respond_to matcher, :"=~"
|
50
|
-
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
51
|
-
assert matcher =~ obj, msg
|
33
|
+
def assert_between(floor, ceiling, value, message = "expected #{floor} <= #{value} <= #{ceiling}")
|
34
|
+
assert((floor <= value && value <= ceiling), message) # rubocop:disable Minitest/AssertWithExpectedArgument
|
52
35
|
end
|
53
36
|
|
54
|
-
def
|
55
|
-
assert((floor <= value && value <= ceiling), message)
|
56
|
-
end
|
57
|
-
|
58
|
-
def assert_in_delta expected, actual, delta
|
37
|
+
def assert_in_delta(expected, actual, delta)
|
59
38
|
assert_between((expected - delta), (expected + delta), actual)
|
60
39
|
end
|
61
40
|
|
@@ -67,10 +46,9 @@ def reset_error_traces!
|
|
67
46
|
NewRelic::Agent.instance.error_collector.error_trace_aggregator.reset!
|
68
47
|
end
|
69
48
|
|
70
|
-
def assert_has_traced_error
|
49
|
+
def assert_has_traced_error(error_class)
|
71
50
|
errors = harvest_error_traces!
|
72
|
-
|
73
|
-
errors.find { |e| e.exception_class_name == error_class.name } != nil, \
|
51
|
+
refute_nil errors.find { |e| e.exception_class_name == error_class.name }, \
|
74
52
|
"Didn't find error of class #{error_class}"
|
75
53
|
end
|
76
54
|
|
@@ -102,51 +80,44 @@ def last_error_event
|
|
102
80
|
harvest_error_events!.last.last
|
103
81
|
end
|
104
82
|
|
105
|
-
unless defined? assert_block
|
106
|
-
def assert_block *msgs
|
107
|
-
assert yield, *msgs
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
83
|
unless defined? assert_includes
|
112
|
-
def assert_includes
|
84
|
+
def assert_includes(collection, member, msg = nil)
|
113
85
|
msg = "Expected #{collection.inspect} to include #{member.inspect}"
|
114
|
-
|
86
|
+
assert_includes collection, member, msg
|
115
87
|
end
|
116
88
|
end
|
117
89
|
|
118
90
|
unless defined? assert_not_includes
|
119
|
-
def assert_not_includes
|
91
|
+
def assert_not_includes(collection, member, msg = nil)
|
120
92
|
msg = "Expected #{collection.inspect} not to include #{member.inspect}"
|
121
|
-
|
93
|
+
refute_includes collection, member, msg
|
122
94
|
end
|
123
95
|
end
|
124
96
|
|
125
97
|
unless defined? assert_empty
|
126
|
-
def assert_empty
|
127
|
-
|
98
|
+
def assert_empty(collection, msg = nil)
|
99
|
+
assert_empty collection, msg
|
128
100
|
end
|
129
101
|
end
|
130
102
|
|
131
|
-
def assert_equal_unordered
|
103
|
+
def assert_equal_unordered(left, right)
|
132
104
|
assert_equal(left.length, right.length, "Lengths don't match. #{left.length} != #{right.length}")
|
133
105
|
left.each { |element| assert_includes(right, element) }
|
134
106
|
end
|
135
107
|
|
136
108
|
def assert_log_contains(log, message)
|
137
109
|
lines = log.array
|
138
|
-
|
139
|
-
assert (lines.any? { |line| line.match(message) }), failure_message
|
110
|
+
assert (lines.any? { |line| line.match(message) })
|
140
111
|
end
|
141
112
|
|
142
|
-
def assert_audit_log_contains
|
113
|
+
def assert_audit_log_contains(audit_log_contents, needle)
|
143
114
|
# Original request bodies dumped to the log have symbol keys, but once
|
144
115
|
# they go through a dump/load, they're strings again, so we strip
|
145
116
|
# double-quotes and colons from the log, and the strings we searching for.
|
146
117
|
regex = /[:"]/
|
147
118
|
needle = needle.gsub(regex, '')
|
148
119
|
haystack = audit_log_contents.gsub(regex, '')
|
149
|
-
|
120
|
+
assert_includes(haystack, needle, "Expected log to contain '#{needle}'")
|
150
121
|
end
|
151
122
|
|
152
123
|
# Because we don't generate a strictly machine-readable representation of
|
@@ -157,7 +128,7 @@ end
|
|
157
128
|
# orderings of the key/value pairs in Hashes that were embedded in the request
|
158
129
|
# body). So, this method traverses an object graph and only makes assertions
|
159
130
|
# about the terminal (non-Array-or-Hash) nodes therein.
|
160
|
-
def assert_audit_log_contains_object
|
131
|
+
def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
|
161
132
|
case o
|
162
133
|
when Hash
|
163
134
|
o.each do |k, v|
|
@@ -175,12 +146,12 @@ def assert_audit_log_contains_object audit_log_contents, o, format = :json
|
|
175
146
|
end
|
176
147
|
end
|
177
148
|
|
178
|
-
def compare_metrics
|
149
|
+
def compare_metrics(expected, actual)
|
179
150
|
actual.delete_if { |a| a.include?('GC/Transaction/') }
|
180
151
|
assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
|
181
152
|
end
|
182
153
|
|
183
|
-
def metric_spec_from_specish
|
154
|
+
def metric_spec_from_specish(specish)
|
184
155
|
spec = case specish
|
185
156
|
when String then NewRelic::MetricSpec.new(specish)
|
186
157
|
when Array then NewRelic::MetricSpec.new(*specish)
|
@@ -188,7 +159,7 @@ def metric_spec_from_specish specish
|
|
188
159
|
spec
|
189
160
|
end
|
190
161
|
|
191
|
-
def _normalize_metric_expectations
|
162
|
+
def _normalize_metric_expectations(expectations)
|
192
163
|
case expectations
|
193
164
|
when Array
|
194
165
|
hash = {}
|
@@ -202,8 +173,8 @@ def _normalize_metric_expectations expectations
|
|
202
173
|
end
|
203
174
|
end
|
204
175
|
|
205
|
-
def dump_stats
|
206
|
-
str = " Call count: #{stats.call_count}\n"
|
176
|
+
def dump_stats(stats)
|
177
|
+
str = String.new(" Call count: #{stats.call_count}\n")
|
207
178
|
str << " Total call time: #{stats.total_call_time}\n"
|
208
179
|
str << " Total exclusive time: #{stats.total_exclusive_time}\n"
|
209
180
|
str << " Min call time: #{stats.min_call_time}\n"
|
@@ -215,7 +186,7 @@ def dump_stats stats
|
|
215
186
|
str
|
216
187
|
end
|
217
188
|
|
218
|
-
def assert_stats_has_values
|
189
|
+
def assert_stats_has_values(stats, expected_spec, expected_attrs)
|
219
190
|
expected_attrs.each do |attr, expected_value|
|
220
191
|
actual_value = stats.send(attr)
|
221
192
|
|
@@ -242,7 +213,7 @@ def assert_stats_has_values_with_call_count(expected_value, actual_value, msg)
|
|
242
213
|
end
|
243
214
|
end
|
244
215
|
|
245
|
-
def assert_metrics_recorded
|
216
|
+
def assert_metrics_recorded(expected)
|
246
217
|
expected = _normalize_metric_expectations(expected)
|
247
218
|
expected.each do |specish, expected_attrs|
|
248
219
|
expected_spec = metric_spec_from_specish(specish)
|
@@ -256,7 +227,7 @@ def assert_metrics_recorded expected
|
|
256
227
|
msg += "\nDid find specs: [\n#{matches.join(",\n")}\n]" unless matches.empty?
|
257
228
|
msg += "\nAll specs in there were: #{format_metric_spec_list(all_specs)}"
|
258
229
|
|
259
|
-
assert(actual_stats, msg)
|
230
|
+
assert(actual_stats, msg) # rubocop:disable Minitest/AssertWithExpectedArgument
|
260
231
|
end
|
261
232
|
assert_stats_has_values(actual_stats, expected_spec, expected_attrs)
|
262
233
|
end
|
@@ -273,7 +244,7 @@ end
|
|
273
244
|
# the :ignore_filter option. This will allow you to specify a Regex that
|
274
245
|
# allowlists broad swathes of metric territory (e.g. 'Supportability/').
|
275
246
|
#
|
276
|
-
def assert_metrics_recorded_exclusive
|
247
|
+
def assert_metrics_recorded_exclusive(expected, options = {})
|
277
248
|
expected = _normalize_metric_expectations(expected)
|
278
249
|
assert_metrics_recorded(expected)
|
279
250
|
|
@@ -289,11 +260,20 @@ def assert_metrics_recorded_exclusive expected, options = {}
|
|
289
260
|
expected_metrics = expected.keys.map { |s| metric_spec_from_specish(s) }
|
290
261
|
|
291
262
|
unexpected_metrics = recorded_metrics - expected_metrics
|
292
|
-
unexpected_metrics.reject! { |m| m.name
|
263
|
+
unexpected_metrics.reject! { |m| m.name.include?('GC/Transaction') }
|
293
264
|
|
294
265
|
assert_equal(0, unexpected_metrics.size, "Found unexpected metrics: #{format_metric_spec_list(unexpected_metrics)}")
|
295
266
|
end
|
296
267
|
|
268
|
+
def assert_newrelic_metadata_present(metadata)
|
269
|
+
assert metadata.key?('newrelic')
|
270
|
+
refute_nil metadata['newrelic']
|
271
|
+
end
|
272
|
+
|
273
|
+
def assert_distributed_tracing_payload_created_for_transaction(transaction)
|
274
|
+
assert transaction.distributed_tracer.instance_variable_get(:@distributed_trace_payload_created)
|
275
|
+
end
|
276
|
+
|
297
277
|
# The clear_metrics! method prevents metrics from "leaking" between tests by resetting
|
298
278
|
# the @stats_hash instance variable in the current instance of NewRelic::Agent::StatsEngine.
|
299
279
|
|
@@ -311,7 +291,7 @@ def clear_metrics!
|
|
311
291
|
NewRelic::Agent.instance.stats_engine.reset_for_test!
|
312
292
|
end
|
313
293
|
|
314
|
-
def assert_metrics_not_recorded
|
294
|
+
def assert_metrics_not_recorded(not_expected)
|
315
295
|
not_expected = _normalize_metric_expectations(not_expected)
|
316
296
|
found_but_not_expected = []
|
317
297
|
not_expected.each do |specish, _|
|
@@ -320,19 +300,18 @@ def assert_metrics_not_recorded not_expected
|
|
320
300
|
found_but_not_expected << spec
|
321
301
|
end
|
322
302
|
end
|
323
|
-
|
303
|
+
assert_empty(found_but_not_expected, "Found unexpected metrics: #{format_metric_spec_list(found_but_not_expected)}")
|
324
304
|
end
|
325
305
|
|
326
306
|
alias :refute_metrics_recorded :assert_metrics_not_recorded
|
327
307
|
|
328
|
-
def assert_no_metrics_match
|
308
|
+
def assert_no_metrics_match(regex)
|
329
309
|
matching_metrics = []
|
330
310
|
NewRelic::Agent.instance.stats_engine.to_h.keys.map(&:to_s).each do |metric|
|
331
|
-
matching_metrics << metric if metric.match
|
311
|
+
matching_metrics << metric if metric.match(regex)
|
332
312
|
end
|
333
313
|
|
334
|
-
|
335
|
-
[],
|
314
|
+
assert_empty(
|
336
315
|
matching_metrics,
|
337
316
|
"Found unexpected metrics:\n" + matching_metrics.map { |m| " '#{m}'" }.join("\n") + "\n\n"
|
338
317
|
)
|
@@ -340,26 +319,26 @@ end
|
|
340
319
|
|
341
320
|
alias :refute_metrics_match :assert_no_metrics_match
|
342
321
|
|
343
|
-
def format_metric_spec_list
|
322
|
+
def format_metric_spec_list(specs)
|
344
323
|
spec_strings = specs.map do |spec|
|
345
324
|
"#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
|
346
325
|
end
|
347
326
|
"[\n #{spec_strings.join(",\n ")}\n]"
|
348
327
|
end
|
349
328
|
|
350
|
-
def assert_truthy
|
329
|
+
def assert_truthy(expected, msg = nil)
|
351
330
|
msg ||= "Expected #{expected.inspect} to be truthy"
|
352
|
-
|
331
|
+
refute !expected, msg
|
353
332
|
end
|
354
333
|
|
355
|
-
def assert_falsy
|
334
|
+
def assert_falsy(expected, msg = nil)
|
356
335
|
msg ||= "Expected #{expected.inspect} to be falsy"
|
357
|
-
|
336
|
+
refute expected, msg
|
358
337
|
end
|
359
338
|
|
360
339
|
unless defined? assert_false
|
361
|
-
def assert_false
|
362
|
-
|
340
|
+
def assert_false(expected)
|
341
|
+
refute expected
|
363
342
|
end
|
364
343
|
end
|
365
344
|
|
@@ -385,27 +364,26 @@ end
|
|
385
364
|
# With a transaction name plus category:
|
386
365
|
# in_transaction('foobar', :category => :controller) { ... }
|
387
366
|
#
|
388
|
-
def in_transaction
|
367
|
+
def in_transaction(*args, &blk)
|
389
368
|
opts = args.last && args.last.is_a?(Hash) ? args.pop : {}
|
390
369
|
category = (opts && opts.delete(:category)) || :other
|
391
370
|
|
392
371
|
# At least one test passes `:transaction_name => nil`, so handle it gently
|
393
|
-
name = opts.key?(:transaction_name) ? opts.delete(:transaction_name) :
|
394
|
-
args.first || 'dummy'
|
372
|
+
name = opts.key?(:transaction_name) ? opts.delete(:transaction_name) : args.first || 'dummy'
|
395
373
|
|
396
374
|
state = NewRelic::Agent::Tracer.state
|
397
375
|
txn = nil
|
398
376
|
|
399
377
|
NewRelic::Agent::Tracer.in_transaction(name: name, category: category, options: opts) do
|
400
378
|
txn = state.current_transaction
|
401
|
-
yield
|
379
|
+
yield(state.current_transaction)
|
402
380
|
end
|
403
381
|
|
404
382
|
txn
|
405
383
|
end
|
406
384
|
|
407
385
|
# Temporarily disables default transformer so tests with invalid inputs can be tried
|
408
|
-
def with_disabled_defaults_transformer
|
386
|
+
def with_disabled_defaults_transformer(key)
|
409
387
|
begin
|
410
388
|
transformer = NewRelic::Agent::Configuration::DEFAULTS[key][:transform]
|
411
389
|
NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = nil
|
@@ -416,13 +394,13 @@ def with_disabled_defaults_transformer key
|
|
416
394
|
end
|
417
395
|
|
418
396
|
# Convenience wrapper to stand up a transaction and provide a segment within
|
419
|
-
# that transaction to work with. The same
|
397
|
+
# that transaction to work with. The same arguments as provided to in_transaction
|
420
398
|
# may be supplied.
|
421
|
-
def with_segment
|
399
|
+
def with_segment(*args, &blk)
|
422
400
|
segment = nil
|
423
|
-
txn = in_transaction(*args) do |
|
424
|
-
segment =
|
425
|
-
yield
|
401
|
+
txn = in_transaction(*args) do |t|
|
402
|
+
segment = t.current_segment
|
403
|
+
yield(segment, t)
|
426
404
|
end
|
427
405
|
[segment, txn]
|
428
406
|
end
|
@@ -430,7 +408,7 @@ end
|
|
430
408
|
# building error attributes on segments are deferred until it's time
|
431
409
|
# to publish/harvest them as spans, so for testing, we'll explicitly
|
432
410
|
# build 'em as appropriate so we can test 'em
|
433
|
-
def build_deferred_error_attributes
|
411
|
+
def build_deferred_error_attributes(segment)
|
434
412
|
return unless segment.noticed_error
|
435
413
|
return if segment.noticed_error_attributes.frozen?
|
436
414
|
segment.noticed_error.build_error_attributes
|
@@ -445,30 +423,30 @@ def capture_segment_with_error
|
|
445
423
|
end
|
446
424
|
rescue Exception => exception
|
447
425
|
assert segment_with_error, "expected to have a segment_with_error"
|
448
|
-
build_deferred_error_attributes
|
426
|
+
build_deferred_error_attributes(segment_with_error)
|
449
427
|
return segment_with_error, exception
|
450
428
|
end
|
451
429
|
end
|
452
430
|
|
453
|
-
def stub_transaction_guid
|
431
|
+
def stub_transaction_guid(guid)
|
454
432
|
NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
|
455
433
|
end
|
456
434
|
|
457
435
|
# Convenience wrapper around in_transaction that sets the category so that it
|
458
436
|
# looks like we are in a web transaction
|
459
|
-
def in_web_transaction
|
437
|
+
def in_web_transaction(name = 'dummy')
|
460
438
|
in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
|
461
|
-
yield
|
439
|
+
yield(txn)
|
462
440
|
end
|
463
441
|
end
|
464
442
|
|
465
|
-
def in_background_transaction
|
443
|
+
def in_background_transaction(name = 'silly')
|
466
444
|
in_transaction(name, :category => :task) do |txn|
|
467
|
-
yield
|
445
|
+
yield(txn)
|
468
446
|
end
|
469
447
|
end
|
470
448
|
|
471
|
-
def refute_contains_request_params
|
449
|
+
def refute_contains_request_params(attributes)
|
472
450
|
attributes.keys.each do |key|
|
473
451
|
refute_match(/^request\.parameters\./, key.to_s)
|
474
452
|
end
|
@@ -487,7 +465,7 @@ def last_transaction_trace_request_params
|
|
487
465
|
end
|
488
466
|
end
|
489
467
|
|
490
|
-
def find_sql_trace
|
468
|
+
def find_sql_trace(metric_name)
|
491
469
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
|
492
470
|
trace.database_metric_name == metric_name
|
493
471
|
end
|
@@ -497,7 +475,7 @@ def last_sql_trace
|
|
497
475
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
|
498
476
|
end
|
499
477
|
|
500
|
-
def find_last_transaction_node
|
478
|
+
def find_last_transaction_node(transaction_sample = nil)
|
501
479
|
if transaction_sample
|
502
480
|
root_node = transaction_sample.root_node
|
503
481
|
else
|
@@ -510,7 +488,7 @@ def find_last_transaction_node transaction_sample = nil
|
|
510
488
|
return last_node
|
511
489
|
end
|
512
490
|
|
513
|
-
def find_node_with_name
|
491
|
+
def find_node_with_name(transaction_sample, name)
|
514
492
|
transaction_sample.root_node.each_node do |node|
|
515
493
|
if node.metric_name == name
|
516
494
|
return node
|
@@ -520,9 +498,9 @@ def find_node_with_name transaction_sample, name
|
|
520
498
|
nil
|
521
499
|
end
|
522
500
|
|
523
|
-
def find_node_with_name_matching
|
501
|
+
def find_node_with_name_matching(transaction_sample, regex)
|
524
502
|
transaction_sample.root_node.each_node do |node|
|
525
|
-
if node.metric_name.match
|
503
|
+
if node.metric_name.match(regex)
|
526
504
|
return node
|
527
505
|
end
|
528
506
|
end
|
@@ -530,13 +508,13 @@ def find_node_with_name_matching transaction_sample, regex
|
|
530
508
|
nil
|
531
509
|
end
|
532
510
|
|
533
|
-
def find_all_nodes_with_name_matching
|
511
|
+
def find_all_nodes_with_name_matching(transaction_sample, regexes)
|
534
512
|
regexes = [regexes].flatten
|
535
513
|
matching_nodes = []
|
536
514
|
|
537
515
|
transaction_sample.root_node.each_node do |node|
|
538
516
|
regexes.each do |regex|
|
539
|
-
if node.metric_name.match
|
517
|
+
if node.metric_name.match(regex)
|
540
518
|
matching_nodes << node
|
541
519
|
end
|
542
520
|
end
|
@@ -545,7 +523,7 @@ def find_all_nodes_with_name_matching transaction_sample, regexes
|
|
545
523
|
matching_nodes
|
546
524
|
end
|
547
525
|
|
548
|
-
def with_config
|
526
|
+
def with_config(config_hash, at_start = true)
|
549
527
|
config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
|
550
528
|
NewRelic::Agent.config.add_config_for_testing(config, at_start)
|
551
529
|
NewRelic::Agent.instance.refresh_attribute_filter
|
@@ -557,20 +535,20 @@ def with_config config_hash, at_start = true
|
|
557
535
|
end
|
558
536
|
end
|
559
537
|
|
560
|
-
def with_server_source
|
561
|
-
with_config
|
538
|
+
def with_server_source(config_hash, at_start = true)
|
539
|
+
with_config(config_hash, at_start) do
|
562
540
|
NewRelic::Agent.config.notify_server_source_added
|
563
541
|
yield
|
564
542
|
end
|
565
543
|
end
|
566
544
|
|
567
|
-
def with_config_low_priority
|
545
|
+
def with_config_low_priority(config_hash)
|
568
546
|
with_config(config_hash, false) do
|
569
547
|
yield
|
570
548
|
end
|
571
549
|
end
|
572
550
|
|
573
|
-
def with_transaction_renaming_rules
|
551
|
+
def with_transaction_renaming_rules(rule_specs)
|
574
552
|
original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
|
575
553
|
begin
|
576
554
|
new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
|
@@ -596,7 +574,7 @@ unless Time.respond_to?(:__original_now)
|
|
596
574
|
end
|
597
575
|
end
|
598
576
|
|
599
|
-
def nr_freeze_time
|
577
|
+
def nr_freeze_time(now = Time.now)
|
600
578
|
Time.__frozen_now = now
|
601
579
|
end
|
602
580
|
|
@@ -604,7 +582,7 @@ def nr_unfreeze_time
|
|
604
582
|
Time.__frozen_now = nil
|
605
583
|
end
|
606
584
|
|
607
|
-
def advance_time
|
585
|
+
def advance_time(seconds)
|
608
586
|
Time.__frozen_now = Time.now + seconds
|
609
587
|
end
|
610
588
|
|
@@ -633,7 +611,7 @@ def nr_unfreeze_process_time
|
|
633
611
|
Process.__frozen_clock_gettime = nil
|
634
612
|
end
|
635
613
|
|
636
|
-
def with_constant_defined
|
614
|
+
def with_constant_defined(constant_symbol, implementation = Module.new)
|
637
615
|
const_path = constant_path(constant_symbol.to_s)
|
638
616
|
|
639
617
|
if const_path
|
@@ -653,7 +631,7 @@ def with_constant_defined constant_symbol, implementation = Module.new
|
|
653
631
|
end
|
654
632
|
end
|
655
633
|
|
656
|
-
def constant_path
|
634
|
+
def constant_path(name, opts = {})
|
657
635
|
allow_partial = opts[:allow_partial]
|
658
636
|
path = [Object]
|
659
637
|
parts = name.gsub(/^::/, '').split('::')
|
@@ -666,13 +644,13 @@ def constant_path name, opts = {}
|
|
666
644
|
path
|
667
645
|
end
|
668
646
|
|
669
|
-
def get_parent
|
647
|
+
def get_parent(constant_name)
|
670
648
|
parent_name = constant_name.gsub(/::[^:]*$/, '')
|
671
649
|
const_path = constant_path(parent_name)
|
672
650
|
const_path ? const_path[-1] : nil
|
673
651
|
end
|
674
652
|
|
675
|
-
def undefine_constant
|
653
|
+
def undefine_constant(constant_symbol)
|
676
654
|
const_str = constant_symbol.to_s
|
677
655
|
parent = get_parent(const_str)
|
678
656
|
const_name = const_str.gsub(/.*::/, '')
|
@@ -696,11 +674,11 @@ ensure
|
|
696
674
|
NewRelic::Agent.logger = orig_logger
|
697
675
|
end
|
698
676
|
|
699
|
-
def create_agent_command
|
677
|
+
def create_agent_command(args = {})
|
700
678
|
NewRelic::Agent::Commands::AgentCommand.new([-1, {"name" => "command_name", "arguments" => args}])
|
701
679
|
end
|
702
680
|
|
703
|
-
def wait_for_backtrace_service_poll
|
681
|
+
def wait_for_backtrace_service_poll(opts = {})
|
704
682
|
defaults = {
|
705
683
|
:timeout => 10.0,
|
706
684
|
:service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
|
@@ -726,7 +704,7 @@ def wait_for_backtrace_service_poll opts = {}
|
|
726
704
|
end
|
727
705
|
end
|
728
706
|
|
729
|
-
def with_array_logger
|
707
|
+
def with_array_logger(level = :info)
|
730
708
|
orig_logger = NewRelic::Agent.logger
|
731
709
|
config = {:log_level => level}
|
732
710
|
logdev = ArrayLogDevice.new
|
@@ -763,7 +741,7 @@ class EnvUpdater
|
|
763
741
|
|
764
742
|
# Will attempt the given block up to MAX_RETRIES before
|
765
743
|
# surfacing the exception down the chain.
|
766
|
-
def with_retry
|
744
|
+
def with_retry(retry_limit = MAX_RETRIES)
|
767
745
|
retries ||= 0
|
768
746
|
sleep(retries)
|
769
747
|
yield
|
@@ -772,7 +750,7 @@ class EnvUpdater
|
|
772
750
|
end
|
773
751
|
|
774
752
|
# Locks and updates the ENV
|
775
|
-
def safe_update
|
753
|
+
def safe_update(env)
|
776
754
|
with_retry do
|
777
755
|
@mutex.synchronize do
|
778
756
|
env.each { |key, val| ENV[key] = val.to_s }
|
@@ -781,7 +759,7 @@ class EnvUpdater
|
|
781
759
|
end
|
782
760
|
|
783
761
|
# Locks and restores the ENV
|
784
|
-
def safe_restore
|
762
|
+
def safe_restore(old_env)
|
785
763
|
with_retry do
|
786
764
|
@mutex.synchronize do
|
787
765
|
old_env.each { |key, val| val ? ENV[key] = val : ENV.delete(key) }
|
@@ -794,17 +772,17 @@ class EnvUpdater
|
|
794
772
|
@@instance ||= EnvUpdater.new
|
795
773
|
end
|
796
774
|
|
797
|
-
def self.safe_update
|
798
|
-
instance.safe_update
|
775
|
+
def self.safe_update(env)
|
776
|
+
instance.safe_update(env)
|
799
777
|
end
|
800
778
|
|
801
|
-
def self.safe_restore
|
802
|
-
instance.safe_restore
|
779
|
+
def self.safe_restore(old_env)
|
780
|
+
instance.safe_restore(old_env)
|
803
781
|
end
|
804
782
|
|
805
783
|
# Effectively saves current ENV settings for given env's key/values,
|
806
784
|
# runs given block, then restores ENV to original state before returning.
|
807
|
-
def self.inject
|
785
|
+
def self.inject(env, &block)
|
808
786
|
old_env = {}
|
809
787
|
env.each { |key, val| old_env[key] = ENV[key] }
|
810
788
|
begin
|
@@ -821,11 +799,11 @@ end
|
|
821
799
|
|
822
800
|
# Changes ENV settings to given and runs given block and restores ENV
|
823
801
|
# to original values before returning.
|
824
|
-
def with_environment
|
802
|
+
def with_environment(env, &block)
|
825
803
|
EnvUpdater.inject(env) { yield }
|
826
804
|
end
|
827
805
|
|
828
|
-
def with_argv
|
806
|
+
def with_argv(argv)
|
829
807
|
old_argv = ARGV.dup
|
830
808
|
ARGV.clear
|
831
809
|
ARGV.concat(argv)
|
@@ -838,7 +816,7 @@ def with_argv argv
|
|
838
816
|
end
|
839
817
|
end
|
840
818
|
|
841
|
-
def with_ignore_error_filter
|
819
|
+
def with_ignore_error_filter(filter, &blk)
|
842
820
|
original_filter = NewRelic::Agent.ignore_error_filter
|
843
821
|
NewRelic::Agent.ignore_error_filter(&filter)
|
844
822
|
|
@@ -847,7 +825,7 @@ ensure
|
|
847
825
|
NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
|
848
826
|
end
|
849
827
|
|
850
|
-
def json_dump_and_encode
|
828
|
+
def json_dump_and_encode(object)
|
851
829
|
Base64.encode64(::JSON.dump(object))
|
852
830
|
end
|
853
831
|
|
@@ -855,7 +833,7 @@ def get_last_analytics_event
|
|
855
833
|
NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
|
856
834
|
end
|
857
835
|
|
858
|
-
def swap_instance_method
|
836
|
+
def swap_instance_method(target, method_name, new_method_implementation, &blk)
|
859
837
|
old_method_implementation = target.instance_method(method_name)
|
860
838
|
target.send(:define_method, method_name, new_method_implementation)
|
861
839
|
yield
|
@@ -870,22 +848,22 @@ def cross_agent_tests_dir
|
|
870
848
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
|
871
849
|
end
|
872
850
|
|
873
|
-
def load_cross_agent_test
|
851
|
+
def load_cross_agent_test(name)
|
874
852
|
test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
|
875
853
|
data = File.read(test_file_path)
|
876
854
|
data.gsub!('callCount', 'call_count')
|
877
855
|
data = ::JSON.load(data)
|
878
|
-
data.each { |testcase| testcase['testname'].
|
856
|
+
data.each { |testcase| testcase['testname'].tr!(' ', '_') if String === testcase['testname'] }
|
879
857
|
data
|
880
858
|
end
|
881
859
|
|
882
|
-
def each_cross_agent_test
|
860
|
+
def each_cross_agent_test(options)
|
883
861
|
options = {:dir => nil, :pattern => "*"}.update(options)
|
884
|
-
path = File.join
|
885
|
-
Dir.glob(path).each { |file| yield
|
862
|
+
path = File.join([cross_agent_tests_dir, options[:dir], options[:pattern]].compact)
|
863
|
+
Dir.glob(path).each { |file| yield(file) }
|
886
864
|
end
|
887
865
|
|
888
|
-
def assert_event_attributes
|
866
|
+
def assert_event_attributes(event, test_name, expected_attributes, non_expected_attributes)
|
889
867
|
incorrect_attributes = []
|
890
868
|
|
891
869
|
event_attrs = event[0]
|
@@ -895,7 +873,7 @@ def assert_event_attributes event, test_name, expected_attributes, non_expected_
|
|
895
873
|
incorrect_attributes << name unless actual_value == expected_value
|
896
874
|
end
|
897
875
|
|
898
|
-
msg = "Found missing or incorrect attribute values in #{test_name}:\n"
|
876
|
+
msg = String.new("Found missing or incorrect attribute values in #{test_name}:\n")
|
899
877
|
|
900
878
|
incorrect_attributes.each do |name|
|
901
879
|
msg << " #{name}: expected = #{expected_attributes[name].inspect}, actual = #{event_attrs[name].inspect}\n"
|
@@ -906,19 +884,19 @@ def assert_event_attributes event, test_name, expected_attributes, non_expected_
|
|
906
884
|
event_attrs.each do |name, actual_value|
|
907
885
|
msg << " #{name}: #{actual_value.inspect}\n"
|
908
886
|
end
|
909
|
-
|
887
|
+
assert_empty(incorrect_attributes, msg)
|
910
888
|
|
911
889
|
non_expected_attributes.each do |name|
|
912
890
|
refute event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}"
|
913
891
|
end
|
914
892
|
end
|
915
893
|
|
916
|
-
def attributes_for
|
894
|
+
def attributes_for(sample, type)
|
917
895
|
sample.attributes.instance_variable_get("@#{type}_attributes")
|
918
896
|
end
|
919
897
|
|
920
898
|
def uncache_trusted_account_key
|
921
|
-
NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set
|
899
|
+
NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set(:@trace_state_entry_key, nil)
|
922
900
|
end
|
923
901
|
|
924
902
|
def reset_buffers_and_caches
|
@@ -926,7 +904,7 @@ def reset_buffers_and_caches
|
|
926
904
|
uncache_trusted_account_key
|
927
905
|
end
|
928
906
|
|
929
|
-
def message_for_status_code
|
907
|
+
def message_for_status_code(code)
|
930
908
|
# Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
931
909
|
if defined?(Net::HTTP::STATUS_CODES)
|
932
910
|
return Net::HTTP::STATUS_CODES[code]
|
@@ -944,18 +922,18 @@ end
|
|
944
922
|
# http status code associated with it.
|
945
923
|
# a "status_code" may be passed in the headers to alter the HTTP Status Code
|
946
924
|
# that is wrapped in the response.
|
947
|
-
def mock_http_response
|
925
|
+
def mock_http_response(headers, wrap_it = true)
|
948
926
|
status_code = (headers.delete("status_code") || 200).to_i
|
949
927
|
net_http_resp = Net::HTTPResponse.new(1.0, status_code, message_for_status_code(status_code))
|
950
928
|
headers.each do |key, value|
|
951
|
-
net_http_resp.add_field
|
929
|
+
net_http_resp.add_field(key.to_s, value)
|
952
930
|
end
|
953
931
|
return net_http_resp unless wrap_it
|
954
932
|
NewRelic::Agent::HTTPClients::NetHTTPResponse.new(net_http_resp)
|
955
933
|
end
|
956
934
|
|
957
935
|
# +expected+ can be a string or regular expression
|
958
|
-
def assert_match_or_equal
|
936
|
+
def assert_match_or_equal(expected, value)
|
959
937
|
if expected.is_a?(Regexp)
|
960
938
|
assert_match expected, value
|
961
939
|
else
|
@@ -965,7 +943,7 @@ end
|
|
965
943
|
|
966
944
|
# selects the last segment with a noticed_error and checks
|
967
945
|
# the expectations against it.
|
968
|
-
def assert_segment_noticed_error
|
946
|
+
def assert_segment_noticed_error(txn, segment_name, error_classes, error_message)
|
969
947
|
error_segment = txn.segments.reverse.detect { |s| s.noticed_error }
|
970
948
|
assert error_segment, "Expected at least one segment with a noticed_error"
|
971
949
|
|
@@ -977,41 +955,41 @@ def assert_segment_noticed_error txn, segment_name, error_classes, error_message
|
|
977
955
|
assert_match_or_equal error_message, noticed_error.message
|
978
956
|
end
|
979
957
|
|
980
|
-
def assert_transaction_noticed_error
|
958
|
+
def assert_transaction_noticed_error(txn, error_classes)
|
981
959
|
refute_empty txn.exceptions, "Expected transaction to notice the error"
|
982
960
|
assert_match_or_equal error_classes, txn.exceptions.keys.first.class.name
|
983
961
|
end
|
984
962
|
|
985
|
-
def refute_transaction_noticed_error
|
963
|
+
def refute_transaction_noticed_error(txn, error_class)
|
986
964
|
error_segment = txn.segments.reverse.detect { |s| s.noticed_error }
|
987
965
|
assert error_segment, "Expected at least one segment with a noticed_error"
|
988
966
|
assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
|
989
967
|
end
|
990
968
|
|
991
|
-
def refute_raises
|
969
|
+
def refute_raises(*exp)
|
992
970
|
msg = "#{exp.pop}.\n" if String === exp.last
|
993
971
|
|
994
972
|
begin
|
995
973
|
yield
|
996
974
|
rescue MiniTest::Skip => e
|
997
975
|
puts "SKIP REPORTS: #{e.inspect}"
|
998
|
-
return e if exp.include?
|
976
|
+
return e if exp.include?(MiniTest::Skip)
|
999
977
|
raise e
|
1000
978
|
rescue Exception => e
|
1001
979
|
puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
|
1002
980
|
exp = exp.first if exp.size == 1
|
1003
|
-
flunk
|
981
|
+
flunk(msg || "unexpected exception raised: #{e}")
|
1004
982
|
end
|
1005
983
|
end
|
1006
984
|
|
1007
|
-
def assert_implements
|
985
|
+
def assert_implements(instance, method, *args)
|
1008
986
|
fail_message = "expected #{instance.class}##{method} method to be implemented"
|
1009
987
|
refute_raises NotImplementedError, fail_message do
|
1010
988
|
instance.send(method, *args)
|
1011
989
|
end
|
1012
990
|
end
|
1013
991
|
|
1014
|
-
def defer_testing_to_min_supported_rails
|
992
|
+
def defer_testing_to_min_supported_rails(test_file, min_rails_version, supports_jruby = true)
|
1015
993
|
if defined?(::Rails) &&
|
1016
994
|
defined?(::Rails::VERSION::STRING) &&
|
1017
995
|
(::Rails::VERSION::STRING.to_f >= min_rails_version) &&
|