newrelic_rpm 8.7.0 → 8.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.yml +68 -189
- data/.rubocop_todo.yml +52 -0
- data/.simplecov +15 -0
- data/.snyk +11 -0
- data/.yardopts +1 -0
- data/Brewfile +1 -0
- data/CHANGELOG.md +181 -23
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +0 -1
- data/Guardfile +1 -0
- data/README.md +1 -1
- data/Rakefile +13 -20
- data/Thorfile +5 -0
- data/bin/newrelic +2 -1
- data/bin/newrelic_cmd +1 -0
- data/bin/nrdebug +66 -45
- data/config.dot +5 -5
- data/init.rb +4 -4
- data/install.rb +2 -2
- data/lib/new_relic/agent/adaptive_sampler.rb +4 -4
- data/lib/new_relic/agent/agent/shutdown.rb +34 -0
- data/lib/new_relic/agent/agent/special_startup.rb +70 -0
- data/lib/new_relic/agent/agent/start_worker_thread.rb +163 -0
- data/lib/new_relic/agent/agent/startup.rb +196 -0
- data/lib/new_relic/agent/agent.rb +134 -534
- data/lib/new_relic/agent/agent_logger.rb +8 -10
- data/lib/new_relic/agent/attribute_filter.rb +40 -21
- data/lib/new_relic/agent/attribute_processing.rb +7 -7
- data/lib/new_relic/agent/attributes.rb +2 -2
- data/lib/new_relic/agent/audit_logger.rb +3 -3
- data/lib/new_relic/agent/autostart.rb +2 -2
- data/lib/new_relic/agent/chained_call.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command_router.rb +8 -8
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +105 -41
- data/lib/new_relic/agent/configuration/dotted_hash.rb +2 -2
- data/lib/new_relic/agent/configuration/environment_source.rb +5 -5
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
- data/lib/new_relic/agent/configuration/manager.rb +5 -5
- data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
- data/lib/new_relic/agent/configuration/mask_defaults.rb +3 -3
- data/lib/new_relic/agent/configuration/security_policy_source.rb +7 -4
- data/lib/new_relic/agent/configuration/server_source.rb +7 -7
- data/lib/new_relic/agent/configuration/yaml_source.rb +6 -4
- data/lib/new_relic/agent/configuration.rb +1 -1
- data/lib/new_relic/agent/connect/request_builder.rb +3 -3
- data/lib/new_relic/agent/connect/response_handler.rb +5 -5
- data/lib/new_relic/agent/custom_event_aggregator.rb +5 -5
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscator.rb +2 -2
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
- data/lib/new_relic/agent/database.rb +21 -21
- data/lib/new_relic/agent/database_adapter.rb +1 -1
- data/lib/new_relic/agent/datastores/metric_helper.rb +12 -13
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +4 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +2 -4
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +3 -3
- data/lib/new_relic/agent/datastores.rb +4 -4
- data/lib/new_relic/agent/deprecator.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +16 -17
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +9 -10
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +18 -19
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +8 -10
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +2 -3
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +40 -40
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +16 -15
- data/lib/new_relic/agent/distributed_tracing.rb +17 -18
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
- data/lib/new_relic/agent/error_collector.rb +6 -5
- data/lib/new_relic/agent/error_event_aggregator.rb +3 -4
- data/lib/new_relic/agent/error_filter.rb +5 -5
- data/lib/new_relic/agent/error_trace_aggregator.rb +3 -3
- data/lib/new_relic/agent/event_aggregator.rb +20 -20
- data/lib/new_relic/agent/event_buffer.rb +1 -1
- data/lib/new_relic/agent/event_listener.rb +1 -1
- data/lib/new_relic/agent/event_loop.rb +9 -9
- data/lib/new_relic/agent/external.rb +10 -10
- data/lib/new_relic/agent/guid_generator.rb +2 -2
- data/lib/new_relic/agent/harvester.rb +1 -1
- data/lib/new_relic/agent/heap.rb +5 -5
- data/lib/new_relic/agent/hostname.rb +4 -3
- data/lib/new_relic/agent/http_clients/abstract.rb +1 -2
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +5 -6
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -5
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +2 -3
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +0 -1
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -2
- data/lib/new_relic/agent/http_clients/uri_util.rb +1 -2
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -5
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +31 -23
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +7 -6
- data/lib/new_relic/agent/instrumentation/active_job.rb +11 -4
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +4 -3
- data/lib/new_relic/agent/instrumentation/active_record.rb +9 -9
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +37 -21
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +21 -11
- data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +16 -15
- data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger.rb +2 -2
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
- data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
- data/lib/new_relic/agent/instrumentation/bunny/chain.rb +10 -10
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +10 -11
- data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/bunny.rb +1 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +25 -17
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +21 -22
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +19 -16
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +2 -3
- data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +44 -44
- data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +1 -2
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +2 -3
- data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +1 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -3
- data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
- data/lib/new_relic/agent/instrumentation/grape/chain.rb +6 -6
- data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +5 -5
- data/lib/new_relic/agent/instrumentation/grape/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
- data/lib/new_relic/agent/instrumentation/grpc/client/chain.rb +97 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +89 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/prepend.rb +111 -0
- data/lib/new_relic/agent/instrumentation/grpc/client/request_wrapper.rb +30 -0
- data/lib/new_relic/agent/instrumentation/grpc/helper.rb +32 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/chain.rb +69 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +134 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/rpc_desc_prepend.rb +35 -0
- data/lib/new_relic/agent/instrumentation/grpc/server/rpc_server_prepend.rb +26 -0
- data/lib/new_relic/agent/instrumentation/grpc_client.rb +23 -0
- data/lib/new_relic/agent/instrumentation/grpc_server.rb +25 -0
- data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +6 -6
- data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
- data/lib/new_relic/agent/instrumentation/httprb/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -4
- data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httprb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -2
- data/lib/new_relic/agent/instrumentation/logger/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +5 -1
- data/lib/new_relic/agent/instrumentation/logger/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/logger.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache/chain.rb +2 -3
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +24 -17
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +8 -9
- data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +17 -15
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +21 -15
- data/lib/new_relic/agent/instrumentation/memcache.rb +5 -6
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +0 -1
- data/lib/new_relic/agent/instrumentation/mongo.rb +2 -2
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +15 -14
- data/lib/new_relic/agent/instrumentation/net_http/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
- data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +6 -6
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino.rb +2 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -2
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +12 -12
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +7 -7
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -6
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rake/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -2
- data/lib/new_relic/agent/instrumentation/rake/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
- data/lib/new_relic/agent/instrumentation/redis/chain.rb +3 -4
- data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +5 -6
- data/lib/new_relic/agent/instrumentation/redis/prepend.rb +3 -4
- data/lib/new_relic/agent/instrumentation/redis.rb +2 -2
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +0 -1
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -3
- data/lib/new_relic/agent/instrumentation/sequel.rb +8 -8
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -5
- data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -4
- data/lib/new_relic/agent/instrumentation/thread/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/thread/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/thread.rb +2 -2
- data/lib/new_relic/agent/instrumentation/tilt/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/tilt.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +8 -8
- data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
- data/lib/new_relic/agent/instrumentation.rb +1 -1
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +8 -8
- data/lib/new_relic/agent/linking_metadata.rb +2 -3
- data/lib/new_relic/agent/local_log_decorator.rb +0 -1
- data/lib/new_relic/agent/log_event_aggregator.rb +7 -7
- data/lib/new_relic/agent/log_once.rb +1 -1
- data/lib/new_relic/agent/log_priority.rb +1 -1
- data/lib/new_relic/agent/logging.rb +13 -13
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +19 -20
- data/lib/new_relic/agent/method_tracer.rb +15 -10
- data/lib/new_relic/agent/method_tracer_helpers.rb +83 -1
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -4
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +3 -3
- data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
- data/lib/new_relic/agent/monitors/synthetics_monitor.rb +2 -2
- data/lib/new_relic/agent/monitors.rb +5 -5
- data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +4 -4
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
- data/lib/new_relic/agent/new_relic_service.rb +214 -166
- data/lib/new_relic/agent/{noticible_error.rb → noticeable_error.rb} +2 -3
- data/lib/new_relic/agent/null_logger.rb +1 -1
- data/lib/new_relic/agent/obfuscator.rb +3 -3
- data/lib/new_relic/agent/parameter_filtering.rb +1 -1
- data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +10 -5
- data/lib/new_relic/agent/pipe_service.rb +2 -2
- data/lib/new_relic/agent/prepend_supportability.rb +2 -2
- data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -4
- data/lib/new_relic/agent/range_extensions.rb +8 -28
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +2 -2
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine.rb +2 -2
- data/lib/new_relic/agent/sampler.rb +1 -1
- data/lib/new_relic/agent/sampler_collection.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
- data/lib/new_relic/agent/samplers/memory_sampler.rb +10 -10
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/vm_sampler.rb +3 -1
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
- data/lib/new_relic/agent/span_event_primitive.rb +24 -19
- data/lib/new_relic/agent/sql_sampler.rb +8 -8
- data/lib/new_relic/agent/stats.rb +15 -4
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -2
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +6 -6
- data/lib/new_relic/agent/system_info.rb +68 -53
- data/lib/new_relic/agent/threading/agent_thread.rb +13 -9
- data/lib/new_relic/agent/threading/backtrace_node.rb +6 -4
- data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
- data/lib/new_relic/agent/threading/thread_profile.rb +4 -4
- data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
- data/lib/new_relic/agent/tracer.rb +19 -17
- data/lib/new_relic/agent/transaction/abstract_segment.rb +93 -34
- data/lib/new_relic/agent/transaction/datastore_segment.rb +12 -12
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +52 -48
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
- data/lib/new_relic/agent/transaction/external_request_segment.rb +37 -29
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +6 -6
- data/lib/new_relic/agent/transaction/request_attributes.rb +29 -29
- data/lib/new_relic/agent/transaction/segment.rb +8 -8
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/trace.rb +3 -3
- data/lib/new_relic/agent/transaction/trace_builder.rb +10 -10
- data/lib/new_relic/agent/transaction/trace_context.rb +22 -20
- data/lib/new_relic/agent/transaction/trace_node.rb +9 -9
- data/lib/new_relic/agent/transaction/tracing.rb +7 -7
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
- data/lib/new_relic/agent/transaction.rb +35 -31
- data/lib/new_relic/agent/transaction_error_primitive.rb +9 -9
- data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -5
- data/lib/new_relic/agent/transaction_event_primitive.rb +3 -4
- data/lib/new_relic/agent/transaction_event_recorder.rb +15 -14
- data/lib/new_relic/agent/transaction_metrics.rb +4 -4
- data/lib/new_relic/agent/transaction_sampler.rb +5 -5
- data/lib/new_relic/agent/transaction_time_aggregator.rb +14 -14
- data/lib/new_relic/agent/utilization/aws.rb +4 -4
- data/lib/new_relic/agent/utilization/azure.rb +2 -2
- data/lib/new_relic/agent/utilization/gcp.rb +7 -7
- data/lib/new_relic/agent/utilization/pcf.rb +4 -4
- data/lib/new_relic/agent/utilization/vendor.rb +28 -28
- data/lib/new_relic/agent/utilization_data.rb +1 -1
- data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
- data/lib/new_relic/agent/vm/mri_vm.rb +36 -23
- data/lib/new_relic/agent/vm/snapshot.rb +2 -2
- data/lib/new_relic/agent/vm.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +2 -2
- data/lib/new_relic/agent.rb +27 -27
- data/lib/new_relic/cli/command.rb +6 -6
- data/lib/new_relic/cli/commands/deployments.rb +81 -29
- data/lib/new_relic/cli/commands/install.rb +6 -6
- data/lib/new_relic/coerce.rb +5 -6
- data/lib/new_relic/collection_helper.rb +4 -4
- data/lib/new_relic/constants.rb +0 -1
- data/lib/new_relic/control/class_methods.rb +1 -1
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +3 -3
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/control/frameworks/rails4.rb +1 -1
- data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
- data/lib/new_relic/control/frameworks/ruby.rb +1 -1
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
- data/lib/new_relic/control/frameworks.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +20 -42
- data/lib/new_relic/control/instrumentation.rb +7 -7
- data/lib/new_relic/control/private_instance_methods.rb +48 -0
- data/lib/new_relic/control/server_methods.rb +2 -2
- data/lib/new_relic/control.rb +1 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/dependency_detection.rb +23 -22
- data/lib/new_relic/environment_report.rb +24 -14
- data/lib/new_relic/helper.rb +5 -5
- data/lib/new_relic/language_support.rb +8 -3
- data/lib/new_relic/latest_changes.rb +4 -4
- data/lib/new_relic/local_environment.rb +9 -11
- data/lib/new_relic/metric_data.rb +30 -24
- data/lib/new_relic/metric_spec.rb +3 -3
- data/lib/new_relic/noticed_error.rb +3 -6
- data/lib/new_relic/rack/agent_hooks.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +132 -123
- data/lib/new_relic/rack.rb +1 -1
- data/lib/new_relic/recipes/capistrano3.rb +3 -59
- data/lib/new_relic/recipes/capistrano_legacy.rb +13 -13
- data/lib/new_relic/recipes/helpers/send_deployment.rb +69 -0
- data/lib/new_relic/recipes.rb +1 -1
- data/lib/new_relic/supportability_helper.rb +6 -6
- data/lib/new_relic/traced_thread.rb +5 -7
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +8 -8
- data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/config.rake +8 -112
- data/lib/tasks/coverage_report.rake +28 -0
- data/lib/tasks/{config.html.erb → helpers/config.html.erb} +0 -0
- data/lib/tasks/{config.text.erb → helpers/config.text.erb} +0 -0
- data/lib/tasks/helpers/format.rb +120 -0
- data/lib/tasks/helpers/matches.rb +12 -0
- data/lib/tasks/helpers/prompt.rb +24 -0
- data/lib/tasks/helpers/removers.rb +33 -0
- data/lib/tasks/install.rake +4 -0
- data/lib/tasks/instrumentation_generator/README.md +63 -0
- data/lib/tasks/instrumentation_generator/TODO.md +33 -0
- data/lib/tasks/instrumentation_generator/instrumentation.thor +102 -0
- data/lib/tasks/instrumentation_generator/templates/Envfile.tt +9 -0
- data/lib/tasks/instrumentation_generator/templates/chain.tt +21 -0
- data/lib/tasks/instrumentation_generator/templates/chain_method.tt +7 -0
- data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +29 -0
- data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +12 -0
- data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +3 -0
- data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +19 -0
- data/lib/tasks/instrumentation_generator/templates/prepend.tt +13 -0
- data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +3 -0
- data/lib/tasks/instrumentation_generator/templates/test.tt +15 -0
- data/lib/tasks/multiverse.rake +4 -0
- data/lib/tasks/multiverse.rb +5 -30
- data/lib/tasks/newrelic.rb +1 -1
- data/lib/tasks/tests.rake +7 -8
- data/newrelic.yml +514 -483
- data/newrelic_rpm.gemspec +16 -21
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +125 -147
- metadata +82 -90
- data/bin/mongrel_rpm +0 -32
@@ -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
|
require 'new_relic/coerce'
|
6
6
|
|
@@ -8,9 +8,11 @@ module NewRelic
|
|
8
8
|
class MetricData
|
9
9
|
# a NewRelic::MetricSpec object
|
10
10
|
attr_reader :metric_spec
|
11
|
-
#
|
11
|
+
# a NewRelic::Agent::Stats object
|
12
12
|
attr_accessor :stats
|
13
13
|
|
14
|
+
include NewRelic::Coerce
|
15
|
+
|
14
16
|
def initialize(metric_spec, stats)
|
15
17
|
@original_spec = nil
|
16
18
|
@metric_spec = metric_spec
|
@@ -18,22 +20,31 @@ module NewRelic
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def eql?(o)
|
21
|
-
(metric_spec.eql?
|
23
|
+
(metric_spec.eql?(o.metric_spec)) && (stats.eql?(o.stats))
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
+
def hash
|
27
|
+
[metric_spec, stats].hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}>"
|
26
32
|
end
|
27
33
|
|
28
34
|
# assigns a new metric spec, and retains the old metric spec as
|
29
35
|
# @original_spec if it exists currently
|
30
|
-
def metric_spec=
|
36
|
+
def metric_spec=(new_spec)
|
31
37
|
@original_spec = @metric_spec if @metric_spec
|
32
38
|
@metric_spec = new_spec
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
36
|
-
|
41
|
+
def original_spec
|
42
|
+
@original_spec || @metric_spec
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_collector_array(encoder = nil)
|
46
|
+
stat_key = {'name' => metric_spec.name, 'scope' => metric_spec.scope}
|
47
|
+
[stat_key, stats_collector_array(stat_key)]
|
37
48
|
end
|
38
49
|
|
39
50
|
def to_json(*a)
|
@@ -44,23 +55,18 @@ module NewRelic
|
|
44
55
|
"#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
|
45
56
|
end
|
46
57
|
|
47
|
-
|
48
|
-
"#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}>"
|
49
|
-
end
|
50
|
-
|
51
|
-
include NewRelic::Coerce
|
58
|
+
private
|
52
59
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
[
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
float(stats.
|
61
|
-
|
62
|
-
|
63
|
-
]]
|
60
|
+
def stats_collector_array(stat_key)
|
61
|
+
[[:call_count, Integer], [:total_call_time, Float],
|
62
|
+
[:total_exclusive_time, Float], [:min_call_time, Float],
|
63
|
+
[:max_call_time, Float], [:sum_of_squares, Float]].map do |attr_types|
|
64
|
+
if attr_types[1].eql?(Integer)
|
65
|
+
int(stats.send(attr_types[0]), stat_key)
|
66
|
+
elsif attr_types[1].eql?(Float)
|
67
|
+
float(stats.send(attr_types[0]), stat_key)
|
68
|
+
end
|
69
|
+
end
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
@@ -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
|
# this struct uniquely defines a metric, optionally inside
|
6
6
|
# the call scope of another metric
|
@@ -34,12 +34,12 @@ class NewRelic::MetricSpec
|
|
34
34
|
self.eql?(o)
|
35
35
|
end
|
36
36
|
|
37
|
-
def eql?
|
37
|
+
def eql?(o)
|
38
38
|
@name == o.name && @scope == o.scope
|
39
39
|
end
|
40
40
|
|
41
41
|
def hash
|
42
|
-
@name
|
42
|
+
[@name, @scope].hash
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_s
|
@@ -1,4 +1,3 @@
|
|
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.
|
4
3
|
# frozen_string_literal: true
|
@@ -135,10 +134,8 @@ class NewRelic::NoticedError
|
|
135
134
|
|
136
135
|
def build_error_attributes
|
137
136
|
@attributes_from_notice_error ||= {}
|
138
|
-
@attributes_from_notice_error
|
139
|
-
|
140
|
-
ERROR_CLASS_KEY => string(exception_class_name)
|
141
|
-
})
|
137
|
+
@attributes_from_notice_error[ERROR_MESSAGE_KEY] = string(message)
|
138
|
+
@attributes_from_notice_error[ERROR_CLASS_KEY] = string(exception_class_name)
|
142
139
|
|
143
140
|
@attributes_from_notice_error[ERROR_EXPECTED_KEY] = true if expected
|
144
141
|
end
|
@@ -189,7 +186,7 @@ class NewRelic::NoticedError
|
|
189
186
|
if exception.nil?
|
190
187
|
@exception_class_name = UNKNOWN_ERROR_CLASS_NAME
|
191
188
|
@message = NIL_ERROR_MESSAGE
|
192
|
-
elsif exception.is_a?
|
189
|
+
elsif exception.is_a?(NewRelic::Agent::NoticeableError)
|
193
190
|
@exception_class_name = exception.class_name
|
194
191
|
@message = exception.message
|
195
192
|
else
|
@@ -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
|
require 'new_relic/agent/event_listener'
|
6
6
|
require 'new_relic/rack/agent_middleware'
|
@@ -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
|
require 'new_relic/agent/tracer'
|
6
6
|
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
@@ -1,157 +1,166 @@
|
|
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
|
require 'rack'
|
6
6
|
require 'new_relic/rack/agent_middleware'
|
7
7
|
require 'new_relic/agent/instrumentation/middleware_proxy'
|
8
8
|
|
9
|
-
module NewRelic
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
9
|
+
module NewRelic
|
10
|
+
module Rack
|
11
|
+
# This middleware is used by the agent for the Real user monitoring (RUM)
|
12
|
+
# feature, and will usually be automatically injected in the middleware chain.
|
13
|
+
# If automatic injection is not working, you may manually use it in your
|
14
|
+
# middleware chain instead.
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
#
|
18
|
+
class BrowserMonitoring < AgentMiddleware
|
19
|
+
# The maximum number of bytes of the response body that we will
|
20
|
+
# examine in order to look for a RUM insertion point.
|
21
|
+
SCAN_LIMIT = 50_000
|
22
|
+
|
23
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
24
|
+
CONTENT_DISPOSITION = 'Content-Disposition'.freeze
|
25
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
26
|
+
ATTACHMENT = 'attachment'.freeze
|
27
|
+
TEXT_HTML = 'text/html'.freeze
|
28
|
+
|
29
|
+
BODY_START = "<body".freeze
|
30
|
+
HEAD_START = "<head".freeze
|
31
|
+
GT = ">".freeze
|
32
|
+
|
33
|
+
ALREADY_INSTRUMENTED_KEY = "newrelic.browser_monitoring_already_instrumented"
|
34
|
+
CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
|
35
|
+
X_UA_COMPATIBLE_RE = /<\s*meta[^>]+http-equiv\s*=\s*['"]x-ua-compatible['"][^>]*>/im.freeze
|
36
|
+
|
37
|
+
def traced_call(env)
|
38
|
+
result = @app.call(env)
|
39
|
+
(status, headers, response) = result
|
40
|
+
|
41
|
+
js_to_inject = NewRelic::Agent.browser_timing_header
|
42
|
+
if (js_to_inject != NewRelic::EMPTY_STR) && should_instrument?(env, status, headers)
|
43
|
+
response_string = autoinstrument_source(response, headers, js_to_inject)
|
44
|
+
if headers.key?(CONTENT_LENGTH)
|
45
|
+
content_length = response_string ? response_string.bytesize : 0
|
46
|
+
headers[CONTENT_LENGTH] = content_length.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
env[ALREADY_INSTRUMENTED_KEY] = true
|
50
|
+
if response_string
|
51
|
+
response = ::Rack::Response.new(response_string, status, headers)
|
52
|
+
response.finish
|
53
|
+
else
|
54
|
+
result
|
55
|
+
end
|
48
56
|
else
|
49
57
|
result
|
50
58
|
end
|
51
|
-
else
|
52
|
-
result
|
53
59
|
end
|
54
|
-
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
!is_streaming?(env, headers)
|
65
|
-
end
|
66
|
-
|
67
|
-
def is_html?(headers)
|
68
|
-
headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML)
|
69
|
-
end
|
70
|
-
|
71
|
-
def is_attachment?(headers)
|
72
|
-
headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
|
73
|
-
end
|
61
|
+
def should_instrument?(env, status, headers)
|
62
|
+
NewRelic::Agent.config[:'browser_monitoring.auto_instrument'] &&
|
63
|
+
status == 200 &&
|
64
|
+
!env[ALREADY_INSTRUMENTED_KEY] &&
|
65
|
+
html?(headers) &&
|
66
|
+
!attachment?(headers) &&
|
67
|
+
!streaming?(env, headers)
|
68
|
+
end
|
74
69
|
|
75
|
-
|
76
|
-
|
70
|
+
private
|
71
|
+
|
72
|
+
def autoinstrument_source(response, headers, js_to_inject)
|
73
|
+
source = gather_source(response)
|
74
|
+
close_old_response(response)
|
75
|
+
return nil unless source
|
76
|
+
|
77
|
+
# Only scan the first 50k (roughly) then give up.
|
78
|
+
beginning_of_source = source[0..SCAN_LIMIT]
|
79
|
+
meta_tag_positions = find_meta_tag_positions(beginning_of_source)
|
80
|
+
if body_start = find_body_start(beginning_of_source)
|
81
|
+
if insertion_index = find_insertion_index(meta_tag_positions, beginning_of_source, body_start)
|
82
|
+
source = source_injection(source, insertion_index, js_to_inject)
|
83
|
+
else
|
84
|
+
NewRelic::Agent.logger.debug("Skipping RUM instrumentation. Could not properly determine location to inject script.")
|
85
|
+
end
|
86
|
+
else
|
87
|
+
msg = "Skipping RUM instrumentation. Unable to find <body> tag in first #{SCAN_LIMIT} bytes of document."
|
88
|
+
NewRelic::Agent.logger.log_once(:warn, :rum_insertion_failure, msg)
|
89
|
+
NewRelic::Agent.logger.debug(msg)
|
90
|
+
end
|
77
91
|
|
78
|
-
|
79
|
-
|
80
|
-
|
92
|
+
source
|
93
|
+
rescue => e
|
94
|
+
NewRelic::Agent.logger.debug("Skipping RUM instrumentation on exception.", e)
|
95
|
+
nil
|
96
|
+
end
|
81
97
|
|
82
|
-
|
83
|
-
|
98
|
+
def html?(headers)
|
99
|
+
headers[CONTENT_TYPE] && headers[CONTENT_TYPE].include?(TEXT_HTML)
|
100
|
+
end
|
84
101
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return nil unless source
|
102
|
+
def attachment?(headers)
|
103
|
+
headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
|
104
|
+
end
|
89
105
|
|
90
|
-
|
91
|
-
|
106
|
+
def streaming?(env, headers)
|
107
|
+
return true if headers && headers['Transfer-Encoding'] == 'chunked'
|
92
108
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
find_charset_position(beginning_of_source)
|
97
|
-
].compact
|
109
|
+
defined?(ActionController::Live) &&
|
110
|
+
env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
|
111
|
+
end
|
98
112
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
insertion_index
|
103
|
-
|
113
|
+
def source_injection(source, insertion_index, js_to_inject)
|
114
|
+
source[0...insertion_index] <<
|
115
|
+
js_to_inject <<
|
116
|
+
source[insertion_index..-1]
|
117
|
+
end
|
104
118
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
source[insertion_index..-1]
|
119
|
+
def find_insertion_index(tag_positions, source_beginning, body_start)
|
120
|
+
if !tag_positions.empty?
|
121
|
+
tag_positions.max
|
109
122
|
else
|
110
|
-
|
123
|
+
find_end_of_head_open(source_beginning) || body_start
|
111
124
|
end
|
112
|
-
else
|
113
|
-
msg = "Skipping RUM instrumentation. Unable to find <body> tag in first #{SCAN_LIMIT} bytes of document."
|
114
|
-
NewRelic::Agent.logger.log_once(:warn, :rum_insertion_failure, msg)
|
115
|
-
NewRelic::Agent.logger.debug(msg)
|
116
125
|
end
|
117
126
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
127
|
+
def find_meta_tag_positions(source_beginning)
|
128
|
+
[
|
129
|
+
find_x_ua_compatible_position(source_beginning),
|
130
|
+
find_charset_position(source_beginning)
|
131
|
+
].compact
|
132
|
+
end
|
123
133
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
134
|
+
def gather_source(response)
|
135
|
+
source = nil
|
136
|
+
response.each { |fragment| source ? (source << fragment.to_s) : (source = fragment.to_s) }
|
137
|
+
source
|
138
|
+
end
|
129
139
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
response.close
|
140
|
+
# Per "The Response > The Body" section of Rack spec, we should close
|
141
|
+
# if our response is able. http://rack.rubyforge.org/doc/SPEC.html
|
142
|
+
def close_old_response(response)
|
143
|
+
response.close if response.respond_to?(:close)
|
135
144
|
end
|
136
|
-
end
|
137
145
|
|
138
|
-
|
139
|
-
|
140
|
-
|
146
|
+
def find_body_start(beginning_of_source)
|
147
|
+
beginning_of_source.index(BODY_START)
|
148
|
+
end
|
141
149
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
150
|
+
def find_x_ua_compatible_position(beginning_of_source)
|
151
|
+
match = X_UA_COMPATIBLE_RE.match(beginning_of_source)
|
152
|
+
match.end(0) if match
|
153
|
+
end
|
146
154
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
155
|
+
def find_charset_position(beginning_of_source)
|
156
|
+
match = CHARSET_RE.match(beginning_of_source)
|
157
|
+
match.end(0) if match
|
158
|
+
end
|
151
159
|
|
152
|
-
|
153
|
-
|
154
|
-
|
160
|
+
def find_end_of_head_open(beginning_of_source)
|
161
|
+
head_open = beginning_of_source.index(HEAD_START)
|
162
|
+
beginning_of_source.index(GT, head_open) + 1 if head_open
|
163
|
+
end
|
155
164
|
end
|
156
165
|
end
|
157
166
|
end
|
data/lib/new_relic/rack.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
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
|
require 'capistrano/framework'
|
6
|
+
require_relative 'helpers/send_deployment'
|
6
7
|
|
7
8
|
namespace :newrelic do
|
9
|
+
include SendDeployment
|
8
10
|
# notifies New Relic of a deployment
|
9
11
|
desc "Record a deployment in New Relic (newrelic.com)"
|
10
12
|
task :notice_deployment do
|
@@ -18,62 +20,4 @@ namespace :newrelic do
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
22
|
-
def send_deployment_notification_to_newrelic
|
23
|
-
environment = fetch(:newrelic_rails_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage, "production"))))
|
24
|
-
|
25
|
-
require 'new_relic/cli/command'
|
26
|
-
|
27
|
-
begin
|
28
|
-
# allow overrides to be defined for revision, description, changelog, appname, and user
|
29
|
-
rev = fetch(:newrelic_revision)
|
30
|
-
description = fetch(:newrelic_desc)
|
31
|
-
changelog = fetch(:newrelic_changelog)
|
32
|
-
appname = fetch(:newrelic_appname)
|
33
|
-
user = fetch(:newrelic_user)
|
34
|
-
license_key = fetch(:newrelic_license_key)
|
35
|
-
|
36
|
-
has_scm_from_plugin = respond_to?(:scm_plugin_installed?) && scm_plugin_installed?
|
37
|
-
has_scm_from_config = defined?(scm) && !scm.nil? && scm != :none
|
38
|
-
|
39
|
-
if has_scm_from_plugin || has_scm_from_config
|
40
|
-
changelog ||= lookup_changelog
|
41
|
-
rev ||= fetch(:current_revision)
|
42
|
-
end
|
43
|
-
|
44
|
-
new_revision = rev
|
45
|
-
deploy_options = {
|
46
|
-
:environment => environment,
|
47
|
-
:revision => new_revision,
|
48
|
-
:changelog => changelog,
|
49
|
-
:description => description,
|
50
|
-
:appname => appname,
|
51
|
-
:user => user,
|
52
|
-
:license_key => license_key
|
53
|
-
}
|
54
|
-
|
55
|
-
debug "Uploading deployment to New Relic"
|
56
|
-
deployment = NewRelic::Cli::Deployments.new deploy_options
|
57
|
-
deployment.run
|
58
|
-
info "Uploaded deployment information to New Relic"
|
59
|
-
rescue NewRelic::Cli::Command::CommandFailure => e
|
60
|
-
info e.message
|
61
|
-
rescue => e
|
62
|
-
info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def lookup_changelog
|
67
|
-
previous_revision = fetch(:previous_revision)
|
68
|
-
current_revision = fetch(:current_revision)
|
69
|
-
return unless current_revision && previous_revision
|
70
|
-
|
71
|
-
debug "Retrieving changelog for New Relic Deployment details"
|
72
|
-
|
73
|
-
if Rake::Task.task_defined?("git:check")
|
74
|
-
log_command = "git --no-pager log --no-color --pretty=format:' * %an: %s' " +
|
75
|
-
"--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
|
76
|
-
`#{log_command}`
|
77
|
-
end
|
78
|
-
end
|
79
23
|
end
|
@@ -1,12 +1,12 @@
|
|
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
|
-
make_notify_task =
|
6
|
-
namespace
|
5
|
+
make_notify_task = proc do
|
6
|
+
namespace(:newrelic) do
|
7
7
|
# on all deployments, notify New Relic
|
8
|
-
desc
|
9
|
-
task
|
8
|
+
desc("Record a deployment in New Relic (newrelic.com)")
|
9
|
+
task(:notice_deployment, :roles => :app, :except => {:no_release => true}) do
|
10
10
|
rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
|
11
11
|
|
12
12
|
require 'new_relic/cli/command'
|
@@ -36,22 +36,22 @@ make_notify_task = Proc.new do
|
|
36
36
|
:license_key => license_key
|
37
37
|
}
|
38
38
|
|
39
|
-
logger.debug
|
40
|
-
deployment = NewRelic::Cli::Deployments.new
|
39
|
+
logger.debug("Uploading deployment to New Relic")
|
40
|
+
deployment = NewRelic::Cli::Deployments.new(deploy_options)
|
41
41
|
deployment.run
|
42
|
-
logger.info
|
42
|
+
logger.info("Uploaded deployment information to New Relic")
|
43
43
|
rescue NewRelic::Cli::Command::CommandFailure => e
|
44
|
-
logger.info
|
44
|
+
logger.info(e.message)
|
45
45
|
rescue Capistrano::CommandError
|
46
|
-
logger.info
|
46
|
+
logger.info("Unable to notify New Relic of the deployment... skipping")
|
47
47
|
rescue => e
|
48
|
-
logger.info
|
48
|
+
logger.info("Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def lookup_changelog(changelog)
|
53
53
|
if !changelog
|
54
|
-
logger.debug
|
54
|
+
logger.debug("Getting log of changes for New Relic Deployment details")
|
55
55
|
from_revision = source.next_revision(current_revision)
|
56
56
|
|
57
57
|
if scm == :git
|
@@ -69,7 +69,7 @@ make_notify_task = Proc.new do
|
|
69
69
|
def lookup_rev(rev)
|
70
70
|
if rev.nil?
|
71
71
|
rev = source.query_revision(source.head()) do |cmd|
|
72
|
-
logger.debug
|
72
|
+
logger.debug("executing locally: '#{cmd}'")
|
73
73
|
`#{cmd}`
|
74
74
|
end
|
75
75
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# This file is distributed under New Relic's license terms.
|
2
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
module SendDeployment
|
6
|
+
def send_deployment_notification_to_newrelic
|
7
|
+
require 'new_relic/cli/command'
|
8
|
+
debug("Uploading deployment to New Relic")
|
9
|
+
NewRelic::Cli::Deployments.new(deploy_options).run
|
10
|
+
info("Uploaded deployment information to New Relic")
|
11
|
+
rescue NewRelic::Cli::Command::CommandFailure => e
|
12
|
+
info(e.message)
|
13
|
+
rescue => e
|
14
|
+
info("Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def deploy_options
|
20
|
+
{
|
21
|
+
:environment => fetch_environment,
|
22
|
+
:revision => fetch_rev,
|
23
|
+
:changelog => fetch_changelog,
|
24
|
+
:description => fetch(:newrelic_desc),
|
25
|
+
:appname => fetch(:newrelic_appname),
|
26
|
+
:user => fetch(:newrelic_user),
|
27
|
+
:license_key => fetch(:newrelic_license_key)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_changelog
|
32
|
+
has_scm? ? fetch(:newrelic_changelog) : lookup_changelog
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_environment
|
36
|
+
fetch(:newrelic_rails_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage, "production"))))
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_rev
|
40
|
+
newrelic_rev = fetch(:newrelic_revision)
|
41
|
+
has_scm? && !newrelic_rev ? fetch(:current_revision) : newrelic_rev
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_scm?
|
45
|
+
has_scm_from_plugin? || has_scm_from_config?
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_scm_from_config?
|
49
|
+
defined?(scm) && !scm.nil? && scm != :none
|
50
|
+
end
|
51
|
+
|
52
|
+
def has_scm_from_plugin?
|
53
|
+
respond_to?(:scm_plugin_installed?) && scm_plugin_installed?
|
54
|
+
end
|
55
|
+
|
56
|
+
def lookup_changelog
|
57
|
+
previous_revision = fetch(:previous_revision)
|
58
|
+
current_revision = fetch(:current_revision)
|
59
|
+
return unless current_revision && previous_revision
|
60
|
+
|
61
|
+
debug("Retrieving changelog for New Relic Deployment details")
|
62
|
+
|
63
|
+
if Rake::Task.task_defined?("git:check")
|
64
|
+
log_command = "git --no-pager log --no-color --pretty=format:' * %an: %s' " +
|
65
|
+
"--abbrev-commit --no-merges #{previous_revision}..#{current_revision}"
|
66
|
+
`#{log_command}`
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|