newrelic_rpm 7.2.0 → 8.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1936 -0
- data/CHANGELOG.md +182 -9
- data/CONTRIBUTING.md +14 -2
- data/Guardfile +8 -8
- data/README.md +5 -1
- data/Rakefile +5 -7
- data/bin/mongrel_rpm +8 -9
- data/bin/newrelic +1 -1
- data/bin/nrdebug +14 -14
- 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 +44 -46
- data/lib/new_relic/agent/agent_logger.rb +8 -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/autostart.rb +6 -7
- 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 +352 -336
- data/lib/new_relic/agent/configuration/dotted_hash.rb +3 -3
- data/lib/new_relic/agent/configuration/environment_source.rb +3 -4
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +30 -16
- data/lib/new_relic/agent/configuration/high_security_source.rb +7 -7
- data/lib/new_relic/agent/configuration/manager.rb +57 -58
- 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 +12 -11
- data/lib/new_relic/agent/configuration/yaml_source.rb +26 -5
- data/lib/new_relic/agent/connect/request_builder.rb +13 -16
- 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 +25 -26
- data/lib/new_relic/agent/datastores/metric_helper.rb +10 -10
- 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 +17 -17
- data/lib/new_relic/agent/error_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/error_filter.rb +16 -10
- 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 +1 -3
- 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 +3 -3
- 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 +10 -11
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
- data/lib/new_relic/agent/instrumentation/active_job.rb +4 -3
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
- data/lib/new_relic/agent/instrumentation/active_record.rb +20 -18
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +36 -42
- 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 +5 -6
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +8 -9
- 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 +42 -42
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +19 -20
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +34 -38
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +9 -10
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +10 -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 +4 -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 +25 -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 +4 -5
- 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 +1 -1
- 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 +5 -5
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +0 -1
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +4 -5
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +0 -1
- 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/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 +1 -1
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +2 -3
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -4
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +1 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +7 -7
- 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 +7 -1
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +0 -1
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +4 -3
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- 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 +30 -30
- 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 -61
- data/lib/new_relic/agent/method_tracer.rb +139 -143
- data/lib/new_relic/agent/method_tracer_helpers.rb +2 -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 +34 -41
- 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 +3 -5
- 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 +2 -2
- 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 +4 -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 +39 -39
- data/lib/new_relic/agent/sql_sampler.rb +9 -9
- data/lib/new_relic/agent/stats.rb +16 -16
- 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 +0 -1
- 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 +43 -71
- data/lib/new_relic/agent/transaction/abstract_segment.rb +9 -9
- 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 +13 -15
- data/lib/new_relic/agent/transaction/trace_node.rb +16 -16
- data/lib/new_relic/agent/transaction/tracing.rb +1 -3
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -2
- data/lib/new_relic/agent/transaction.rb +85 -108
- data/lib/new_relic/agent/transaction_error_primitive.rb +16 -16
- data/lib/new_relic/agent/transaction_event_aggregator.rb +5 -6
- data/lib/new_relic/agent/transaction_event_primitive.rb +29 -29
- data/lib/new_relic/agent/transaction_metrics.rb +3 -3
- 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/azure.rb +1 -1
- 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/snapshot.rb +4 -4
- data/lib/new_relic/agent/worker_loop.rb +8 -10
- data/lib/new_relic/agent.rb +27 -27
- 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/instance_methods.rb +4 -5
- data/lib/new_relic/control/instrumentation.rb +4 -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 +6 -8
- data/lib/new_relic/environment_report.rb +16 -18
- data/lib/new_relic/helper.rb +5 -5
- data/lib/new_relic/language_support.rb +1 -1
- data/lib/new_relic/latest_changes.rb +2 -2
- data/lib/new_relic/local_environment.rb +7 -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 +16 -17
- 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 +1 -2
- data/lib/new_relic/version.rb +4 -5
- 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.rake +21 -21
- data/lib/tasks/multiverse.rb +4 -6
- data/lib/tasks/tests.rake +3 -7
- data/newrelic.yml +580 -3
- data/newrelic_rpm.gemspec +13 -12
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +80 -55
- metadata +42 -13
- 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
@@ -7,12 +7,12 @@ module NewRelic
|
|
7
7
|
module VM
|
8
8
|
class Snapshot
|
9
9
|
attr_accessor :gc_total_time, :gc_runs, :major_gc_count, :minor_gc_count,
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
:total_allocated_object, :heap_live, :heap_free,
|
11
|
+
:method_cache_invalidations, :constant_cache_invalidations,
|
12
|
+
:thread_count, :taken_at
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
@taken_at =
|
15
|
+
@taken_at = Process.clock_gettime(Process::CLOCK_REALTIME)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -6,19 +6,17 @@ require 'thread'
|
|
6
6
|
|
7
7
|
module NewRelic
|
8
8
|
module Agent
|
9
|
-
|
10
9
|
# A worker loop executes a set of registered tasks on a single thread.
|
11
10
|
# A task is a proc or block with a specified call period in seconds.
|
12
11
|
class WorkerLoop
|
13
|
-
|
14
12
|
attr_accessor :period, :propagate_errors
|
15
13
|
attr_reader :iterations
|
16
14
|
|
17
15
|
# Optional argument :duration (in seconds) for how long the worker loop runs
|
18
16
|
# or :limit (integer) for max number of iterations
|
19
|
-
def initialize(opts={})
|
17
|
+
def initialize(opts = {})
|
20
18
|
@should_run = true
|
21
|
-
@next_invocation_time =
|
19
|
+
@next_invocation_time = Process.clock_gettime(Process::CLOCK_REALTIME)
|
22
20
|
@period = 60.0
|
23
21
|
@duration = opts[:duration]
|
24
22
|
@limit = opts[:limit]
|
@@ -34,7 +32,7 @@ module NewRelic
|
|
34
32
|
@should_run = true
|
35
33
|
@iterations = 0
|
36
34
|
|
37
|
-
now =
|
35
|
+
now = Process.clock_gettime(Process::CLOCK_REALTIME)
|
38
36
|
@deadline = now + @duration if @duration
|
39
37
|
@next_invocation_time = (now + @period)
|
40
38
|
end
|
@@ -42,9 +40,9 @@ module NewRelic
|
|
42
40
|
# Run infinitely, calling the registered tasks at their specified
|
43
41
|
# call periods. The caller is responsible for creating the thread
|
44
42
|
# that runs this worker loop. This will run the task immediately.
|
45
|
-
def run(period=nil, &block)
|
43
|
+
def run(period = nil, &block)
|
46
44
|
setup(period, block)
|
47
|
-
while keep_running?
|
45
|
+
while keep_running?
|
48
46
|
sleep_time = schedule_next_invocation
|
49
47
|
sleep(sleep_time) if sleep_time > 0
|
50
48
|
run_task if keep_running?
|
@@ -53,11 +51,11 @@ module NewRelic
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def schedule_next_invocation
|
56
|
-
now =
|
54
|
+
now = Process.clock_gettime(Process::CLOCK_REALTIME)
|
57
55
|
while @next_invocation_time <= now && @period > 0
|
58
56
|
@next_invocation_time += @period
|
59
57
|
end
|
60
|
-
@next_invocation_time -
|
58
|
+
@next_invocation_time - Process.clock_gettime(Process::CLOCK_REALTIME)
|
61
59
|
end
|
62
60
|
|
63
61
|
# a simple accessor for @should_run
|
@@ -66,7 +64,7 @@ module NewRelic
|
|
66
64
|
end
|
67
65
|
|
68
66
|
def under_duration?
|
69
|
-
!@deadline ||
|
67
|
+
!@deadline || Process.clock_gettime(Process::CLOCK_REALTIME) < @deadline
|
70
68
|
end
|
71
69
|
|
72
70
|
def under_limit?
|
data/lib/new_relic/agent.rb
CHANGED
@@ -44,7 +44,7 @@ module NewRelic
|
|
44
44
|
require 'new_relic/agent/sql_sampler'
|
45
45
|
require 'new_relic/agent/commands/thread_profiler_session'
|
46
46
|
require 'new_relic/agent/error_collector'
|
47
|
-
require 'new_relic/agent/error_filter'
|
47
|
+
require 'new_relic/agent/error_filter'
|
48
48
|
require 'new_relic/agent/sampler'
|
49
49
|
require 'new_relic/agent/database'
|
50
50
|
require 'new_relic/agent/database_adapter'
|
@@ -111,19 +111,19 @@ module NewRelic
|
|
111
111
|
@tracer_queue = []
|
112
112
|
|
113
113
|
# The singleton Agent instance. Used internally.
|
114
|
-
def agent
|
114
|
+
def agent # :nodoc:
|
115
115
|
return @agent if @agent
|
116
116
|
NewRelic::Agent.logger.warn("Agent unavailable as it hasn't been started.")
|
117
117
|
NewRelic::Agent.logger.warn(caller.join("\n"))
|
118
118
|
nil
|
119
119
|
end
|
120
120
|
|
121
|
-
def agent=(new_instance)
|
121
|
+
def agent=(new_instance) # :nodoc:
|
122
122
|
@agent = new_instance
|
123
123
|
add_deferred_method_tracers_now
|
124
124
|
end
|
125
125
|
|
126
|
-
alias instance agent
|
126
|
+
alias instance agent # :nodoc:
|
127
127
|
|
128
128
|
# Primary interface to logging is fronted by this accessor
|
129
129
|
# Access via ::NewRelic::Agent.logger
|
@@ -139,20 +139,20 @@ module NewRelic
|
|
139
139
|
# is initialized; these methods enable us to defer these calls
|
140
140
|
# until we have started up and can process them.
|
141
141
|
#
|
142
|
-
def add_or_defer_method_tracer(receiver, method_name,
|
142
|
+
def add_or_defer_method_tracer(receiver, method_name, metric_name, options)
|
143
143
|
@tracer_lock.synchronize do
|
144
144
|
if @agent
|
145
|
-
receiver.send(:
|
145
|
+
receiver.send(:_nr_add_method_tracer_now, method_name, metric_name, options)
|
146
146
|
else
|
147
|
-
@tracer_queue << [receiver, method_name,
|
147
|
+
@tracer_queue << [receiver, method_name, metric_name, options]
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
152
|
def add_deferred_method_tracers_now
|
153
153
|
@tracer_lock.synchronize do
|
154
|
-
@tracer_queue.each do |receiver, method_name,
|
155
|
-
receiver.send(:
|
154
|
+
@tracer_queue.each do |receiver, method_name, metric_name, options|
|
155
|
+
receiver.send(:_nr_add_method_tracer_now, method_name, metric_name, options)
|
156
156
|
end
|
157
157
|
|
158
158
|
@tracer_queue = []
|
@@ -187,7 +187,7 @@ module NewRelic
|
|
187
187
|
# This method is safe to use from any thread.
|
188
188
|
#
|
189
189
|
# @api public
|
190
|
-
def record_metric(metric_name, value) #THREAD_LOCAL_ACCESS
|
190
|
+
def record_metric(metric_name, value) # THREAD_LOCAL_ACCESS
|
191
191
|
record_api_supportability_metric(:record_metric)
|
192
192
|
|
193
193
|
return unless agent
|
@@ -217,14 +217,14 @@ module NewRelic
|
|
217
217
|
|
218
218
|
SUPPORTABILITY_INCREMENT_METRIC = 'Supportability/API/increment_metric'.freeze
|
219
219
|
|
220
|
-
def increment_metric(metric_name, amount=1) #THREAD_LOCAL_ACCESS
|
220
|
+
def increment_metric(metric_name, amount = 1) # THREAD_LOCAL_ACCESS
|
221
221
|
return unless agent
|
222
222
|
if amount == 1
|
223
223
|
metrics = [metric_name, SUPPORTABILITY_INCREMENT_METRIC]
|
224
|
-
agent.stats_engine.tl_record_unscoped_metrics(metrics) {|stats| stats.increment_count}
|
224
|
+
agent.stats_engine.tl_record_unscoped_metrics(metrics) { |stats| stats.increment_count }
|
225
225
|
else
|
226
|
-
agent.stats_engine.tl_record_unscoped_metrics(metric_name) {|stats| stats.increment_count(amount)}
|
227
|
-
agent.stats_engine.tl_record_unscoped_metrics(SUPPORTABILITY_INCREMENT_METRIC) {|stats| stats.increment_count}
|
226
|
+
agent.stats_engine.tl_record_unscoped_metrics(metric_name) { |stats| stats.increment_count(amount) }
|
227
|
+
agent.stats_engine.tl_record_unscoped_metrics(SUPPORTABILITY_INCREMENT_METRIC) { |stats| stats.increment_count }
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
@@ -281,7 +281,7 @@ module NewRelic
|
|
281
281
|
#
|
282
282
|
# @api public
|
283
283
|
#
|
284
|
-
def notice_error(exception, options={})
|
284
|
+
def notice_error(exception, options = {})
|
285
285
|
record_api_supportability_metric(:notice_error)
|
286
286
|
|
287
287
|
Transaction.notice_error(exception, options)
|
@@ -347,9 +347,9 @@ module NewRelic
|
|
347
347
|
#
|
348
348
|
# @api public
|
349
349
|
#
|
350
|
-
def manual_start(options={})
|
350
|
+
def manual_start(options = {})
|
351
351
|
raise "Options must be a hash" unless Hash === options
|
352
|
-
NewRelic::Control.instance.init_plugin({
|
352
|
+
NewRelic::Control.instance.init_plugin({:agent_enabled => true, :sync_startup => true}.merge(options))
|
353
353
|
record_api_supportability_metric(:manual_start)
|
354
354
|
end
|
355
355
|
|
@@ -378,7 +378,7 @@ module NewRelic
|
|
378
378
|
#
|
379
379
|
# @api public
|
380
380
|
#
|
381
|
-
def after_fork(options={})
|
381
|
+
def after_fork(options = {})
|
382
382
|
record_api_supportability_metric(:after_fork)
|
383
383
|
agent.after_fork(options) if agent
|
384
384
|
end
|
@@ -390,7 +390,7 @@ module NewRelic
|
|
390
390
|
#
|
391
391
|
# @api public
|
392
392
|
#
|
393
|
-
def shutdown(options={})
|
393
|
+
def shutdown(options = {})
|
394
394
|
record_api_supportability_metric(:shutdown)
|
395
395
|
agent.shutdown if agent
|
396
396
|
end
|
@@ -512,7 +512,7 @@ module NewRelic
|
|
512
512
|
#
|
513
513
|
def disable_transaction_tracing
|
514
514
|
Deprecator.deprecate :disable_transaction_tracing,
|
515
|
-
|
515
|
+
'disable_all_tracing or ignore_transaction'
|
516
516
|
record_api_supportability_metric(:disable_transaction_tracing)
|
517
517
|
yield
|
518
518
|
end
|
@@ -572,7 +572,7 @@ module NewRelic
|
|
572
572
|
#
|
573
573
|
# @api public
|
574
574
|
#
|
575
|
-
def add_custom_attributes(params) #THREAD_LOCAL_ACCESS
|
575
|
+
def add_custom_attributes(params) # THREAD_LOCAL_ACCESS
|
576
576
|
record_api_supportability_metric(:add_custom_attributes)
|
577
577
|
|
578
578
|
if params.is_a? Hash
|
@@ -644,7 +644,7 @@ module NewRelic
|
|
644
644
|
#
|
645
645
|
# @api public
|
646
646
|
#
|
647
|
-
def set_transaction_name(name, options={})
|
647
|
+
def set_transaction_name(name, options = {})
|
648
648
|
record_api_supportability_metric(:set_transaction_name)
|
649
649
|
Transaction.set_overriding_transaction_name(name, options[:category])
|
650
650
|
end
|
@@ -654,7 +654,7 @@ module NewRelic
|
|
654
654
|
#
|
655
655
|
# @api public
|
656
656
|
#
|
657
|
-
def get_transaction_name #THREAD_LOCAL_ACCESS
|
657
|
+
def get_transaction_name # THREAD_LOCAL_ACCESS
|
658
658
|
record_api_supportability_metric(:get_transaction_name)
|
659
659
|
|
660
660
|
txn = Transaction.tl_current
|
@@ -686,13 +686,13 @@ module NewRelic
|
|
686
686
|
# Subscribe to events of +event_type+, calling the given +handler+
|
687
687
|
# when one is sent.
|
688
688
|
def subscribe(event_type, &handler)
|
689
|
-
agent.events.subscribe(
|
689
|
+
agent.events.subscribe(event_type, &handler)
|
690
690
|
end
|
691
691
|
|
692
692
|
# Fire an event of the specified +event_type+, passing it an the given +args+
|
693
693
|
# to any registered handlers.
|
694
694
|
def notify(event_type, *args)
|
695
|
-
agent.events.notify(
|
695
|
+
agent.events.notify(event_type, *args)
|
696
696
|
rescue
|
697
697
|
NewRelic::Agent.logger.debug "Ignoring exception during %p event notification" % [event_type]
|
698
698
|
end
|
@@ -743,7 +743,7 @@ module NewRelic
|
|
743
743
|
metadata
|
744
744
|
end
|
745
745
|
|
746
|
-
|
746
|
+
# @!endgroup
|
747
747
|
|
748
748
|
# @!group Manual browser monitoring configuration
|
749
749
|
|
@@ -763,7 +763,7 @@ module NewRelic
|
|
763
763
|
#
|
764
764
|
# @api public
|
765
765
|
#
|
766
|
-
def browser_timing_header(nonce=nil)
|
766
|
+
def browser_timing_header(nonce = nil)
|
767
767
|
record_api_supportability_metric(:browser_timing_header)
|
768
768
|
|
769
769
|
return "" unless agent
|
@@ -15,7 +15,7 @@ module NewRelic
|
|
15
15
|
# Capture a failure to execute the command.
|
16
16
|
class CommandFailure < StandardError
|
17
17
|
attr_reader :options
|
18
|
-
def initialize message, opt_parser=nil
|
18
|
+
def initialize message, opt_parser = nil
|
19
19
|
super message
|
20
20
|
@options = opt_parser
|
21
21
|
end
|
@@ -32,13 +32,13 @@ module NewRelic
|
|
32
32
|
def initialize(command_line_args)
|
33
33
|
if Hash === command_line_args
|
34
34
|
# command line args is an options hash
|
35
|
-
command_line_args.each do |
|
35
|
+
command_line_args.each do |key, value|
|
36
36
|
instance_variable_set "@#{key}", value.to_s if value
|
37
37
|
end
|
38
38
|
else
|
39
39
|
# parse command line args. Throw an exception on a bad arg.
|
40
|
-
@options = options do |
|
41
|
-
opts.on("-h", "Show this help") {
|
40
|
+
@options = options do |opts|
|
41
|
+
opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
|
42
42
|
end
|
43
43
|
@leftover = @options.parse(command_line_args)
|
44
44
|
end
|
@@ -55,8 +55,7 @@ module NewRelic
|
|
55
55
|
Dir[cmds].each { |command| require command }
|
56
56
|
|
57
57
|
def self.run
|
58
|
-
|
59
|
-
@command_names = @commands.map{ |c| c.command }
|
58
|
+
@command_names = @commands.map { |c| c.command }
|
60
59
|
|
61
60
|
extra = []
|
62
61
|
options = ARGV.options do |opts|
|
@@ -65,7 +64,7 @@ module NewRelic
|
|
65
64
|
$stdout.puts "warning: the 'newrelic_cmd' script has been renamed 'newrelic'"
|
66
65
|
script_name = 'newrelic'
|
67
66
|
end
|
68
|
-
opts.banner = "Usage: #{script_name} [ #{
|
67
|
+
opts.banner = "Usage: #{script_name} [ #{@command_names.join(" | ")} ] [options]"
|
69
68
|
opts.separator "use '#{script_name} <command> -h' to see detailed command options"
|
70
69
|
opts
|
71
70
|
end
|
@@ -73,19 +72,18 @@ module NewRelic
|
|
73
72
|
command = extra.shift
|
74
73
|
# just make it a little easier on them
|
75
74
|
command = 'deployments' if command =~ /deploy/
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
if command.nil?
|
76
|
+
STDERR.puts options
|
77
|
+
elsif !@command_names.include?(command)
|
78
|
+
STDERR.puts "Unrecognized command: #{command}"
|
79
|
+
STDERR.puts options
|
80
|
+
else
|
81
|
+
command_class = @commands.find { |c| c.command == command }
|
82
|
+
command_class.new(extra).run
|
83
|
+
end
|
85
84
|
rescue OptionParser::InvalidOption => e
|
86
85
|
raise NewRelic::Cli::Command::CommandFailure, e.message
|
87
86
|
end
|
88
87
|
end
|
89
|
-
|
90
88
|
end
|
91
89
|
end
|
@@ -10,7 +10,7 @@ require 'net/http'
|
|
10
10
|
require 'new_relic/agent/hostname'
|
11
11
|
|
12
12
|
# We need to use the Control object but we don't want to load
|
13
|
-
# the rails
|
13
|
+
# the rails environment. The defined? clause is so that
|
14
14
|
# it won't load it twice, something it does when run inside a test
|
15
15
|
require 'new_relic/control' unless defined? NewRelic::Control
|
16
16
|
|
@@ -30,8 +30,8 @@ class NewRelic::Cli::Deployments < NewRelic::Cli::Command
|
|
30
30
|
def initialize command_line_args
|
31
31
|
@control = NewRelic::Control.instance
|
32
32
|
@environment = nil
|
33
|
-
@changelog
|
34
|
-
@user
|
33
|
+
@changelog = nil
|
34
|
+
@user = nil
|
35
35
|
super(command_line_args)
|
36
36
|
@description ||= @leftover && @leftover.join(" ")
|
37
37
|
@user ||= ENV['USER']
|
@@ -66,12 +66,12 @@ class NewRelic::Cli::Deployments < NewRelic::Cli::Command
|
|
66
66
|
@description = nil if @description && @description.strip.empty?
|
67
67
|
create_params = {}
|
68
68
|
{
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
:application_id => @appname,
|
70
|
+
:host => NewRelic::Agent::Hostname.get,
|
71
|
+
:description => @description,
|
72
|
+
:user => @user,
|
73
|
+
:revision => @revision,
|
74
|
+
:changelog => @changelog
|
75
75
|
}.each do |k, v|
|
76
76
|
create_params["deployment[#{k}]"] = v unless v.nil? || v == ''
|
77
77
|
end
|
@@ -90,9 +90,9 @@ class NewRelic::Cli::Deployments < NewRelic::Cli::Command
|
|
90
90
|
response = http.request(request)
|
91
91
|
|
92
92
|
if response.is_a? Net::HTTPSuccess
|
93
|
-
info "Recorded deployment to '#{@appname}' (#{@description || Time.now
|
93
|
+
info "Recorded deployment to '#{@appname}' (#{@description || Time.now})"
|
94
94
|
else
|
95
|
-
err_string = REXML::Document.new(response.body).elements['errors/error'].map(&:to_s).join("; ") rescue
|
95
|
+
err_string = REXML::Document.new(response.body).elements['errors/error'].map(&:to_s).join("; ") rescue response.message
|
96
96
|
raise NewRelic::Cli::Command::CommandFailure, "Deployment not recorded: #{err_string}"
|
97
97
|
end
|
98
98
|
rescue SystemCallError, SocketError => e
|
@@ -111,26 +111,24 @@ class NewRelic::Cli::Deployments < NewRelic::Cli::Command
|
|
111
111
|
private
|
112
112
|
|
113
113
|
def options
|
114
|
-
OptionParser.new %Q
|
114
|
+
OptionParser.new %Q(Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] ), 40 do |o|
|
115
115
|
o.separator "OPTIONS:"
|
116
116
|
o.on("-a", "--appname=NAME", String,
|
117
|
-
|
118
|
-
|
117
|
+
"Set the application name.",
|
118
|
+
"Default is app_name setting in newrelic.yml") { |e| @appname = e }
|
119
119
|
o.on("-e", "--environment=name", String,
|
120
|
-
|
121
|
-
|
120
|
+
"Override the (RAILS|RUBY|RACK)_ENV setting",
|
121
|
+
"currently: #{control.env}") { |e| @environment = e }
|
122
122
|
o.on("-u", "--user=USER", String,
|
123
|
-
|
124
|
-
|
123
|
+
"Specify the user deploying, for information only",
|
124
|
+
"Default: #{@user || '<none>'}") { |u| @user = u }
|
125
125
|
o.on("-r", "--revision=REV", String,
|
126
|
-
|
126
|
+
"Specify the revision being deployed") { |r| @revision = r }
|
127
127
|
o.on("-l", "--license-key=KEY", String,
|
128
|
-
|
128
|
+
"Specify the license key of the account for the app being deployed") { |l| @license_key = l }
|
129
129
|
o.on("-c", "--changes",
|
130
|
-
|
130
|
+
"Read in a change log from the standard input") { @changelog = STDIN.read }
|
131
131
|
yield o if block_given?
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
135
|
-
|
136
134
|
end
|
@@ -7,7 +7,6 @@ require 'new_relic/version'
|
|
7
7
|
require 'erb'
|
8
8
|
|
9
9
|
class NewRelic::Cli::Install < NewRelic::Cli::Command
|
10
|
-
|
11
10
|
NO_LICENSE_KEY = "<PASTE LICENSE KEY HERE>"
|
12
11
|
|
13
12
|
def self.command; "install"; end
|
@@ -21,7 +20,7 @@ class NewRelic::Cli::Install < NewRelic::Cli::Command
|
|
21
20
|
# Will throw CommandFailed exception if there's any error.
|
22
21
|
#
|
23
22
|
attr_reader :dest_dir, :license_key, :generated_for_user, :quiet, :src_file, :app_name
|
24
|
-
def initialize command_line_args={}
|
23
|
+
def initialize command_line_args = {}
|
25
24
|
@dest_dir = nil
|
26
25
|
super command_line_args
|
27
26
|
if @dest_dir.nil?
|
@@ -43,7 +42,7 @@ class NewRelic::Cli::Install < NewRelic::Cli::Command
|
|
43
42
|
if File.exist?(dest_file) && !@force
|
44
43
|
raise NewRelic::Cli::Command::CommandFailure, "newrelic.yml file already exists. Use --force flag to overwrite."
|
45
44
|
end
|
46
|
-
File.open(dest_file, 'w') { |
|
45
|
+
File.open(dest_file, 'w') { |out| out.puts(content) }
|
47
46
|
|
48
47
|
puts <<-EOF unless quiet
|
49
48
|
|
@@ -60,11 +59,10 @@ you receive upon registration.
|
|
60
59
|
|
61
60
|
Visit support.newrelic.com if you are experiencing installation issues.
|
62
61
|
EOF
|
63
|
-
|
64
62
|
end
|
65
63
|
|
66
64
|
def content
|
67
|
-
@src_file ||= File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","..","newrelic.yml"))
|
65
|
+
@src_file ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "newrelic.yml"))
|
68
66
|
template = File.read(@src_file)
|
69
67
|
ERB.new(template).result(binding)
|
70
68
|
end
|
@@ -73,14 +71,12 @@ Visit support.newrelic.com if you are experiencing installation issues.
|
|
73
71
|
|
74
72
|
def options
|
75
73
|
OptionParser.new "Usage: #{$0} #{self.class.command} [ OPTIONS] 'application name'", 40 do |o|
|
76
|
-
o.on("-f", "--force", "Overwrite newrelic.yml if it exists") { |
|
74
|
+
o.on("-f", "--force", "Overwrite newrelic.yml if it exists") { |e| @force = true }
|
77
75
|
o.on("-l", "--license_key=NAME", String,
|
78
|
-
|
76
|
+
"Use the given license key") { |e| @license_key = e }
|
79
77
|
o.on("-d", "--destdir=name", String,
|
80
|
-
|
78
|
+
"Write the newrelic.yml to the given directory, default is '.'") { |e| @dest_dir = e }
|
81
79
|
yield o if block_given?
|
82
80
|
end
|
83
81
|
end
|
84
|
-
|
85
|
-
|
86
82
|
end
|
data/lib/new_relic/coerce.rb
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
|
6
6
|
module NewRelic
|
7
7
|
module Coerce
|
8
|
-
|
9
8
|
module_function
|
10
9
|
|
11
10
|
# We really don't want to send bad values to the collector, and it doesn't
|
@@ -15,14 +14,14 @@ module NewRelic
|
|
15
14
|
# to provide documentation of expected types on to_collector_array methods,
|
16
15
|
# and to log failures if totally invalid data gets into outgoing data
|
17
16
|
|
18
|
-
def int(value, context=nil)
|
17
|
+
def int(value, context = nil)
|
19
18
|
Integer(value)
|
20
19
|
rescue => error
|
21
20
|
log_failure(value, Integer, context, error)
|
22
21
|
0
|
23
22
|
end
|
24
23
|
|
25
|
-
def int_or_nil(value, context=nil)
|
24
|
+
def int_or_nil(value, context = nil)
|
26
25
|
return nil if value.nil?
|
27
26
|
Integer(value)
|
28
27
|
rescue => error
|
@@ -30,7 +29,7 @@ module NewRelic
|
|
30
29
|
nil
|
31
30
|
end
|
32
31
|
|
33
|
-
def float(value, context=nil)
|
32
|
+
def float(value, context = nil)
|
34
33
|
result = Float(value)
|
35
34
|
raise "Value #{result.inspect} is not finite." unless result.finite?
|
36
35
|
result
|
@@ -39,7 +38,7 @@ module NewRelic
|
|
39
38
|
0.0
|
40
39
|
end
|
41
40
|
|
42
|
-
def string(value, context=nil)
|
41
|
+
def string(value, context = nil)
|
43
42
|
return value if value.nil?
|
44
43
|
String(value)
|
45
44
|
rescue => error
|
@@ -54,8 +53,6 @@ module NewRelic
|
|
54
53
|
when Float
|
55
54
|
if val.finite?
|
56
55
|
val
|
57
|
-
else
|
58
|
-
nil
|
59
56
|
end
|
60
57
|
when Symbol
|
61
58
|
val.to_s
|
@@ -76,7 +73,7 @@ module NewRelic
|
|
76
73
|
value.to_i
|
77
74
|
end
|
78
75
|
|
79
|
-
def float! value, precision=NewRelic::PRIORITY_PRECISION
|
76
|
+
def float! value, precision = NewRelic::PRIORITY_PRECISION
|
80
77
|
return nil unless value_or_nil(value)
|
81
78
|
value.to_f.round(precision)
|
82
79
|
end
|
@@ -4,58 +4,59 @@
|
|
4
4
|
|
5
5
|
module NewRelic
|
6
6
|
module CollectionHelper
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
7
|
+
DEFAULT_TRUNCATION_SIZE = 16 * 1024
|
8
|
+
DEFAULT_ARRAY_TRUNCATION_SIZE = 128
|
9
|
+
# Transform parameter hash into a hash whose values are strictly
|
10
|
+
# strings
|
11
|
+
def normalize_params(params)
|
12
|
+
case params
|
13
|
+
when Hash
|
14
|
+
# optimize for empty hash since that is often what this is called with.
|
15
|
+
return params if params.empty?
|
16
|
+
new_params = {}
|
17
|
+
params.each do |key, value|
|
18
|
+
new_params[truncate(normalize_params(key), 64)] = normalize_params(value)
|
19
|
+
end
|
20
|
+
new_params
|
21
|
+
when Symbol, FalseClass, TrueClass, nil
|
22
|
+
params
|
23
|
+
when Numeric
|
24
|
+
truncate(params.to_s)
|
25
|
+
when String
|
26
|
+
truncate(params)
|
27
|
+
when Array
|
28
|
+
params.first(DEFAULT_ARRAY_TRUNCATION_SIZE).map { |item| normalize_params(item) }
|
29
|
+
else
|
30
|
+
truncate(flatten(params))
|
31
|
+
end
|
31
32
|
end
|
32
|
-
end
|
33
33
|
|
34
|
-
|
34
|
+
private
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
# Convert any kind of object to a short string.
|
37
|
+
def flatten(object)
|
38
|
+
case object
|
39
|
+
when nil then ''
|
40
|
+
when object.instance_of?(String) then object
|
41
|
+
when String then String.new(object) # convert string subclasses to strings
|
42
|
+
else "#<#{object.class.to_s}>"
|
43
|
+
end
|
43
44
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
|
46
|
+
def truncate(string, len = DEFAULT_TRUNCATION_SIZE)
|
47
|
+
case string
|
48
|
+
when Symbol then string
|
49
|
+
when nil then ""
|
50
|
+
when String
|
51
|
+
real_string = flatten(string)
|
52
|
+
if real_string.size > len
|
53
|
+
real_string = real_string.slice(0...len)
|
54
|
+
real_string << "..."
|
55
|
+
end
|
56
|
+
real_string
|
57
|
+
else
|
58
|
+
truncate(flatten(string), len)
|
54
59
|
end
|
55
|
-
real_string
|
56
|
-
else
|
57
|
-
truncate(flatten(string), len)
|
58
60
|
end
|
59
61
|
end
|
60
|
-
end
|
61
62
|
end
|
data/lib/new_relic/constants.rb
CHANGED
@@ -28,10 +28,6 @@ module NewRelic
|
|
28
28
|
TRACEPARENT_KEY = "traceparent"
|
29
29
|
TRACESTATE_KEY = "tracestate"
|
30
30
|
|
31
|
-
# Right now, old and new Rubies are the same. Intention is to use "(...)" for
|
32
|
-
# Ruby 2.7+ for argument delegation, but doing so is a breaking API change.
|
33
|
-
ARGS_FOR_RUBY_VERSION = RUBY_VERSION < "2.7.0" ? "*args, &block" : "*args, &block"
|
34
|
-
|
35
31
|
HTTP_TRACEPARENT_KEY = "HTTP_#{TRACEPARENT_KEY.upcase}"
|
36
32
|
HTTP_TRACESTATE_KEY = "HTTP_#{TRACESTATE_KEY.upcase}"
|
37
33
|
HTTP_NEWRELIC_KEY = "HTTP_#{NEWRELIC_KEY.upcase}"
|