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