newrelic_rpm 5.5.0.348 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +931 -0
- data/CONTRIBUTING.md +117 -19
- data/Gemfile +6 -2
- data/Guardfile +18 -1
- data/LICENSE +208 -38
- data/README.md +80 -84
- data/ROADMAP.md +24 -0
- data/Rakefile +2 -0
- data/THIRD_PARTY_NOTICES.md +213 -0
- data/bin/nrdebug +1 -1
- data/config.dot +1 -0
- data/init.rb +1 -1
- data/install.rb +1 -1
- data/lib/new_relic/agent.rb +111 -20
- data/lib/new_relic/agent/adaptive_sampler.rb +1 -1
- data/lib/new_relic/agent/agent.rb +182 -194
- data/lib/new_relic/agent/agent_logger.rb +5 -1
- data/lib/new_relic/agent/attribute_filter.rb +85 -25
- data/lib/new_relic/agent/attribute_processing.rb +1 -1
- data/lib/new_relic/agent/attributes.rb +152 -0
- data/lib/new_relic/agent/audit_logger.rb +11 -1
- data/lib/new_relic/agent/autostart.rb +19 -15
- data/lib/new_relic/agent/chained_call.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command_router.rb +3 -22
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
- data/lib/new_relic/agent/configuration.rb +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +656 -188
- data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
- data/lib/new_relic/agent/configuration/environment_source.rb +5 -3
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
- data/lib/new_relic/agent/configuration/high_security_source.rb +2 -1
- data/lib/new_relic/agent/configuration/manager.rb +17 -13
- data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
- data/lib/new_relic/agent/configuration/security_policy_source.rb +15 -1
- data/lib/new_relic/agent/configuration/server_source.rb +39 -4
- data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
- data/lib/new_relic/agent/connect/request_builder.rb +63 -0
- data/lib/new_relic/agent/connect/response_handler.rb +61 -0
- data/lib/new_relic/agent/custom_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/database.rb +2 -3
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
- data/lib/new_relic/agent/database/obfuscator.rb +1 -1
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
- data/lib/new_relic/agent/database_adapter.rb +33 -0
- data/lib/new_relic/agent/datastores.rb +7 -9
- data/lib/new_relic/agent/datastores/metric_helper.rb +2 -3
- data/lib/new_relic/agent/datastores/mongo.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +1 -5
- data/lib/new_relic/agent/deprecator.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing.rb +115 -32
- data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +3 -2
- data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +61 -46
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
- data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +32 -113
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
- data/lib/new_relic/agent/error_collector.rb +88 -58
- data/lib/new_relic/agent/error_event_aggregator.rb +10 -7
- data/lib/new_relic/agent/error_filter.rb +167 -0
- data/lib/new_relic/agent/error_trace_aggregator.rb +2 -1
- data/lib/new_relic/agent/event_aggregator.rb +27 -33
- data/lib/new_relic/agent/event_buffer.rb +1 -1
- data/lib/new_relic/agent/event_listener.rb +1 -1
- data/lib/new_relic/agent/event_loop.rb +1 -1
- data/lib/new_relic/agent/external.rb +13 -11
- data/lib/new_relic/agent/guid_generator.rb +28 -0
- data/lib/new_relic/agent/harvester.rb +1 -1
- data/lib/new_relic/agent/heap.rb +1 -1
- data/lib/new_relic/agent/hostname.rb +16 -2
- data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
- data/lib/new_relic/agent/http_clients/uri_util.rb +12 -11
- data/lib/new_relic/agent/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +26 -43
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +53 -73
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +81 -56
- data/lib/new_relic/agent/instrumentation/active_job.rb +7 -8
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +17 -6
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +152 -0
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +35 -11
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +47 -51
- data/lib/new_relic/agent/instrumentation/active_storage.rb +23 -0
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +63 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +10 -9
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/bunny.rb +13 -132
- data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
- data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +11 -4
- data/lib/new_relic/agent/instrumentation/curb.rb +11 -183
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +5 -3
- data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
- data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +9 -49
- data/lib/new_relic/agent/instrumentation/excon.rb +4 -3
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +8 -5
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
- data/lib/new_relic/agent/instrumentation/grape.rb +14 -107
- data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
- data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
- data/lib/new_relic/agent/instrumentation/httpclient.rb +10 -30
- data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
- data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
- data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
- data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
- data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +55 -68
- data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +39 -118
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
- data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -2
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +20 -11
- data/lib/new_relic/agent/instrumentation/mongo.rb +17 -4
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +36 -3
- data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
- data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
- data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +100 -0
- data/lib/new_relic/agent/instrumentation/padrino.rb +19 -52
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
- data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rack.rb +30 -138
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +58 -0
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +37 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
- data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_cable.rb +6 -7
- data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_controller.rb +4 -4
- data/lib/new_relic/agent/instrumentation/{rails4 → rails_notifications}/action_view.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rake.rb +14 -155
- data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
- data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
- data/lib/new_relic/agent/instrumentation/redis.rb +13 -102
- data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
- data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
- data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +22 -30
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
- data/lib/new_relic/agent/instrumentation/sequel.rb +2 -2
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
- data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -160
- data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +30 -35
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
- data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +12 -74
- data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
- data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +15 -10
- data/lib/new_relic/agent/log_once.rb +1 -1
- data/lib/new_relic/agent/logging.rb +139 -0
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +15 -82
- data/lib/new_relic/agent/method_tracer.rb +10 -8
- data/lib/new_relic/agent/method_tracer_helpers.rb +5 -5
- data/lib/new_relic/agent/monitors.rb +27 -0
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
- data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +4 -4
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +4 -7
- data/lib/new_relic/agent/new_relic_service.rb +106 -40
- data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -2
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +6 -27
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/null_logger.rb +1 -1
- data/lib/new_relic/agent/obfuscator.rb +1 -1
- data/lib/new_relic/agent/parameter_filtering.rb +19 -6
- data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/pipe_service.rb +1 -1
- data/lib/new_relic/agent/prepend_supportability.rb +1 -1
- data/lib/new_relic/agent/priority_sampled_buffer.rb +9 -4
- data/lib/new_relic/agent/range_extensions.rb +1 -1
- data/lib/new_relic/agent/rules_engine.rb +1 -1
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
- data/lib/new_relic/agent/sampler.rb +1 -1
- data/lib/new_relic/agent/sampler_collection.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -2
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
- data/lib/new_relic/agent/span_event_aggregator.rb +3 -5
- data/lib/new_relic/agent/span_event_primitive.rb +129 -65
- data/lib/new_relic/agent/sql_sampler.rb +12 -12
- data/lib/new_relic/agent/stats.rb +1 -1
- data/lib/new_relic/agent/stats_engine.rb +3 -3
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +2 -2
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
- data/lib/new_relic/agent/supported_versions.rb +3 -3
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/system_info.rb +18 -4
- data/lib/new_relic/agent/threading/agent_thread.rb +2 -2
- data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_service.rb +4 -4
- data/lib/new_relic/agent/threading/thread_profile.rb +10 -24
- data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
- data/lib/new_relic/agent/tracer.rb +509 -0
- data/lib/new_relic/agent/transaction.rb +143 -171
- data/lib/new_relic/agent/transaction/abstract_segment.rb +33 -6
- data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -3
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +177 -0
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +59 -149
- data/lib/new_relic/agent/transaction/external_request_segment.rb +32 -39
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -12
- data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
- data/lib/new_relic/agent/transaction/segment.rb +28 -2
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/trace.rb +6 -13
- data/lib/new_relic/agent/transaction/trace_builder.rb +1 -2
- data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +12 -8
- data/lib/new_relic/agent/transaction/tracing.rb +1 -100
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction_error_primitive.rb +11 -16
- data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/transaction_event_primitive.rb +29 -40
- data/lib/new_relic/agent/transaction_event_recorder.rb +4 -4
- data/lib/new_relic/agent/transaction_metrics.rb +1 -1
- data/lib/new_relic/agent/transaction_sampler.rb +2 -6
- data/lib/new_relic/agent/transaction_time_aggregator.rb +50 -26
- data/lib/new_relic/agent/utilization/aws.rb +1 -1
- data/lib/new_relic/agent/utilization/azure.rb +1 -1
- data/lib/new_relic/agent/utilization/gcp.rb +1 -1
- data/lib/new_relic/agent/utilization/pcf.rb +1 -1
- data/lib/new_relic/agent/utilization/vendor.rb +1 -1
- data/lib/new_relic/agent/utilization_data.rb +37 -2
- data/lib/new_relic/agent/vm.rb +1 -1
- data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
- data/lib/new_relic/agent/vm/mri_vm.rb +7 -5
- data/lib/new_relic/agent/vm/snapshot.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/cli/command.rb +1 -1
- data/lib/new_relic/cli/commands/deployments.rb +2 -3
- data/lib/new_relic/cli/commands/install.rb +4 -3
- data/lib/new_relic/coerce.rb +32 -7
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/constants.rb +42 -0
- data/lib/new_relic/control.rb +1 -1
- data/lib/new_relic/control/class_methods.rb +8 -2
- data/lib/new_relic/control/frameworks.rb +1 -1
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/merb.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +12 -10
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/control/frameworks/rails4.rb +1 -1
- data/lib/new_relic/control/frameworks/{rails5.rb → rails_notifications.rb} +2 -2
- data/lib/new_relic/control/frameworks/ruby.rb +1 -1
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +12 -2
- data/lib/new_relic/control/instrumentation.rb +1 -1
- data/lib/new_relic/control/server_methods.rb +1 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/dependency_detection.rb +124 -14
- data/lib/new_relic/environment_report.rb +2 -4
- data/lib/new_relic/helper.rb +1 -1
- data/lib/new_relic/language_support.rb +1 -1
- data/lib/new_relic/latest_changes.rb +4 -4
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/metric_spec.rb +1 -1
- data/lib/new_relic/noticed_error.rb +38 -21
- data/lib/new_relic/rack.rb +1 -1
- data/lib/new_relic/rack/agent_hooks.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +2 -2
- data/lib/new_relic/rack/browser_monitoring.rb +16 -9
- data/lib/new_relic/recipes.rb +1 -1
- data/lib/new_relic/recipes/capistrano3.rb +1 -1
- data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
- data/lib/new_relic/supportability_helper.rb +16 -1
- data/lib/new_relic/version.rb +3 -3
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
- data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/config.html.erb +14 -25
- data/lib/tasks/config.rake +9 -9
- data/lib/tasks/multiverse.rb +35 -1
- data/lib/tasks/newrelic.rb +1 -1
- data/lib/tasks/tests.rake +6 -1
- data/newrelic_rpm.gemspec +22 -17
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +358 -78
- metadata +151 -66
- data/.travis.yml +0 -201
- data/cert/cacert.pem +0 -1177
- data/lib/new_relic/agent/commands/xray_session.rb +0 -55
- data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
- data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
- data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -41
- data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
- data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
- data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -41
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
- data/lib/new_relic/agent/instrumentation/http.rb +0 -46
- data/lib/new_relic/agent/instrumentation/net.rb +0 -50
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
- data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
- data/lib/new_relic/agent/transaction/attributes.rb +0 -154
- data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
- data/lib/new_relic/agent/transaction_state.rb +0 -186
- data/lib/new_relic/build.rb +0 -2
- data/lib/new_relic/metrics.rb +0 -13
- data/lib/tasks/versions.html.erb +0 -28
- data/lib/tasks/versions.postface.html +0 -8
- data/lib/tasks/versions.preface.html +0 -9
- data/lib/tasks/versions.rake +0 -65
- data/lib/tasks/versions.txt.erb +0 -14
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
module NewRelic
|
6
6
|
module Agent
|
@@ -21,11 +21,18 @@ module NewRelic
|
|
21
21
|
@entry_timestamp = relative_start
|
22
22
|
@metric_name = metric_name || UNKNOWN_NODE_NAME
|
23
23
|
@exit_timestamp = relative_end
|
24
|
-
@children
|
25
|
-
@params = params
|
24
|
+
@children = nil
|
25
|
+
@params = select_allowed_params(params)
|
26
26
|
@parent_node = parent
|
27
27
|
end
|
28
28
|
|
29
|
+
def select_allowed_params params
|
30
|
+
return unless params
|
31
|
+
params.select do |p|
|
32
|
+
NewRelic::Agent.instance.attribute_filter.allows_key? p, AttributeFilter::DST_TRANSACTION_SEGMENTS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
# sets the final timestamp on a node to indicate the exit
|
30
37
|
# point of the node
|
31
38
|
def end_trace(timestamp)
|
@@ -36,16 +43,13 @@ module NewRelic
|
|
36
43
|
to_debug_str(0)
|
37
44
|
end
|
38
45
|
|
39
|
-
EMPTY_HASH = {}.freeze
|
40
|
-
EMPTY_ARRAY = [].freeze
|
41
|
-
|
42
46
|
def to_array
|
43
|
-
params = @params ? @params : EMPTY_HASH
|
47
|
+
params = @params ? @params : NewRelic::EMPTY_HASH
|
44
48
|
[ NewRelic::Helper.time_to_millis(@entry_timestamp),
|
45
49
|
NewRelic::Helper.time_to_millis(@exit_timestamp),
|
46
50
|
NewRelic::Coerce.string(@metric_name),
|
47
51
|
params ] +
|
48
|
-
[ (@children ? @children.map{|s| s.to_array} : EMPTY_ARRAY) ]
|
52
|
+
[ (@children ? @children.map{|s| s.to_array} : NewRelic::EMPTY_ARRAY) ]
|
49
53
|
end
|
50
54
|
|
51
55
|
def path_string
|
@@ -1,110 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
4
|
-
|
5
|
-
require 'new_relic/agent/transaction/segment'
|
6
|
-
require 'new_relic/agent/transaction/datastore_segment'
|
7
|
-
require 'new_relic/agent/transaction/external_request_segment'
|
8
|
-
require 'new_relic/agent/transaction/message_broker_segment'
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
9
4
|
|
10
5
|
module NewRelic
|
11
6
|
module Agent
|
12
7
|
class Transaction
|
13
8
|
module Tracing
|
14
|
-
module ClassMethods
|
15
|
-
def start_segment(name:nil,
|
16
|
-
unscoped_metrics:nil,
|
17
|
-
start_time: nil,
|
18
|
-
parent: nil)
|
19
|
-
|
20
|
-
# ruby 2.0.0 does not support required kwargs
|
21
|
-
raise ArgumentError, 'missing required argument: name' if name.nil?
|
22
|
-
|
23
|
-
segment = Segment.new name, unscoped_metrics, start_time
|
24
|
-
|
25
|
-
start_and_add_segment segment, parent
|
26
|
-
end
|
27
|
-
|
28
|
-
UNKNOWN_PRODUCT = "Unknown".freeze
|
29
|
-
UNKNOWN_OPERATION = "other".freeze
|
30
|
-
|
31
|
-
def start_datastore_segment(product: nil,
|
32
|
-
operation: nil,
|
33
|
-
collection: nil,
|
34
|
-
host: nil,
|
35
|
-
port_path_or_id: nil,
|
36
|
-
database_name: nil,
|
37
|
-
start_time: nil,
|
38
|
-
parent: nil)
|
39
|
-
|
40
|
-
product ||= UNKNOWN_PRODUCT
|
41
|
-
operation ||= UNKNOWN_OPERATION
|
42
|
-
|
43
|
-
segment = DatastoreSegment.new product, operation, collection, host, port_path_or_id, database_name
|
44
|
-
start_and_add_segment segment, parent
|
45
|
-
end
|
46
|
-
|
47
|
-
def start_external_request_segment(library: nil,
|
48
|
-
uri: nil,
|
49
|
-
procedure: nil,
|
50
|
-
start_time: nil,
|
51
|
-
parent: nil)
|
52
|
-
|
53
|
-
# ruby 2.0.0 does not support required kwargs
|
54
|
-
raise ArgumentError, 'missing required argument: library' if library.nil?
|
55
|
-
raise ArgumentError, 'missing required argument: uri' if uri.nil?
|
56
|
-
raise ArgumentError, 'missing required argument: procedure' if procedure.nil?
|
57
|
-
|
58
|
-
segment = ExternalRequestSegment.new library, uri, procedure, start_time
|
59
|
-
start_and_add_segment segment, parent
|
60
|
-
end
|
61
|
-
|
62
|
-
# @api private
|
63
|
-
#
|
64
|
-
def start_message_broker_segment(action: nil,
|
65
|
-
library: nil,
|
66
|
-
destination_type: nil,
|
67
|
-
destination_name: nil,
|
68
|
-
headers: nil,
|
69
|
-
parameters: nil,
|
70
|
-
start_time: nil,
|
71
|
-
parent: nil)
|
72
|
-
|
73
|
-
# ruby 2.0.0 does not support required kwargs
|
74
|
-
raise ArgumentError, 'missing required argument: action' if action.nil?
|
75
|
-
raise ArgumentError, 'missing required argument: library' if library.nil?
|
76
|
-
raise ArgumentError, 'missing required argument: destination_type' if destination_type.nil?
|
77
|
-
raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
|
78
|
-
|
79
|
-
segment = MessageBrokerSegment.new(
|
80
|
-
action: action,
|
81
|
-
library: library,
|
82
|
-
destination_type: destination_type,
|
83
|
-
destination_name: destination_name,
|
84
|
-
headers: headers,
|
85
|
-
parameters: parameters,
|
86
|
-
start_time: start_time
|
87
|
-
)
|
88
|
-
start_and_add_segment segment, parent
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def start_and_add_segment segment, parent = nil
|
94
|
-
state = NewRelic::Agent::TransactionState.tl_get
|
95
|
-
if (txn = state.current_transaction) && state.is_execution_traced?
|
96
|
-
txn.add_segment segment, parent
|
97
|
-
else
|
98
|
-
segment.record_metrics = false
|
99
|
-
end
|
100
|
-
segment.start
|
101
|
-
segment
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.included base
|
106
|
-
base.extend ClassMethods
|
107
|
-
end
|
108
9
|
|
109
10
|
attr_reader :current_segment
|
110
11
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
module NewRelic
|
6
6
|
module Agent
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# This module was introduced and largely extracted from the transaction event aggregator
|
6
6
|
# when the synthetics container was extracted from it. Its purpose is to create the data
|
@@ -8,7 +8,8 @@
|
|
8
8
|
# the transaction event aggregator and the synthetics container.
|
9
9
|
|
10
10
|
require 'new_relic/agent/payload_metric_mapping'
|
11
|
-
require 'new_relic/agent/distributed_trace_payload'
|
11
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_payload'
|
12
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_attributes'
|
12
13
|
|
13
14
|
module NewRelic
|
14
15
|
module Agent
|
@@ -31,16 +32,17 @@ module NewRelic
|
|
31
32
|
SYNTHETICS_JOB_ID_KEY = "nr.syntheticsJobId".freeze
|
32
33
|
SYNTHETICS_MONITOR_ID_KEY = "nr.syntheticsMonitorId".freeze
|
33
34
|
PRIORITY_KEY = "priority".freeze
|
35
|
+
SPAN_ID_KEY = "spanId".freeze
|
34
36
|
|
35
|
-
def create noticed_error, payload
|
37
|
+
def create noticed_error, payload, span_id
|
36
38
|
[
|
37
|
-
intrinsic_attributes_for(noticed_error, payload),
|
39
|
+
intrinsic_attributes_for(noticed_error, payload, span_id),
|
38
40
|
noticed_error.custom_attributes,
|
39
41
|
noticed_error.agent_attributes
|
40
42
|
]
|
41
43
|
end
|
42
44
|
|
43
|
-
def intrinsic_attributes_for noticed_error, payload
|
45
|
+
def intrinsic_attributes_for noticed_error, payload, span_id
|
44
46
|
attrs = {
|
45
47
|
TYPE_KEY => SAMPLE_TYPE,
|
46
48
|
ERROR_CLASS_KEY => noticed_error.exception_class_name,
|
@@ -49,16 +51,17 @@ module NewRelic
|
|
49
51
|
TIMESTAMP_KEY => noticed_error.timestamp.to_f
|
50
52
|
}
|
51
53
|
|
54
|
+
attrs[SPAN_ID_KEY] = span_id if span_id
|
52
55
|
attrs[PORT_KEY] = noticed_error.request_port if noticed_error.request_port
|
53
56
|
|
54
57
|
if payload
|
55
58
|
attrs[NAME_KEY] = payload[:name]
|
56
59
|
attrs[DURATION_KEY] = payload[:duration]
|
57
|
-
attrs[SAMPLED_KEY] = payload[:
|
58
|
-
attrs[PRIORITY_KEY] = payload[:
|
60
|
+
attrs[SAMPLED_KEY] = payload[:sampled] if payload.key?(:sampled)
|
61
|
+
attrs[PRIORITY_KEY] = payload[:priority]
|
59
62
|
append_synthetics payload, attrs
|
60
63
|
append_cat payload, attrs
|
61
|
-
|
64
|
+
DistributedTraceAttributes.copy_to_hash payload, attrs
|
62
65
|
PayloadMetricMapping.append_mapped_metrics payload[:metrics], attrs
|
63
66
|
end
|
64
67
|
|
@@ -75,14 +78,6 @@ module NewRelic
|
|
75
78
|
sample[GUID_KEY] = payload[:guid] if payload[:guid]
|
76
79
|
sample[REFERRING_TRANSACTION_GUID_KEY] = payload[:referring_transaction_guid] if payload[:referring_transaction_guid]
|
77
80
|
end
|
78
|
-
|
79
|
-
def append_distributed_trace_intrinsics payload, sample
|
80
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
81
|
-
DistributedTracePayload::INTRINSIC_KEYS.each do |key|
|
82
|
-
value = payload[key]
|
83
|
-
sample[key] = value unless value.nil?
|
84
|
-
end
|
85
|
-
end
|
86
81
|
end
|
87
82
|
end
|
88
83
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# encoding: utf-8
|
3
3
|
# This file is distributed under New Relic's license terms.
|
4
|
-
# See https://github.com/newrelic/
|
4
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
5
5
|
|
6
6
|
require 'newrelic_rpm' unless defined?( NewRelic )
|
7
7
|
require 'new_relic/agent' unless defined?( NewRelic::Agent )
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
|
+
# frozen_string_literal: true
|
4
5
|
|
5
6
|
# This module was introduced and largely extracted from the transaction event aggregator
|
6
7
|
# when the synthetics container was extracted from it. Its purpose is to create the data
|
@@ -8,7 +9,7 @@
|
|
8
9
|
# the transaction event aggregator and the synthetics container.
|
9
10
|
|
10
11
|
require 'new_relic/agent/payload_metric_mapping'
|
11
|
-
require 'new_relic/agent/
|
12
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_attributes'
|
12
13
|
|
13
14
|
module NewRelic
|
14
15
|
module Agent
|
@@ -16,30 +17,28 @@ module NewRelic
|
|
16
17
|
include NewRelic::Coerce
|
17
18
|
extend self
|
18
19
|
|
20
|
+
COMMA = ','
|
21
|
+
|
19
22
|
# The type field of the sample
|
20
|
-
SAMPLE_TYPE = 'Transaction'
|
23
|
+
SAMPLE_TYPE = 'Transaction'
|
21
24
|
|
22
25
|
# Strings for static keys of the sample structure
|
23
|
-
TYPE_KEY = 'type'
|
24
|
-
TIMESTAMP_KEY = 'timestamp'
|
25
|
-
NAME_KEY = 'name'
|
26
|
-
DURATION_KEY = 'duration'
|
27
|
-
ERROR_KEY = 'error'
|
28
|
-
SAMPLED_KEY = 'sampled'
|
29
|
-
PRIORITY_KEY = 'priority'
|
30
|
-
GUID_KEY = 'nr.guid'
|
31
|
-
REFERRING_TRANSACTION_GUID_KEY = 'nr.referringTransactionGuid'
|
32
|
-
CAT_PATH_HASH_KEY = 'nr.pathHash'
|
33
|
-
CAT_REFERRING_PATH_HASH_KEY = 'nr.referringPathHash'
|
34
|
-
CAT_ALTERNATE_PATH_HASHES_KEY = 'nr.alternatePathHashes'
|
35
|
-
APDEX_PERF_ZONE_KEY = 'nr.apdexPerfZone'
|
36
|
-
SYNTHETICS_RESOURCE_ID_KEY = "nr.syntheticsResourceId"
|
37
|
-
SYNTHETICS_JOB_ID_KEY = "nr.syntheticsJobId"
|
38
|
-
SYNTHETICS_MONITOR_ID_KEY = "nr.syntheticsMonitorId"
|
39
|
-
|
40
|
-
|
41
|
-
# To avoid allocations when we have empty custom or agent attributes
|
42
|
-
EMPTY_HASH = {}.freeze
|
26
|
+
TYPE_KEY = 'type'
|
27
|
+
TIMESTAMP_KEY = 'timestamp'
|
28
|
+
NAME_KEY = 'name'
|
29
|
+
DURATION_KEY = 'duration'
|
30
|
+
ERROR_KEY = 'error'
|
31
|
+
SAMPLED_KEY = 'sampled'
|
32
|
+
PRIORITY_KEY = 'priority'
|
33
|
+
GUID_KEY = 'nr.guid'
|
34
|
+
REFERRING_TRANSACTION_GUID_KEY = 'nr.referringTransactionGuid'
|
35
|
+
CAT_PATH_HASH_KEY = 'nr.pathHash'
|
36
|
+
CAT_REFERRING_PATH_HASH_KEY = 'nr.referringPathHash'
|
37
|
+
CAT_ALTERNATE_PATH_HASHES_KEY = 'nr.alternatePathHashes'
|
38
|
+
APDEX_PERF_ZONE_KEY = 'nr.apdexPerfZone'
|
39
|
+
SYNTHETICS_RESOURCE_ID_KEY = "nr.syntheticsResourceId"
|
40
|
+
SYNTHETICS_JOB_ID_KEY = "nr.syntheticsJobId"
|
41
|
+
SYNTHETICS_MONITOR_ID_KEY = "nr.syntheticsMonitorId"
|
43
42
|
|
44
43
|
def create(payload)
|
45
44
|
intrinsics = {
|
@@ -51,11 +50,11 @@ module NewRelic
|
|
51
50
|
PRIORITY_KEY => payload[:priority]
|
52
51
|
}
|
53
52
|
|
54
|
-
intrinsics[SAMPLED_KEY] = payload[:
|
53
|
+
intrinsics[SAMPLED_KEY] = payload[:sampled] if payload.key?(:sampled)
|
55
54
|
|
56
|
-
|
55
|
+
PayloadMetricMapping.append_mapped_metrics(payload[:metrics], intrinsics)
|
57
56
|
append_optional_attributes(intrinsics, payload)
|
58
|
-
|
57
|
+
DistributedTraceAttributes.copy_to_hash payload, intrinsics
|
59
58
|
|
60
59
|
attributes = payload[:attributes]
|
61
60
|
|
@@ -76,22 +75,12 @@ module NewRelic
|
|
76
75
|
append_cat_alternate_path_hashes(sample, payload)
|
77
76
|
end
|
78
77
|
|
79
|
-
COMMA = ','.freeze
|
80
|
-
|
81
78
|
def append_cat_alternate_path_hashes(sample, payload)
|
82
79
|
if payload.include?(:cat_alternate_path_hashes)
|
83
80
|
sample[CAT_ALTERNATE_PATH_HASHES_KEY] = payload[:cat_alternate_path_hashes].sort.join(COMMA)
|
84
81
|
end
|
85
82
|
end
|
86
83
|
|
87
|
-
def append_distributed_trace_intrinsics(sample, payload)
|
88
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
89
|
-
DistributedTracePayload::INTRINSIC_KEYS.each do |key|
|
90
|
-
value = payload[key]
|
91
|
-
sample[key] = value unless value.nil?
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
84
|
def optionally_append(sample_key, payload_key, sample, payload)
|
96
85
|
if payload.include?(payload_key)
|
97
86
|
sample[sample_key] = string(payload[payload_key])
|
@@ -100,19 +89,19 @@ module NewRelic
|
|
100
89
|
|
101
90
|
def custom_attributes attributes
|
102
91
|
if attributes
|
103
|
-
result = attributes.custom_attributes_for(
|
92
|
+
result = attributes.custom_attributes_for(AttributeFilter::DST_TRANSACTION_EVENTS)
|
104
93
|
result.freeze
|
105
94
|
else
|
106
|
-
EMPTY_HASH
|
95
|
+
NewRelic::EMPTY_HASH
|
107
96
|
end
|
108
97
|
end
|
109
98
|
|
110
99
|
def agent_attributes attributes
|
111
100
|
if attributes
|
112
|
-
result = attributes.agent_attributes_for(
|
101
|
+
result = attributes.agent_attributes_for(AttributeFilter::DST_TRANSACTION_EVENTS)
|
113
102
|
result.freeze
|
114
103
|
else
|
115
|
-
EMPTY_HASH
|
104
|
+
NewRelic::EMPTY_HASH
|
116
105
|
end
|
117
106
|
end
|
118
107
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
require 'new_relic/agent/transaction_event_aggregator'
|
5
5
|
require 'new_relic/agent/synthetics_event_aggregator'
|
6
6
|
require 'new_relic/agent/transaction_event_primitive'
|
@@ -14,9 +14,9 @@ module NewRelic
|
|
14
14
|
attr_reader :transaction_event_aggregator
|
15
15
|
attr_reader :synthetics_event_aggregator
|
16
16
|
|
17
|
-
def initialize
|
18
|
-
@transaction_event_aggregator = NewRelic::Agent::TransactionEventAggregator.new
|
19
|
-
@synthetics_event_aggregator = NewRelic::Agent::SyntheticsEventAggregator.new
|
17
|
+
def initialize events
|
18
|
+
@transaction_event_aggregator = NewRelic::Agent::TransactionEventAggregator.new events
|
19
|
+
@synthetics_event_aggregator = NewRelic::Agent::SyntheticsEventAggregator.new events
|
20
20
|
end
|
21
21
|
|
22
22
|
def record payload
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# This class represents a set of metrics that were recorded during a single
|
6
6
|
# transaction. Since the name of the transaction is not known until its end, we
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'new_relic/agent/transaction/slowest_sample_buffer'
|
6
6
|
require 'new_relic/agent/transaction/synthetics_sample_buffer'
|
7
|
-
require 'new_relic/agent/transaction/xray_sample_buffer'
|
8
7
|
require 'new_relic/agent/transaction/trace_builder'
|
9
8
|
|
10
9
|
module NewRelic
|
@@ -19,13 +18,10 @@ module NewRelic
|
|
19
18
|
#
|
20
19
|
# @api public
|
21
20
|
class TransactionSampler
|
22
|
-
attr_reader :last_sample
|
21
|
+
attr_reader :last_sample
|
23
22
|
|
24
23
|
def initialize
|
25
|
-
@xray_sample_buffer = NewRelic::Agent::Transaction::XraySampleBuffer.new
|
26
|
-
|
27
24
|
@sample_buffers = []
|
28
|
-
@sample_buffers << @xray_sample_buffer
|
29
25
|
@sample_buffers << NewRelic::Agent::Transaction::SlowestSampleBuffer.new
|
30
26
|
@sample_buffers << NewRelic::Agent::Transaction::SyntheticsSampleBuffer.new
|
31
27
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
4
|
-
|
5
|
-
require 'objspace'
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
6
4
|
|
7
5
|
# This module powers the Busy calculation for the Capacity report in
|
8
6
|
# APM (https://rpm.newrelic.com/accounts/.../applications/.../optimize/capacity_analysis).
|
@@ -23,37 +21,37 @@ module NewRelic
|
|
23
21
|
h[k] = TransactionStats.new nil, 0.0
|
24
22
|
end
|
25
23
|
|
26
|
-
def reset!(
|
27
|
-
@harvest_cycle_started_at =
|
24
|
+
def reset!(timestamp = Time.now)
|
25
|
+
@harvest_cycle_started_at = timestamp
|
28
26
|
@stats.clear
|
29
27
|
end
|
30
28
|
|
31
|
-
def transaction_start(
|
29
|
+
def transaction_start(timestamp = Time.now)
|
32
30
|
@lock.synchronize do
|
33
|
-
set_transaction_start_time
|
31
|
+
set_transaction_start_time timestamp
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
|
-
def transaction_stop(
|
35
|
+
def transaction_stop(timestamp = Time.now, starting_thread_id = current_thread)
|
38
36
|
@lock.synchronize do
|
39
|
-
record_elapsed_transaction_time_until
|
40
|
-
set_transaction_start_time nil
|
37
|
+
record_elapsed_transaction_time_until timestamp, starting_thread_id
|
38
|
+
set_transaction_start_time nil, starting_thread_id
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
INSTANCE_BUSY_METRIC = 'Instance/Busy'.freeze
|
45
43
|
|
46
|
-
def harvest!(
|
44
|
+
def harvest!(timestamp = Time.now)
|
47
45
|
active_threads = 0
|
48
46
|
result = @lock.synchronize do
|
49
47
|
# Sum up the transaction times spent in each thread
|
50
48
|
elapsed_transaction_time = @stats.inject(0.0) do |total, (thread_id, entry)|
|
51
|
-
total + transaction_time_in_thread(thread_id, entry
|
49
|
+
total + transaction_time_in_thread(timestamp, thread_id, entry)
|
52
50
|
end
|
53
51
|
|
54
52
|
active_threads = @stats.size
|
55
|
-
elapsed_harvest_time = (
|
56
|
-
@harvest_cycle_started_at =
|
53
|
+
elapsed_harvest_time = (timestamp - @harvest_cycle_started_at) * active_threads
|
54
|
+
@harvest_cycle_started_at = timestamp
|
57
55
|
|
58
56
|
# Clear out the stats for all threads, _except_ the live ones
|
59
57
|
# that have transactions still open (we'll count the rest of
|
@@ -81,12 +79,16 @@ module NewRelic
|
|
81
79
|
:transaction_stop,
|
82
80
|
:harvest!
|
83
81
|
|
84
|
-
class <<self
|
82
|
+
class << self
|
85
83
|
private
|
86
84
|
|
87
|
-
def record_elapsed_transaction_time_until(timestamp, thread_id
|
88
|
-
@stats[thread_id].
|
89
|
-
|
85
|
+
def record_elapsed_transaction_time_until(timestamp, thread_id = current_thread)
|
86
|
+
if @stats[thread_id].transaction_started_at
|
87
|
+
@stats[thread_id].elapsed_transaction_time +=
|
88
|
+
(timestamp - (@stats[thread_id].transaction_started_at || 0.0))
|
89
|
+
else
|
90
|
+
log_missing_elapsed_transaction_time
|
91
|
+
end
|
90
92
|
end
|
91
93
|
|
92
94
|
def in_transaction?(thread_id = current_thread)
|
@@ -98,33 +100,55 @@ module NewRelic
|
|
98
100
|
end
|
99
101
|
|
100
102
|
def thread_is_alive?(thread_id)
|
101
|
-
thread =
|
103
|
+
thread = thread_by_id thread_id
|
102
104
|
thread && thread.alive?
|
103
105
|
rescue StandardError
|
104
106
|
false
|
105
107
|
end
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
+
# ObjectSpace is faster on MRI, but disabled by default on JRuby for
|
110
|
+
# perfomance reasons. We have two implmentations of `thread_by_id`
|
111
|
+
# based on ruby implementation.
|
112
|
+
if RUBY_ENGINE == 'jruby'
|
113
|
+
def thread_by_id thread_id
|
114
|
+
Thread.list.detect { |t| t.object_id == thread_id }
|
115
|
+
end
|
116
|
+
else
|
117
|
+
require 'objspace'
|
118
|
+
|
119
|
+
def thread_by_id thread_id
|
120
|
+
ObjectSpace._id2ref(thread_id)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_transaction_start_time(timestamp, thread_id = current_thread)
|
125
|
+
@stats[thread_id].transaction_started_at = timestamp
|
109
126
|
end
|
110
127
|
|
111
|
-
def split_transaction_at_harvest(
|
128
|
+
def split_transaction_at_harvest(timestamp, thread_id = nil)
|
112
129
|
raise ArgumentError, 'thread_id required' unless thread_id
|
113
|
-
@stats[thread_id].transaction_started_at =
|
130
|
+
@stats[thread_id].transaction_started_at = timestamp
|
114
131
|
@stats[thread_id].elapsed_transaction_time = 0.0
|
115
132
|
end
|
116
133
|
|
117
|
-
def transaction_time_in_thread thread_id, entry
|
134
|
+
def transaction_time_in_thread timestamp, thread_id, entry
|
118
135
|
return entry.elapsed_transaction_time unless in_transaction? thread_id
|
119
136
|
|
120
137
|
# Count the portion of the transaction that's elapsed so far,...
|
121
|
-
elapsed = record_elapsed_transaction_time_until
|
138
|
+
elapsed = record_elapsed_transaction_time_until timestamp, thread_id
|
122
139
|
|
123
140
|
# ...then readjust the transaction start time to the next harvest
|
124
|
-
split_transaction_at_harvest
|
141
|
+
split_transaction_at_harvest timestamp, thread_id
|
125
142
|
|
126
143
|
elapsed
|
127
144
|
end
|
145
|
+
|
146
|
+
def log_missing_elapsed_transaction_time
|
147
|
+
transaction_name = Tracer.current_transaction &&
|
148
|
+
Tracer.current_transaction.best_name ||
|
149
|
+
"unknown"
|
150
|
+
NewRelic::Agent.logger.warn("Unable to calculate elapsed transaction time for #{transaction_name}")
|
151
|
+
end
|
128
152
|
end
|
129
153
|
end
|
130
154
|
end
|