newrelic_rpm 7.0.0 → 8.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +1941 -0
- data/.yardopts +1 -0
- data/Brewfile +10 -0
- data/CHANGELOG.md +431 -1
- data/CONTRIBUTING.md +32 -5
- data/DOCKER.md +167 -0
- data/Dockerfile +10 -0
- data/Guardfile +8 -8
- data/LICENSE +0 -6
- data/README.md +20 -18
- data/Rakefile +39 -29
- data/THIRD_PARTY_NOTICES.md +14 -199
- data/bin/mongrel_rpm +8 -9
- data/bin/newrelic +1 -1
- data/bin/nrdebug +14 -14
- data/docker-compose.yml +85 -0
- data/init.rb +0 -2
- data/lefthook.yml +9 -0
- data/lib/new_relic/agent/adaptive_sampler.rb +9 -5
- data/lib/new_relic/agent/agent.rb +72 -49
- data/lib/new_relic/agent/agent_logger.rb +15 -9
- data/lib/new_relic/agent/attribute_filter.rb +31 -31
- data/lib/new_relic/agent/attributes.rb +2 -2
- data/lib/new_relic/agent/audit_logger.rb +4 -0
- data/lib/new_relic/agent/autostart.rb +19 -17
- data/lib/new_relic/agent/commands/agent_command.rb +2 -2
- data/lib/new_relic/agent/commands/agent_command_router.rb +6 -5
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +7 -6
- data/lib/new_relic/agent/configuration/default_source.rb +731 -476
- data/lib/new_relic/agent/configuration/dotted_hash.rb +3 -3
- data/lib/new_relic/agent/configuration/environment_source.rb +5 -4
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +39 -16
- data/lib/new_relic/agent/configuration/high_security_source.rb +7 -7
- data/lib/new_relic/agent/configuration/manager.rb +74 -64
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
- data/lib/new_relic/agent/configuration/security_policy_source.rb +73 -73
- data/lib/new_relic/agent/configuration/server_source.rb +14 -12
- data/lib/new_relic/agent/configuration/yaml_source.rb +26 -5
- data/lib/new_relic/agent/connect/request_builder.rb +14 -15
- data/lib/new_relic/agent/connect/response_handler.rb +0 -3
- data/lib/new_relic/agent/custom_event_aggregator.rb +9 -9
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +3 -4
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +12 -12
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +2 -2
- data/lib/new_relic/agent/database.rb +30 -31
- data/lib/new_relic/agent/datastores/metric_helper.rb +13 -11
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +3 -5
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +1 -2
- data/lib/new_relic/agent/datastores/mongo.rb +5 -10
- data/lib/new_relic/agent/datastores/redis.rb +2 -4
- data/lib/new_relic/agent/datastores.rb +7 -9
- data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +9 -9
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +21 -16
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -12
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +42 -43
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +3 -3
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +41 -43
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +25 -25
- 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 +65 -50
- data/lib/new_relic/agent/error_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/error_filter.rb +173 -0
- data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
- data/lib/new_relic/agent/event_aggregator.rb +1 -1
- data/lib/new_relic/agent/event_buffer.rb +6 -7
- data/lib/new_relic/agent/event_listener.rb +0 -1
- data/lib/new_relic/agent/event_loop.rb +14 -14
- data/lib/new_relic/agent/external.rb +1 -34
- data/lib/new_relic/agent/guid_generator.rb +2 -9
- data/lib/new_relic/agent/harvester.rb +3 -4
- data/lib/new_relic/agent/heap.rb +1 -3
- data/lib/new_relic/agent/hostname.rb +16 -10
- data/lib/new_relic/agent/http_clients/abstract.rb +7 -9
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -5
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +4 -4
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +3 -3
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -2
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +8 -3
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +2 -3
- data/lib/new_relic/agent/http_clients/uri_util.rb +0 -1
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +2 -3
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +28 -26
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
- data/lib/new_relic/agent/instrumentation/active_job.rb +12 -5
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +17 -3
- data/lib/new_relic/agent/instrumentation/active_record.rb +20 -18
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +56 -46
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +28 -25
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +3 -3
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +22 -16
- data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_support_logger/chain.rb +23 -0
- data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +20 -0
- data/lib/new_relic/agent/instrumentation/active_support_logger/prepend.rb +12 -0
- data/lib/new_relic/agent/instrumentation/active_support_logger.rb +24 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +18 -9
- data/lib/new_relic/agent/instrumentation/authlogic.rb +10 -0
- data/lib/new_relic/agent/instrumentation/bunny/chain.rb +1 -1
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +8 -9
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +52 -46
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +20 -21
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +34 -38
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +10 -11
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +22 -10
- data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +5 -7
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +5 -9
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +23 -4
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -2
- data/lib/new_relic/agent/instrumentation/excon.rb +3 -23
- data/lib/new_relic/agent/instrumentation/grape/chain.rb +1 -2
- data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +6 -7
- data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
- data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +2 -3
- data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +0 -1
- data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +0 -2
- data/lib/new_relic/agent/instrumentation/httprb/chain.rb +2 -2
- data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +6 -6
- data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +2 -3
- data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
- data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +58 -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/dalli.rb +7 -2
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +5 -1
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +9 -2
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +9 -10
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +5 -6
- data/lib/new_relic/agent/instrumentation/mongo.rb +3 -141
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +4 -4
- data/lib/new_relic/agent/instrumentation/net_http/chain.rb +3 -4
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -5
- data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +4 -4
- data/lib/new_relic/agent/instrumentation/net_http.rb +7 -2
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +2 -3
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +23 -19
- data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +3 -2
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +2 -2
- data/lib/new_relic/agent/instrumentation/padrino.rb +2 -5
- data/lib/new_relic/agent/instrumentation/queue_time.rb +8 -8
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +8 -7
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +2 -1
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +4 -5
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +11 -47
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +0 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +11 -0
- data/lib/new_relic/agent/instrumentation/rake/chain.rb +0 -5
- data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +6 -6
- data/lib/new_relic/agent/instrumentation/rake.rb +1 -1
- data/lib/new_relic/agent/instrumentation/redis/chain.rb +6 -6
- data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/redis/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/redis.rb +5 -1
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -3
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +9 -7
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +17 -8
- data/lib/new_relic/agent/instrumentation/sequel.rb +7 -9
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +22 -1
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +0 -1
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +12 -5
- data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -11
- data/lib/new_relic/agent/instrumentation/sunspot.rb +11 -1
- data/lib/new_relic/agent/instrumentation/thread/chain.rb +24 -0
- data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +27 -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 +40 -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 +4 -4
- data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +3 -5
- data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +1 -1
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +38 -33
- data/lib/new_relic/agent/linking_metadata.rb +45 -0
- data/lib/new_relic/agent/local_log_decorator.rb +37 -0
- data/lib/new_relic/agent/log_event_aggregator.rb +234 -0
- data/lib/new_relic/agent/log_priority.rb +20 -0
- data/lib/new_relic/agent/logging.rb +11 -8
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +46 -62
- data/lib/new_relic/agent/method_tracer.rb +145 -144
- data/lib/new_relic/agent/method_tracer_helpers.rb +82 -2
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +21 -13
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +2 -2
- data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +0 -1
- data/lib/new_relic/agent/monitors/synthetics_monitor.rb +4 -7
- data/lib/new_relic/agent/monitors.rb +1 -2
- data/lib/new_relic/agent/new_relic_service/encoders.rb +4 -4
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +4 -3
- data/lib/new_relic/agent/new_relic_service.rb +61 -53
- data/lib/new_relic/agent/noticible_error.rb +0 -2
- data/lib/new_relic/agent/null_logger.rb +6 -2
- data/lib/new_relic/agent/obfuscator.rb +6 -8
- data/lib/new_relic/agent/parameter_filtering.rb +16 -8
- data/lib/new_relic/agent/payload_metric_mapping.rb +8 -9
- data/lib/new_relic/agent/pipe_channel_manager.rb +15 -12
- data/lib/new_relic/agent/pipe_service.rb +6 -3
- data/lib/new_relic/agent/priority_sampled_buffer.rb +4 -7
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +9 -9
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +12 -12
- data/lib/new_relic/agent/rules_engine.rb +2 -2
- data/lib/new_relic/agent/sampler.rb +2 -3
- data/lib/new_relic/agent/sampler_collection.rb +2 -3
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +10 -7
- data/lib/new_relic/agent/samplers/memory_sampler.rb +9 -3
- data/lib/new_relic/agent/samplers/vm_sampler.rb +18 -18
- data/lib/new_relic/agent/span_event_aggregator.rb +10 -10
- data/lib/new_relic/agent/span_event_primitive.rb +48 -45
- data/lib/new_relic/agent/sql_sampler.rb +9 -9
- data/lib/new_relic/agent/stats.rb +62 -37
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +7 -9
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +8 -9
- data/lib/new_relic/agent/stats_engine.rb +7 -7
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -2
- data/lib/new_relic/agent/system_info.rb +22 -20
- data/lib/new_relic/agent/threading/agent_thread.rb +4 -5
- data/lib/new_relic/agent/threading/backtrace_node.rb +6 -9
- data/lib/new_relic/agent/threading/backtrace_service.rb +12 -13
- data/lib/new_relic/agent/threading/thread_profile.rb +16 -19
- data/lib/new_relic/agent/tracer.rb +57 -72
- data/lib/new_relic/agent/transaction/abstract_segment.rb +38 -10
- data/lib/new_relic/agent/transaction/datastore_segment.rb +7 -6
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +8 -9
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +21 -22
- data/lib/new_relic/agent/transaction/external_request_segment.rb +6 -5
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +24 -30
- data/lib/new_relic/agent/transaction/request_attributes.rb +7 -7
- data/lib/new_relic/agent/transaction/segment.rb +6 -3
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +0 -2
- data/lib/new_relic/agent/transaction/trace.rb +8 -8
- data/lib/new_relic/agent/transaction/trace_context.rb +14 -16
- data/lib/new_relic/agent/transaction/trace_node.rb +16 -16
- data/lib/new_relic/agent/transaction/tracing.rb +9 -6
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
- data/lib/new_relic/agent/transaction.rb +132 -119
- data/lib/new_relic/agent/transaction_error_primitive.rb +18 -16
- data/lib/new_relic/agent/transaction_event_aggregator.rb +7 -8
- data/lib/new_relic/agent/transaction_event_primitive.rb +29 -29
- data/lib/new_relic/agent/transaction_event_recorder.rb +1 -1
- data/lib/new_relic/agent/transaction_metrics.rb +8 -7
- data/lib/new_relic/agent/transaction_sampler.rb +0 -1
- data/lib/new_relic/agent/transaction_time_aggregator.rb +11 -11
- data/lib/new_relic/agent/utilization/aws.rb +32 -2
- data/lib/new_relic/agent/utilization/azure.rb +1 -1
- data/lib/new_relic/agent/utilization/vendor.rb +15 -2
- data/lib/new_relic/agent/utilization_data.rb +3 -4
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
- data/lib/new_relic/agent/vm/mri_vm.rb +13 -1
- data/lib/new_relic/agent/vm/snapshot.rb +4 -4
- data/lib/new_relic/agent/worker_loop.rb +8 -10
- data/lib/new_relic/agent.rb +36 -41
- data/lib/new_relic/cli/command.rb +15 -17
- data/lib/new_relic/cli/commands/deployments.rb +21 -23
- data/lib/new_relic/cli/commands/install.rb +6 -10
- data/lib/new_relic/coerce.rb +5 -8
- data/lib/new_relic/collection_helper.rb +48 -47
- data/lib/new_relic/constants.rb +0 -4
- data/lib/new_relic/control/class_methods.rb +2 -2
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +5 -6
- data/lib/new_relic/control/frameworks/rails3.rb +2 -3
- data/lib/new_relic/control/frameworks/ruby.rb +2 -2
- data/lib/new_relic/control/frameworks/sinatra.rb +6 -0
- data/lib/new_relic/control/instance_methods.rb +4 -5
- data/lib/new_relic/control/instrumentation.rb +35 -5
- data/lib/new_relic/control/server_methods.rb +2 -3
- data/lib/new_relic/control.rb +0 -1
- data/lib/new_relic/dependency_detection.rb +7 -9
- data/lib/new_relic/environment_report.rb +16 -18
- data/lib/new_relic/helper.rb +45 -5
- data/lib/new_relic/language_support.rb +20 -2
- data/lib/new_relic/latest_changes.rb +2 -2
- data/lib/new_relic/local_environment.rb +9 -7
- data/lib/new_relic/metric_data.rb +6 -7
- data/lib/new_relic/metric_spec.rb +3 -3
- data/lib/new_relic/noticed_error.rb +18 -19
- data/lib/new_relic/rack/agent_middleware.rb +2 -2
- data/lib/new_relic/rack/browser_monitoring.rb +9 -9
- data/lib/new_relic/recipes/capistrano3.rb +11 -13
- data/lib/new_relic/recipes/capistrano_legacy.rb +11 -14
- data/lib/new_relic/supportability_helper.rb +2 -2
- data/lib/new_relic/traced_thread.rb +35 -0
- data/lib/new_relic/version.rb +5 -16
- data/lib/newrelic_rpm.rb +10 -34
- data/lib/sequel/extensions/newrelic_instrumentation.rb +4 -7
- data/lib/sequel/plugins/newrelic_instrumentation.rb +3 -9
- data/lib/tasks/all.rb +2 -2
- data/lib/tasks/config.html.erb +14 -25
- data/lib/tasks/config.rake +36 -27
- data/lib/tasks/multiverse.rb +4 -6
- data/lib/tasks/tests.rake +3 -7
- data/newrelic.yml +610 -3
- data/newrelic_rpm.gemspec +14 -14
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +98 -59
- metadata +69 -20
- data/ROADMAP.md +0 -24
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
- data/lib/new_relic/agent/instrumentation/excon/connection.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/rails/action_controller.rb +0 -125
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +0 -46
- data/lib/new_relic/agent/supported_versions.rb +0 -275
- data/lib/new_relic/control/frameworks/merb.rb +0 -29
@@ -47,13 +47,12 @@ module NewRelic
|
|
47
47
|
#
|
48
48
|
|
49
49
|
module MethodTracer
|
50
|
-
|
51
|
-
|
52
|
-
clazz.extend ClassMethods
|
50
|
+
def self.included(klass)
|
51
|
+
klass.extend(ClassMethods)
|
53
52
|
end
|
54
53
|
|
55
|
-
def self.extended
|
56
|
-
|
54
|
+
def self.extended(klass)
|
55
|
+
klass.extend(ClassMethods)
|
57
56
|
end
|
58
57
|
|
59
58
|
# Trace a given block with stats and keep track of the caller.
|
@@ -68,8 +67,8 @@ module NewRelic
|
|
68
67
|
#
|
69
68
|
# @api public
|
70
69
|
#
|
71
|
-
def trace_execution_scoped(metric_names, options=NewRelic::EMPTY_HASH) #THREAD_LOCAL_ACCESS
|
72
|
-
NewRelic::Agent.record_api_supportability_metric :trace_execution_scoped
|
70
|
+
def trace_execution_scoped(metric_names, options = NewRelic::EMPTY_HASH) # THREAD_LOCAL_ACCESS
|
71
|
+
NewRelic::Agent.record_api_supportability_metric :trace_execution_scoped unless options[:internal]
|
73
72
|
NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped(metric_names, options) do
|
74
73
|
# Using an implicit block avoids object allocation for a &block param
|
75
74
|
yield
|
@@ -79,19 +78,19 @@ module NewRelic
|
|
79
78
|
# Trace a given block with stats assigned to the given metric_name. It does not
|
80
79
|
# provide scoped measurements, meaning whatever is being traced will not 'blame the
|
81
80
|
# Controller'--that is to say appear in the breakdown chart.
|
82
|
-
#
|
81
|
+
#
|
83
82
|
# * <tt>metric_names</tt> is a single name or an array of names of metrics
|
84
83
|
#
|
85
84
|
# @api public
|
86
85
|
#
|
87
|
-
def trace_execution_unscoped(metric_names, options=NewRelic::EMPTY_HASH) #THREAD_LOCAL_ACCESS
|
88
|
-
NewRelic::Agent.record_api_supportability_metric :trace_execution_unscoped
|
86
|
+
def trace_execution_unscoped(metric_names, options = NewRelic::EMPTY_HASH) # THREAD_LOCAL_ACCESS
|
87
|
+
NewRelic::Agent.record_api_supportability_metric :trace_execution_unscoped unless options[:internal]
|
89
88
|
return yield unless NewRelic::Agent.tl_is_execution_traced?
|
90
|
-
t0 =
|
89
|
+
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
91
90
|
begin
|
92
91
|
yield
|
93
92
|
ensure
|
94
|
-
duration = (
|
93
|
+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0
|
95
94
|
NewRelic::Agent.instance.stats_engine.tl_record_unscoped_metrics(metric_names, duration)
|
96
95
|
end
|
97
96
|
end
|
@@ -101,52 +100,40 @@ module NewRelic
|
|
101
100
|
module ClassMethods
|
102
101
|
# contains methods refactored out of the #add_method_tracer method
|
103
102
|
module AddMethodTracer
|
104
|
-
ALLOWED_KEYS = [:metric, :push_scope, :code_header, :code_footer].freeze
|
105
|
-
|
106
|
-
# raises an error when the
|
107
|
-
# NewRelic::Agent::MethodTracer::ClassMethods#add_method_tracer
|
108
|
-
# method is called with improper keys. This aids in
|
109
|
-
# debugging new instrumentation by failing fast
|
110
|
-
def check_for_illegal_keys!(method_name, options)
|
111
|
-
unrecognized_keys = options.keys - ALLOWED_KEYS
|
112
|
-
|
113
|
-
if unrecognized_keys.any?
|
114
|
-
raise "Unrecognized options when adding method tracer to #{method_name}: " +
|
115
|
-
unrecognized_keys.join(', ')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# validity checking - add_method_tracer must receive either
|
120
|
-
# push scope or metric, or else it would record no
|
121
|
-
# data. Raises an error if this is the case
|
122
|
-
def check_for_push_scope_and_metric(options)
|
123
|
-
unless options[:push_scope] || options[:metric]
|
124
|
-
raise "Can't add a tracer where push_scope is false and metric is false"
|
125
|
-
end
|
126
|
-
end
|
103
|
+
ALLOWED_KEYS = [:metric, :push_scope, :code_header, :code_information, :code_footer].freeze
|
127
104
|
|
128
|
-
DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :code_header => "", :code_footer => ""
|
105
|
+
DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :code_header => "", :code_footer => ""}.freeze
|
129
106
|
|
130
107
|
# Checks the provided options to make sure that they make
|
131
108
|
# sense. Raises an error if the options are incorrect to
|
132
109
|
# assist with debugging, so that errors occur at class
|
133
110
|
# construction time rather than instrumentation run time
|
134
|
-
def
|
111
|
+
def _nr_validate_method_tracer_options(method_name, options)
|
135
112
|
unless options.is_a?(Hash)
|
136
113
|
raise TypeError.new("Error adding method tracer to #{method_name}: provided options must be a Hash")
|
137
114
|
end
|
138
|
-
|
115
|
+
|
116
|
+
unrecognized_keys = options.keys - ALLOWED_KEYS
|
117
|
+
if unrecognized_keys.any?
|
118
|
+
raise "Unrecognized options when adding method tracer to #{method_name}: " +
|
119
|
+
unrecognized_keys.join(', ')
|
120
|
+
end
|
121
|
+
|
139
122
|
options = DEFAULT_SETTINGS.merge(options)
|
140
|
-
|
123
|
+
unless options[:push_scope] || options[:metric]
|
124
|
+
raise "Can't add a tracer where push_scope is false and metric is false"
|
125
|
+
end
|
126
|
+
|
141
127
|
options
|
142
128
|
end
|
143
129
|
|
144
130
|
# Default to the class where the method is defined.
|
145
131
|
#
|
146
132
|
# Example:
|
147
|
-
# Foo.
|
148
|
-
def
|
149
|
-
|
133
|
+
# Foo._nr_default_metric_name_code('bar') #=> "Custom/#{Foo.name}/bar"
|
134
|
+
def _nr_default_metric_name(method_name)
|
135
|
+
class_name = _nr_derived_class_name
|
136
|
+
-> (*) { "Custom/#{class_name}/#{method_name}" }
|
150
137
|
end
|
151
138
|
|
152
139
|
# Checks to see if the method we are attempting to trace
|
@@ -154,7 +141,7 @@ module NewRelic
|
|
154
141
|
# anything if the method doesn't exist.
|
155
142
|
def newrelic_method_exists?(method_name)
|
156
143
|
exists = method_defined?(method_name) || private_method_defined?(method_name)
|
157
|
-
::NewRelic::Agent.logger.error("Did not trace #{
|
144
|
+
::NewRelic::Agent.logger.error("Did not trace #{_nr_derived_class_name}##{method_name} because that method does not exist") unless exists
|
158
145
|
exists
|
159
146
|
end
|
160
147
|
|
@@ -162,67 +149,25 @@ module NewRelic
|
|
162
149
|
# given metric by checking to see if the traced method
|
163
150
|
# exists. Warns the user if methods are being double-traced
|
164
151
|
# to help with debugging custom instrumentation.
|
165
|
-
def
|
166
|
-
exists = method_defined?(
|
167
|
-
::NewRelic::Agent.logger.error("Attempt to trace a method twice
|
152
|
+
def method_traced?(method_name)
|
153
|
+
exists = method_name && _nr_traced_method_module.method_defined?(method_name)
|
154
|
+
::NewRelic::Agent.logger.error("Attempt to trace a method twice: Method = #{method_name}") if exists
|
168
155
|
exists
|
169
156
|
end
|
170
157
|
|
171
|
-
# Returns
|
172
|
-
|
173
|
-
|
174
|
-
# when the agent is disabled
|
175
|
-
def assemble_code_header(method_name, metric_name_code, options)
|
176
|
-
header = "return #{_untraced_method_name(method_name, metric_name_code)}(#{ARGS_FOR_RUBY_VERSION}) unless NewRelic::Agent.tl_is_execution_traced?\n"
|
177
|
-
header += options[:code_header].to_s
|
178
|
-
header
|
179
|
-
end
|
180
|
-
|
181
|
-
# returns an eval-able string that contains the traced
|
182
|
-
# method code used if the agent is not creating a scope for
|
183
|
-
# use in scoped metrics.
|
184
|
-
def method_without_push_scope(method_name, metric_name_code, options)
|
185
|
-
"def #{_traced_method_name(method_name, metric_name_code)}(#{ARGS_FOR_RUBY_VERSION})
|
186
|
-
#{assemble_code_header(method_name, metric_name_code, options)}
|
187
|
-
t0 = Time.now
|
188
|
-
begin
|
189
|
-
#{_untraced_method_name(method_name, metric_name_code)}(#{ARGS_FOR_RUBY_VERSION})\n
|
190
|
-
ensure
|
191
|
-
duration = (Time.now - t0).to_f
|
192
|
-
NewRelic::Agent.record_metric(\"#{metric_name_code}\", duration)
|
193
|
-
#{options[:code_footer]}
|
194
|
-
end
|
195
|
-
end"
|
196
|
-
end
|
197
|
-
|
198
|
-
# returns an eval-able string that contains the tracing code
|
199
|
-
# for a fully traced metric including scoping
|
200
|
-
def method_with_push_scope(method_name, metric_name_code, options)
|
201
|
-
"def #{_traced_method_name(method_name, metric_name_code)}(#{ARGS_FOR_RUBY_VERSION})
|
202
|
-
#{options[:code_header]}
|
203
|
-
result = ::NewRelic::Agent::MethodTracerHelpers.trace_execution_scoped(\"#{metric_name_code}\",
|
204
|
-
:metric => #{options[:metric]}) do
|
205
|
-
#{_untraced_method_name(method_name, metric_name_code)}(#{ARGS_FOR_RUBY_VERSION})
|
206
|
-
end
|
207
|
-
#{options[:code_footer]}
|
208
|
-
result
|
209
|
-
end"
|
158
|
+
# Returns an anonymous module that stores prepended trace methods.
|
159
|
+
def _nr_traced_method_module
|
160
|
+
@_nr_traced_method_module ||= Module.new
|
210
161
|
end
|
211
162
|
|
212
|
-
#
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
if options[:push_scope]
|
217
|
-
method_with_push_scope(method_name, metric_name_code, options)
|
218
|
-
else
|
219
|
-
method_without_push_scope(method_name, metric_name_code, options)
|
163
|
+
# for testing only
|
164
|
+
def _nr_clear_traced_methods!
|
165
|
+
_nr_traced_method_module.module_eval do
|
166
|
+
self.instance_methods.each { |m| remove_method m }
|
220
167
|
end
|
221
168
|
end
|
222
169
|
|
223
|
-
|
224
|
-
|
225
|
-
def derived_class_name
|
170
|
+
def _nr_derived_class_name
|
226
171
|
return self.name if self.name && !self.name.empty?
|
227
172
|
return "AnonymousModule" if self.to_s.start_with?("#<Module:")
|
228
173
|
|
@@ -248,22 +193,26 @@ module NewRelic
|
|
248
193
|
#
|
249
194
|
# === Overriding the metric name
|
250
195
|
#
|
251
|
-
# +
|
252
|
-
#
|
253
|
-
# evaluated at call time, then single quote the value like this:
|
196
|
+
# +metric_name+ is a String or Proc. If a Proc is given, it is bound to
|
197
|
+
# the object that called the traced method. For example:
|
254
198
|
#
|
255
|
-
# add_method_tracer :foo,
|
199
|
+
# add_method_tracer :foo, -> { "Custom/#{self.class.name}/foo" }
|
256
200
|
#
|
257
201
|
# This would name the metric according to the class of the runtime
|
258
|
-
#
|
202
|
+
# instance, as opposed to the class where +foo+ is defined.
|
259
203
|
#
|
260
204
|
# If not provided, the metric name will be <tt>Custom/ClassName/method_name</tt>.
|
261
205
|
#
|
262
|
-
# @param [Symbol]
|
263
|
-
# @param [String]
|
264
|
-
# the traced method under. This may be either a
|
265
|
-
#
|
206
|
+
# @param method_name [Symbol] the name of the method to trace
|
207
|
+
# @param metric_name [String,Proc,Array] the metric name to record calls to
|
208
|
+
# the traced method under. This may be either a String, or a Proc
|
209
|
+
# to be evaluated at call-time in order to determine the metric
|
266
210
|
# name dynamically.
|
211
|
+
# This method also accepts an array of Strings/Procs, in which case the
|
212
|
+
# first metric given will be scoped, while the remaining metrics will be
|
213
|
+
# recorded as though passed with :push_scope => false. If an Array of
|
214
|
+
# metric names is given with :push_scope => false, all metrics will be
|
215
|
+
# unscoped.
|
267
216
|
# @param [Hash] options additional options controlling how the method is
|
268
217
|
# traced.
|
269
218
|
# @option options [Boolean] :push_scope (true) If false, the traced method will
|
@@ -272,16 +221,17 @@ module NewRelic
|
|
272
221
|
# @option options [Boolean] :metric (true) If false, the traced method will
|
273
222
|
# only appear in transaction traces, but no metrics will be recorded
|
274
223
|
# for it.
|
275
|
-
# @option options [
|
224
|
+
# @option options [Proc] :code_header ('') Ruby code to be inserted and run
|
276
225
|
# before the tracer begins timing.
|
277
|
-
# @option options [
|
226
|
+
# @option options [Proc] :code_footer ('') Ruby code to be inserted and run
|
278
227
|
# after the tracer stops timing.
|
279
228
|
#
|
280
229
|
# @example
|
281
230
|
# add_method_tracer :foo
|
282
231
|
#
|
283
232
|
# # With a custom metric name
|
284
|
-
# add_method_tracer :foo,
|
233
|
+
# add_method_tracer :foo, "Custom/MyClass/foo"
|
234
|
+
# add_method_tracer :bar, -> { "Custom/#{self.class.name}/bar" }
|
285
235
|
#
|
286
236
|
# # Instrument foo only for custom dashboards (not in transaction
|
287
237
|
# # traces or breakdown charts)
|
@@ -292,65 +242,116 @@ module NewRelic
|
|
292
242
|
#
|
293
243
|
# @api public
|
294
244
|
#
|
295
|
-
def add_method_tracer(method_name,
|
296
|
-
::NewRelic::Agent.add_or_defer_method_tracer(self, method_name,
|
245
|
+
def add_method_tracer(method_name, metric_name = nil, options = {})
|
246
|
+
::NewRelic::Agent.add_or_defer_method_tracer(self, method_name, metric_name, options)
|
297
247
|
end
|
298
248
|
|
299
249
|
# For tests only because tracers must be removed in reverse-order
|
300
250
|
# from when they were added, or else other tracers that were added to the same method
|
301
251
|
# may get removed as well.
|
302
|
-
def remove_method_tracer(method_name
|
252
|
+
def remove_method_tracer(method_name) # :nodoc:
|
303
253
|
return unless Agent.config[:agent_enabled]
|
304
|
-
if method_defined?
|
305
|
-
|
306
|
-
|
307
|
-
::NewRelic::Agent.logger.debug("removed method tracer #{method_name} #{metric_name_code}\n")
|
254
|
+
if _nr_traced_method_module.method_defined?(method_name)
|
255
|
+
_nr_traced_method_module.send(:remove_method, method_name)
|
256
|
+
::NewRelic::Agent.logger.debug("removed method tracer #{method_name}\n")
|
308
257
|
else
|
309
|
-
raise "No tracer
|
258
|
+
raise "No tracer on method '#{method_name}'"
|
310
259
|
end
|
311
260
|
end
|
312
261
|
|
313
262
|
private
|
314
263
|
|
315
|
-
def
|
264
|
+
def _nr_add_method_tracer_now(method_name, metric_name, options)
|
316
265
|
NewRelic::Agent.record_api_supportability_metric(:add_method_tracer)
|
317
|
-
|
318
266
|
return unless newrelic_method_exists?(method_name)
|
319
|
-
|
320
|
-
return if traced_method_exists?(method_name, metric_name_code)
|
267
|
+
remove_method_tracer(method_name) if method_traced?(method_name)
|
321
268
|
|
322
|
-
|
269
|
+
options = _nr_validate_method_tracer_options(method_name, options)
|
323
270
|
|
324
271
|
visibility = NewRelic::Helper.instance_method_visibility self, method_name
|
325
272
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
"metric = '#{metric_name_code}'")
|
335
|
-
end
|
273
|
+
scoped_metric, unscoped_metrics = _nr_scoped_unscoped_metrics(metric_name, method_name, push_scope: options[:push_scope])
|
274
|
+
|
275
|
+
_nr_define_traced_method(method_name, scoped_metric: scoped_metric, unscoped_metrics: unscoped_metrics,
|
276
|
+
code_header: options[:code_header], code_footer: options[:code_footer],
|
277
|
+
record_metrics: options[:metric], visibility: visibility,
|
278
|
+
code_information: options[:code_information])
|
279
|
+
|
280
|
+
prepend(_nr_traced_method_module)
|
336
281
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
"#{_sanitize_name(method_name)}_without_trace_#{_sanitize_name(metric_name)}"
|
282
|
+
::NewRelic::Agent.logger.debug("Traced method: class = #{_nr_derived_class_name}," +
|
283
|
+
"method = #{method_name}, " +
|
284
|
+
"metric = '#{metric_name}'")
|
341
285
|
end
|
342
286
|
|
343
|
-
#
|
344
|
-
#
|
345
|
-
|
346
|
-
|
287
|
+
# See #add_method_tracer; if multiple metric names are given, the first is
|
288
|
+
# treated as scoped, the rest unscoped. If options[:push_scope] is false,
|
289
|
+
# all given metrics are unscoped.
|
290
|
+
def _nr_scoped_unscoped_metrics(metric_name, method_name, push_scope: true)
|
291
|
+
if metric_name.is_a?(Array) && push_scope
|
292
|
+
[metric_name.shift, metric_name]
|
293
|
+
elsif push_scope
|
294
|
+
[metric_name || _nr_default_metric_name(method_name), []]
|
295
|
+
else
|
296
|
+
[nil, Array(metric_name)]
|
297
|
+
end
|
347
298
|
end
|
348
299
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
300
|
+
def _nr_define_traced_method(method_name, scoped_metric: nil, unscoped_metrics: [],
|
301
|
+
code_header: nil, code_footer: nil, record_metrics: true,
|
302
|
+
visibility: :public, code_information: {})
|
303
|
+
|
304
|
+
_nr_traced_method_module.module_eval do
|
305
|
+
define_method(method_name) do |*args, &block|
|
306
|
+
return super(*args, &block) unless NewRelic::Agent.tl_is_execution_traced?
|
307
|
+
scoped_metric_eval, unscoped_metrics_eval = nil, []
|
308
|
+
|
309
|
+
scoped_metric_eval = case scoped_metric
|
310
|
+
when Proc
|
311
|
+
instance_exec(*args, &scoped_metric)
|
312
|
+
when String
|
313
|
+
scoped_metric
|
314
|
+
end
|
315
|
+
|
316
|
+
unscoped_metrics_eval = unscoped_metrics.map do |metric|
|
317
|
+
metric.kind_of?(Proc) ? instance_exec(*args, &metric) : metric.to_s
|
318
|
+
end
|
319
|
+
|
320
|
+
instance_exec(&code_header) if code_header.kind_of?(Proc)
|
321
|
+
|
322
|
+
# NOTE: Calling ::NewRelic::Agent::MethodTracer.trace_execution_scoped and
|
323
|
+
# .trace_execution_unscoped below relies on the fact that MethodTracer is included
|
324
|
+
# in Module on agent startup. If/when this changes, these methods should be
|
325
|
+
# explicitly namespaced and extended in MethodTracer.
|
326
|
+
|
327
|
+
# If tracing multiple metrics on this method, nest one unscoped trace inside the scoped trace.
|
328
|
+
begin
|
329
|
+
if scoped_metric_eval
|
330
|
+
::NewRelic::Agent::MethodTracer.trace_execution_scoped(scoped_metric_eval,
|
331
|
+
metric: record_metrics,
|
332
|
+
internal: true,
|
333
|
+
code_information: code_information) do
|
334
|
+
if unscoped_metrics_eval.empty?
|
335
|
+
super(*args, &block)
|
336
|
+
else
|
337
|
+
::NewRelic::Agent::MethodTracer.trace_execution_unscoped(unscoped_metrics_eval, internal: true) do
|
338
|
+
super(*args, &block)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
elsif !unscoped_metrics_eval.empty?
|
343
|
+
::NewRelic::Agent::MethodTracer.trace_execution_unscoped(unscoped_metrics_eval, internal: true) do
|
344
|
+
super(*args, &block)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
ensure
|
348
|
+
instance_exec(&code_footer) if code_footer.kind_of?(Proc)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
send visibility, method_name
|
353
|
+
ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
|
354
|
+
end
|
354
355
|
end
|
355
356
|
end
|
356
357
|
|
@@ -5,16 +5,23 @@
|
|
5
5
|
module NewRelic
|
6
6
|
module Agent
|
7
7
|
module MethodTracerHelpers
|
8
|
+
# These are code level metrics (CLM) attributes. For Ruby, they map like so:
|
9
|
+
# filepath: full path to an .rb file on disk
|
10
|
+
# lineno: the line number a Ruby method is defined on within a given .rb file
|
11
|
+
# function: the name of the Ruby method
|
12
|
+
# namespace: the Ruby class' namespace as a string, ex: 'MyModule::MyClass'
|
13
|
+
SOURCE_CODE_INFORMATION_PARAMETERS = %i[filepath lineno function namespace].freeze
|
14
|
+
SOURCE_CODE_INFORMATION_FAILURE_METRIC = "Supportabiltiy/CodeLevelMetrics/Ruby/Failure".freeze
|
8
15
|
MAX_ALLOWED_METRIC_DURATION = 1_000_000_000 # roughly 31 years
|
9
16
|
|
10
17
|
extend self
|
11
18
|
|
12
|
-
def trace_execution_scoped(metric_names, options=NewRelic::EMPTY_HASH) #THREAD_LOCAL_ACCESS
|
19
|
+
def trace_execution_scoped(metric_names, options = NewRelic::EMPTY_HASH) # THREAD_LOCAL_ACCESS
|
13
20
|
state = NewRelic::Agent::Tracer.state
|
14
21
|
return yield unless state.is_execution_traced?
|
15
22
|
|
16
23
|
metric_names = Array(metric_names)
|
17
|
-
first_name
|
24
|
+
first_name = metric_names.shift
|
18
25
|
return yield unless first_name
|
19
26
|
|
20
27
|
segment = NewRelic::Agent::Tracer.start_segment(
|
@@ -26,12 +33,85 @@ module NewRelic
|
|
26
33
|
segment.record_metrics = false
|
27
34
|
end
|
28
35
|
|
36
|
+
unless !options.key?(:code_information) || options[:code_information].nil? || options[:code_information].empty?
|
37
|
+
segment.code_information = options[:code_information]
|
38
|
+
end
|
39
|
+
|
29
40
|
begin
|
30
41
|
Tracer.capture_segment_error(segment) { yield }
|
31
42
|
ensure
|
32
43
|
segment.finish if segment
|
33
44
|
end
|
34
45
|
end
|
46
|
+
|
47
|
+
def code_information(object, method_name)
|
48
|
+
unless NewRelic::Agent.config[:'code_level_metrics.enabled'] && object && method_name
|
49
|
+
return NewRelic::EMPTY_HASH
|
50
|
+
end
|
51
|
+
|
52
|
+
@code_information ||= {}
|
53
|
+
cache_key = "#{object.object_id}#{method_name}"
|
54
|
+
return @code_information[cache_key] if @code_information.key?(cache_key)
|
55
|
+
|
56
|
+
namespace, location, is_class_method = namespace_and_location(object, method_name.to_sym)
|
57
|
+
|
58
|
+
@code_information[cache_key] = {filepath: location.first,
|
59
|
+
lineno: location.last,
|
60
|
+
function: "#{'self.' if is_class_method}#{method_name}",
|
61
|
+
namespace: namespace}
|
62
|
+
rescue => e
|
63
|
+
::NewRelic::Agent.logger.warn("Unable to determine source code info for '#{object}', " \
|
64
|
+
"method '#{method_name}' - #{e.class}: #{e.message}")
|
65
|
+
::NewRelic::Agent.increment_metric(SOURCE_CODE_INFORMATION_FAILURE_METRIC, 1)
|
66
|
+
::NewRelic::EMPTY_HASH
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# The string representation of a singleton class looks like
|
72
|
+
# '#<Class:MyModule::MyClass>'. Return the 'MyModule::MyClass' part of
|
73
|
+
# that string
|
74
|
+
def klass_name(object)
|
75
|
+
name = Regexp.last_match(1) if object.to_s =~ /^#<Class:(.*)>$/
|
76
|
+
return name if name
|
77
|
+
|
78
|
+
raise "Unable to glean a class name from string '#{object}'" unless name
|
79
|
+
end
|
80
|
+
|
81
|
+
# get at the underlying class from the singleton class
|
82
|
+
#
|
83
|
+
# note: even with the regex hit from klass_name(), `Object.const_get`
|
84
|
+
# is more performant than iterating through `ObjectSpace`
|
85
|
+
def klassify_singleton(object)
|
86
|
+
Object.const_get(klass_name(object))
|
87
|
+
end
|
88
|
+
|
89
|
+
# determine the namespace (class name including all module names in scope)
|
90
|
+
# and source code location (file path and line number) for the given
|
91
|
+
# object and method name
|
92
|
+
#
|
93
|
+
# traced class methods:
|
94
|
+
# * object is a singleton class, `#<Class::MyClass>`
|
95
|
+
# * get at the underlying non-singleton class
|
96
|
+
#
|
97
|
+
# traced instance methods and Rails controller methods:
|
98
|
+
# * object is a class, `MyClass`
|
99
|
+
#
|
100
|
+
# anonymous class based methods (`c = Class.new { def method; end; }`:
|
101
|
+
# * `#name` returns `nil`, so use '(Anonymous)' instead
|
102
|
+
#
|
103
|
+
def namespace_and_location(object, method_name)
|
104
|
+
klass = object.singleton_class? ? klassify_singleton(object) : object
|
105
|
+
name = klass.name || '(Anonymous)'
|
106
|
+
is_class_method = false
|
107
|
+
method = if klass.instance_methods.include?(method_name)
|
108
|
+
klass.instance_method(method_name)
|
109
|
+
else
|
110
|
+
is_class_method = true
|
111
|
+
klass.method(method_name)
|
112
|
+
end
|
113
|
+
[name, method.source_location, is_class_method]
|
114
|
+
end
|
35
115
|
end
|
36
116
|
end
|
37
117
|
end
|
@@ -12,22 +12,28 @@ module NewRelic
|
|
12
12
|
module Agent
|
13
13
|
module DistributedTracing
|
14
14
|
class CrossAppMonitor < InboundRequestMonitor
|
15
|
-
|
16
|
-
|
17
|
-
NEWRELIC_TXN_HEADER = 'X-NewRelic-Transaction'.freeze
|
15
|
+
NEWRELIC_ID_HEADER = 'X-NewRelic-ID'.freeze
|
16
|
+
NEWRELIC_TXN_HEADER = 'X-NewRelic-Transaction'.freeze
|
18
17
|
NEWRELIC_APPDATA_HEADER = 'X-NewRelic-App-Data'.freeze
|
19
18
|
|
20
|
-
NEWRELIC_ID_HEADER_KEY
|
21
|
-
NEWRELIC_TXN_HEADER_KEY
|
19
|
+
NEWRELIC_ID_HEADER_KEY = 'HTTP_X_NEWRELIC_ID'.freeze
|
20
|
+
NEWRELIC_TXN_HEADER_KEY = 'HTTP_X_NEWRELIC_TRANSACTION'.freeze
|
22
21
|
CONTENT_LENGTH_HEADER_KEY = 'HTTP_CONTENT_LENGTH'.freeze
|
23
22
|
|
24
23
|
def on_finished_configuring(events)
|
24
|
+
if CrossAppTracing.cross_app_enabled?
|
25
|
+
Deprecator.deprecate('cross_application_tracer')
|
26
|
+
::NewRelic::Agent.logger.warn(
|
27
|
+
"[DEPRECATED] Cross application tracing is enabled. Distributed tracing is replacing cross application tracing as the default means of tracing between services. To continue using cross application tracing, enable it with `cross_application_tracer.enabled: true` and `distributed_tracing.enabled: false`"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
25
31
|
register_event_listeners(events)
|
26
32
|
end
|
27
33
|
|
28
34
|
def path_hash(txn_name, seed)
|
29
|
-
rotated
|
30
|
-
app_name
|
35
|
+
rotated = ((seed << 1) | (seed >> 31)) & 0xffffffff
|
36
|
+
app_name = NewRelic::Agent.config[:app_name].first
|
31
37
|
identifier = "#{app_name};#{txn_name}"
|
32
38
|
sprintf("%08x", rotated ^ hash_transaction_name(identifier))
|
33
39
|
end
|
@@ -38,10 +44,10 @@ module NewRelic
|
|
38
44
|
# :before_call will save our cross application request id to the thread
|
39
45
|
# :after_call will write our response headers/metrics and clean up the thread
|
40
46
|
def register_event_listeners(events)
|
41
|
-
NewRelic::Agent.logger
|
42
|
-
debug("Wiring up Cross Application Tracing to events after finished configuring")
|
47
|
+
NewRelic::Agent.logger
|
48
|
+
.debug("Wiring up Cross Application Tracing to events after finished configuring")
|
43
49
|
|
44
|
-
events.subscribe(:before_call) do |env| #THREAD_LOCAL_ACCESS
|
50
|
+
events.subscribe(:before_call) do |env| # THREAD_LOCAL_ACCESS
|
45
51
|
if id = decoded_id(env) and should_process_request?(id)
|
46
52
|
state = NewRelic::Agent::Tracer.state
|
47
53
|
|
@@ -56,7 +62,7 @@ module NewRelic
|
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
59
|
-
events.subscribe(:after_call) do |env, (_status_code, headers, _body)| #THREAD_LOCAL_ACCESS
|
65
|
+
events.subscribe(:after_call) do |env, (_status_code, headers, _body)| # THREAD_LOCAL_ACCESS
|
60
66
|
state = NewRelic::Agent::Tracer.state
|
61
67
|
|
62
68
|
insert_response_header(state, env, headers)
|
@@ -85,7 +91,9 @@ module NewRelic
|
|
85
91
|
def set_response_headers(transaction, response_headers, content_length)
|
86
92
|
payload = obfuscator.obfuscate(
|
87
93
|
::JSON.dump(
|
88
|
-
transaction.distributed_tracer.cross_app_payload.as_json_array(content_length)
|
94
|
+
transaction.distributed_tracer.cross_app_payload.as_json_array(content_length)
|
95
|
+
)
|
96
|
+
)
|
89
97
|
|
90
98
|
response_headers[NEWRELIC_APPDATA_HEADER] = payload
|
91
99
|
end
|
@@ -107,4 +115,4 @@ module NewRelic
|
|
107
115
|
end
|
108
116
|
end
|
109
117
|
end
|
110
|
-
end
|
118
|
+
end
|
@@ -13,7 +13,7 @@ module NewRelic
|
|
13
13
|
|
14
14
|
def on_before_call(request)
|
15
15
|
unless NewRelic::Agent.config[:'distributed_tracing.enabled']
|
16
|
-
NewRelic::Agent.logger.warn "Not configured to accept distributed trace headers"
|
16
|
+
NewRelic::Agent.logger.warn "Not configured to accept distributed trace headers"
|
17
17
|
return
|
18
18
|
end
|
19
19
|
|
@@ -24,4 +24,4 @@ module NewRelic
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|