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