newrelic_rpm 6.6.0.358 → 6.11.0.365
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +81 -5
- data/CHANGELOG.md +262 -0
- data/Gemfile +6 -2
- data/Guardfile +18 -1
- data/LICENSE +1 -1
- data/Rakefile +2 -0
- data/lib/new_relic/agent.rb +89 -7
- data/lib/new_relic/agent/agent.rb +115 -58
- data/lib/new_relic/agent/agent_logger.rb +4 -0
- data/lib/new_relic/agent/attribute_filter.rb +7 -7
- data/lib/new_relic/agent/attributes.rb +150 -0
- data/lib/new_relic/agent/autostart.rb +19 -14
- data/lib/new_relic/agent/configuration/default_source.rb +154 -9
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
- data/lib/new_relic/agent/configuration/manager.rb +0 -8
- data/lib/new_relic/agent/configuration/server_source.rb +3 -2
- data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
- data/lib/new_relic/agent/connect/request_builder.rb +5 -13
- data/lib/new_relic/agent/database.rb +1 -2
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
- data/lib/new_relic/agent/distributed_tracing.rb +155 -6
- data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +2 -1
- data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -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} +24 -101
- 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/error_collector.rb +33 -16
- data/lib/new_relic/agent/error_event_aggregator.rb +7 -5
- data/lib/new_relic/agent/external.rb +7 -7
- data/lib/new_relic/agent/guid_generator.rb +28 -0
- data/lib/new_relic/agent/hostname.rb +7 -1
- data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +24 -19
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +28 -13
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +17 -21
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +10 -11
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +16 -4
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -6
- data/lib/new_relic/agent/http_clients/uri_util.rb +3 -2
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +5 -7
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -0
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +4 -2
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +7 -2
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -4
- data/lib/new_relic/agent/instrumentation/bunny.rb +45 -28
- data/lib/new_relic/agent/instrumentation/curb.rb +59 -18
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -1
- data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +6 -3
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
- data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
- data/lib/new_relic/agent/instrumentation/http.rb +6 -3
- data/lib/new_relic/agent/instrumentation/httpclient.rb +5 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +3 -1
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +6 -2
- data/lib/new_relic/agent/instrumentation/mongo.rb +9 -3
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +13 -0
- data/lib/new_relic/agent/instrumentation/net.rb +6 -3
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +25 -1
- data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +47 -23
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
- data/lib/new_relic/agent/logging.rb +139 -0
- data/lib/new_relic/agent/messaging.rb +5 -73
- data/lib/new_relic/agent/method_tracer.rb +18 -6
- data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
- 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} +1 -1
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
- data/lib/new_relic/agent/new_relic_service.rb +7 -6
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/span_event_aggregator.rb +1 -0
- data/lib/new_relic/agent/span_event_primitive.rb +86 -53
- data/lib/new_relic/agent/sql_sampler.rb +3 -3
- data/lib/new_relic/agent/supported_versions.rb +2 -2
- data/lib/new_relic/agent/system_info.rb +12 -3
- data/lib/new_relic/agent/tracer.rb +65 -18
- data/lib/new_relic/agent/transaction.rb +84 -79
- data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
- data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
- data/lib/new_relic/agent/transaction/segment.rb +7 -1
- data/lib/new_relic/agent/transaction/trace.rb +2 -4
- data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
- data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
- data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
- data/lib/new_relic/cli/commands/deployments.rb +1 -1
- data/lib/new_relic/cli/commands/install.rb +3 -2
- data/lib/new_relic/coerce.rb +31 -6
- data/lib/new_relic/constants.rb +38 -0
- data/lib/new_relic/control/instance_methods.rb +10 -1
- data/lib/new_relic/dependency_detection.rb +4 -4
- data/lib/new_relic/environment_report.rb +5 -1
- data/lib/new_relic/noticed_error.rb +38 -17
- data/lib/new_relic/rack/browser_monitoring.rb +5 -0
- data/lib/new_relic/supportability_helper.rb +14 -0
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/multiverse.rb +25 -0
- data/lib/tasks/tests.rake +6 -1
- data/newrelic_rpm.gemspec +19 -8
- data/test/agent_helper.rb +323 -71
- metadata +100 -33
- data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
- data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
- data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
- data/lib/new_relic/agent/transaction/attributes.rb +0 -154
- 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
data/Gemfile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
# frozen_string_literal: true
|
2
5
|
|
3
|
-
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
gemspec name: "newrelic_rpm"
|
data/Guardfile
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
-
|
1
|
+
require './test/multiverse/lib/multiverse/bundler_patch'
|
2
|
+
|
3
|
+
test_folders = Dir.glob("test/new_relic/*").select{|f| File.directory?(f)}
|
4
|
+
test_folders += Dir.glob("test/new_relic/**/*").select{|f| File.directory?(f)}
|
5
|
+
|
6
|
+
rake_lib_path = Bundler.with_unbundled_env{ `bundle exec gem which rake`.chomp.gsub("lib/rake.rb", "lib") }
|
7
|
+
ruby_options = %{-w -I"#{rake_lib_path}" "#{rake_lib_path}/rake/rake_test_loader.rb"}
|
8
|
+
|
9
|
+
guard_options = {
|
10
|
+
spring: "bundle exec ruby #{ruby_options} ",
|
11
|
+
test_folders: ['test/new_relic'] + test_folders,
|
12
|
+
all_after_pass: false,
|
13
|
+
all_on_start: false
|
14
|
+
}
|
15
|
+
|
16
|
+
guard :minitest, guard_options do
|
2
17
|
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
3
18
|
watch(%r{^test/.+_test\.rb$})
|
4
19
|
watch(%r{^test/rum/.*}) { "test/new_relic/rack/browser_monitoring_test.rb" }
|
20
|
+
watch(%r{^test/fixtures/cross_agent_tests/distributed_tracing/(.+).json}) { |m| "test/new_relic/agent/distributed_tracing/#{m[1]}_cross_agent_test.rb" }
|
5
21
|
watch('test/test_helper.rb') { "test/new_relic" }
|
6
22
|
watch('test/agent_helper.rb') { "test/new_relic" }
|
7
23
|
watch('lib/new_relic/agent/configuration/default_source.rb') { "test/new_relic/agent/configuration/orphan_configuration_test.rb" }
|
24
|
+
watch(%r{^lib/new_relic/agent/transaction/(.+).rb}) { |m| "test/new_relic/agent/distributed_tracing/#{m[1]}_cross_agent_test.rb" }
|
8
25
|
end
|
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
All components of this product are
|
2
|
-
Copyright (c) 2008-
|
2
|
+
Copyright (c) 2008-2020 New Relic, Inc. All rights reserved.
|
3
3
|
|
4
4
|
Certain inventions disclosed in this file may be claimed within
|
5
5
|
patents owned or patent applications filed by New Relic, Inc. or third
|
data/Rakefile
CHANGED
@@ -113,6 +113,7 @@ namespace :cross_agent_tests do
|
|
113
113
|
cross_agent_tests_upstream_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'cross_agent_tests'))
|
114
114
|
cross_agent_tests_local_path = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'fixtures', 'cross_agent_tests'))
|
115
115
|
|
116
|
+
# Note: before you pull, make sure your local repo is on the correct, synced branch!
|
116
117
|
desc 'Pull latest changes from cross_agent_tests repo'
|
117
118
|
task :pull do
|
118
119
|
puts "Updating embedded cross_agent_tests from #{cross_agent_tests_upstream_path}..."
|
@@ -136,3 +137,4 @@ task :console do
|
|
136
137
|
ARGV.clear
|
137
138
|
Pry.start
|
138
139
|
end
|
140
|
+
|
data/lib/new_relic/agent.rb
CHANGED
@@ -30,12 +30,12 @@ module NewRelic
|
|
30
30
|
require 'new_relic/metric_spec'
|
31
31
|
require 'new_relic/metric_data'
|
32
32
|
require 'new_relic/noticed_error'
|
33
|
+
require 'new_relic/agent/noticible_error'
|
33
34
|
require 'new_relic/supportability_helper'
|
34
35
|
|
35
36
|
require 'new_relic/agent/encoding_normalizer'
|
36
37
|
require 'new_relic/agent/stats'
|
37
38
|
require 'new_relic/agent/chained_call'
|
38
|
-
require 'new_relic/agent/cross_app_monitor'
|
39
39
|
require 'new_relic/agent/agent'
|
40
40
|
require 'new_relic/agent/method_tracer'
|
41
41
|
require 'new_relic/agent/worker_loop'
|
@@ -55,7 +55,9 @@ module NewRelic
|
|
55
55
|
require 'new_relic/agent/system_info'
|
56
56
|
require 'new_relic/agent/external'
|
57
57
|
require 'new_relic/agent/deprecator'
|
58
|
-
|
58
|
+
require 'new_relic/agent/logging'
|
59
|
+
require 'new_relic/agent/distributed_tracing'
|
60
|
+
|
59
61
|
require 'new_relic/agent/instrumentation/controller_instrumentation'
|
60
62
|
|
61
63
|
require 'new_relic/agent/samplers/cpu_sampler'
|
@@ -350,10 +352,9 @@ module NewRelic
|
|
350
352
|
# @api public
|
351
353
|
#
|
352
354
|
def manual_start(options={})
|
353
|
-
record_api_supportability_metric(:manual_start)
|
354
|
-
|
355
355
|
raise "Options must be a hash" unless Hash === options
|
356
356
|
NewRelic::Control.instance.init_plugin({ :agent_enabled => true, :sync_startup => true }.merge(options))
|
357
|
+
record_api_supportability_metric(:manual_start)
|
357
358
|
end
|
358
359
|
|
359
360
|
# Register this method as a callback for processes that fork
|
@@ -567,6 +568,12 @@ module NewRelic
|
|
567
568
|
# these custom attributes will also be present in the script injected into
|
568
569
|
# the response body, making them available on Insights PageView events.
|
569
570
|
#
|
571
|
+
#
|
572
|
+
# @param [Hash] params A Hash of attributes to be attached to the transaction event.
|
573
|
+
# Keys should be strings or symbols, and values
|
574
|
+
# may be strings, symbols, numeric values or
|
575
|
+
# booleans.
|
576
|
+
#
|
570
577
|
# @api public
|
571
578
|
#
|
572
579
|
def add_custom_attributes(params) #THREAD_LOCAL_ACCESS
|
@@ -580,6 +587,31 @@ module NewRelic
|
|
580
587
|
end
|
581
588
|
end
|
582
589
|
|
590
|
+
# Add custom attributes to the span event for the current span. Attributes will be visible on spans in the
|
591
|
+
# New Relic Distributed Tracing UI and on span events in New Relic Insights.
|
592
|
+
#
|
593
|
+
# Custom attributes will not be transmitted when +high_security+ setting is enabled or
|
594
|
+
# +custom_attributes+ setting is disabled.
|
595
|
+
#
|
596
|
+
# @param [Hash] params A Hash of attributes to be attached to the span event.
|
597
|
+
# Keys should be strings or symbols, and values
|
598
|
+
# may be strings, symbols, numeric values or
|
599
|
+
# booleans.
|
600
|
+
#
|
601
|
+
# @see https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/glossary#span
|
602
|
+
# @api public
|
603
|
+
def add_custom_span_attributes params
|
604
|
+
record_api_supportability_metric :add_custom_span_attributes
|
605
|
+
|
606
|
+
if params.is_a? Hash
|
607
|
+
if segment = NewRelic::Agent::Tracer.current_segment
|
608
|
+
segment.add_custom_attributes params
|
609
|
+
end
|
610
|
+
else
|
611
|
+
::NewRelic::Agent.logger.warn "Bad argument passed to #add_custom_span_attributes. Expected Hash but got #{params.class}"
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
583
615
|
# @!endgroup
|
584
616
|
|
585
617
|
# @!group Transaction naming
|
@@ -588,7 +620,9 @@ module NewRelic
|
|
588
620
|
# apply a reasonable default based on framework routing, but in
|
589
621
|
# cases where this is insufficient, this can be used to manually
|
590
622
|
# control the name of the transaction.
|
591
|
-
#
|
623
|
+
#
|
624
|
+
# The category of transaction can be specified via the +:category+ option.
|
625
|
+
# The following are the only valid categories:
|
592
626
|
#
|
593
627
|
# * <tt>:category => :controller</tt> indicates that this is a
|
594
628
|
# controller action and will appear with all the other actions.
|
@@ -638,8 +672,8 @@ module NewRelic
|
|
638
672
|
# @param [String] method the name of the finder method or other method to
|
639
673
|
# identify the operation with.
|
640
674
|
#
|
641
|
-
def with_database_metric_name(model, method = nil, product = nil, &block)
|
642
|
-
if txn =
|
675
|
+
def with_database_metric_name(model, method = nil, product = nil, &block)
|
676
|
+
if txn = Tracer.current_transaction
|
643
677
|
txn.with_database_metric_name(model, method, product, &block)
|
644
678
|
else
|
645
679
|
yield
|
@@ -660,6 +694,54 @@ module NewRelic
|
|
660
694
|
NewRelic::Agent.logger.debug "Ignoring exception during %p event notification" % [event_type]
|
661
695
|
end
|
662
696
|
|
697
|
+
# @!group Trace and Entity metadata
|
698
|
+
|
699
|
+
TRACE_ID_KEY = 'trace.id'.freeze
|
700
|
+
SPAN_ID_KEY = 'span.id'.freeze
|
701
|
+
ENTITY_NAME_KEY = 'entity.name'.freeze
|
702
|
+
ENTITY_TYPE_KEY = 'entity.type'.freeze
|
703
|
+
ENTITY_GUID_KEY = 'entity.guid'.freeze
|
704
|
+
HOSTNAME_KEY = 'hostname'.freeze
|
705
|
+
|
706
|
+
ENTITY_TYPE = 'SERVICE'.freeze
|
707
|
+
|
708
|
+
# Returns a new hash containing trace and entity metadata that can be used
|
709
|
+
# to relate data to a trace or to an entity in APM.
|
710
|
+
#
|
711
|
+
# This hash includes:
|
712
|
+
# * trace.id - The current trace id, if there is a current trace id. This
|
713
|
+
# value may be omitted.
|
714
|
+
# * span.id - The current span id, if there is a current span. This
|
715
|
+
# value may be omitted.
|
716
|
+
# * entity.name - The name of the current application. This is read from
|
717
|
+
# the +app_name+ key in your config. If there are multiple application
|
718
|
+
# names, the first one is used.
|
719
|
+
# * entity.type - The entity type is hardcoded to the string +'SERVICE'+.
|
720
|
+
# * entity.guid - The guid of the current entity.
|
721
|
+
# * hostname - The fully qualified hostname.
|
722
|
+
#
|
723
|
+
# @api public
|
724
|
+
def linking_metadata
|
725
|
+
metadata = Hash.new
|
726
|
+
metadata[ENTITY_NAME_KEY] = config[:app_name][0]
|
727
|
+
metadata[ENTITY_TYPE_KEY] = ENTITY_TYPE
|
728
|
+
metadata[HOSTNAME_KEY] = Hostname.get
|
729
|
+
|
730
|
+
if entity_guid = config[:entity_guid]
|
731
|
+
metadata[ENTITY_GUID_KEY] = entity_guid
|
732
|
+
end
|
733
|
+
|
734
|
+
if trace_id = Tracer.current_trace_id
|
735
|
+
metadata[TRACE_ID_KEY] = trace_id
|
736
|
+
end
|
737
|
+
if span_id = Tracer.current_span_id
|
738
|
+
metadata[SPAN_ID_KEY] = span_id
|
739
|
+
end
|
740
|
+
metadata
|
741
|
+
end
|
742
|
+
|
743
|
+
#@!endgroup
|
744
|
+
|
663
745
|
# @!group Manual browser monitoring configuration
|
664
746
|
|
665
747
|
# This method returns a string suitable for inclusion in a page - known as
|
@@ -8,6 +8,8 @@ require 'net/http'
|
|
8
8
|
require 'logger'
|
9
9
|
require 'zlib'
|
10
10
|
require 'stringio'
|
11
|
+
require 'new_relic/constants'
|
12
|
+
require 'new_relic/coerce'
|
11
13
|
require 'new_relic/agent/autostart'
|
12
14
|
require 'new_relic/agent/harvester'
|
13
15
|
require 'new_relic/agent/hostname'
|
@@ -17,9 +19,8 @@ require 'new_relic/agent/configuration/manager'
|
|
17
19
|
require 'new_relic/agent/database'
|
18
20
|
require 'new_relic/agent/commands/agent_command_router'
|
19
21
|
require 'new_relic/agent/event_listener'
|
20
|
-
require 'new_relic/agent/
|
21
|
-
require 'new_relic/agent/
|
22
|
-
require 'new_relic/agent/synthetics_monitor'
|
22
|
+
require 'new_relic/agent/distributed_tracing'
|
23
|
+
require 'new_relic/agent/monitors'
|
23
24
|
require 'new_relic/agent/transaction_event_recorder'
|
24
25
|
require 'new_relic/agent/custom_event_aggregator'
|
25
26
|
require 'new_relic/agent/span_event_aggregator'
|
@@ -48,31 +49,30 @@ module NewRelic
|
|
48
49
|
def initialize
|
49
50
|
@started = false
|
50
51
|
@event_loop = nil
|
52
|
+
@worker_thread = nil
|
51
53
|
|
52
54
|
@service = NewRelicService.new
|
53
55
|
|
54
|
-
@events =
|
55
|
-
@stats_engine =
|
56
|
-
@transaction_sampler =
|
57
|
-
@sql_sampler =
|
58
|
-
@agent_command_router =
|
59
|
-
@
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@harvester = NewRelic::Agent::Harvester.new(@events)
|
56
|
+
@events = EventListener.new
|
57
|
+
@stats_engine = StatsEngine.new
|
58
|
+
@transaction_sampler = TransactionSampler.new
|
59
|
+
@sql_sampler = SqlSampler.new
|
60
|
+
@agent_command_router = Commands::AgentCommandRouter.new @events
|
61
|
+
@monitors = Monitors.new @events
|
62
|
+
@error_collector = ErrorCollector.new @events
|
63
|
+
@transaction_rules = RulesEngine.new
|
64
|
+
@harvest_samplers = SamplerCollection.new @events
|
65
|
+
@monotonic_gc_profiler = VM::MonotonicGCProfiler.new
|
66
|
+
@javascript_instrumentor = JavascriptInstrumentor.new @events
|
67
|
+
@adaptive_sampler = AdaptiveSampler.new(Agent.config[:sampling_target],
|
68
|
+
Agent.config[:sampling_target_period_in_seconds])
|
69
|
+
|
70
|
+
@harvester = Harvester.new @events
|
71
71
|
@after_fork_lock = Mutex.new
|
72
72
|
|
73
|
-
@transaction_event_recorder =
|
74
|
-
@custom_event_aggregator =
|
75
|
-
@span_event_aggregator =
|
73
|
+
@transaction_event_recorder = TransactionEventRecorder.new @events
|
74
|
+
@custom_event_aggregator = CustomEventAggregator.new @events
|
75
|
+
@span_event_aggregator = SpanEventAggregator.new @events
|
76
76
|
|
77
77
|
@connect_state = :pending
|
78
78
|
@connect_attempts = 0
|
@@ -94,7 +94,7 @@ module NewRelic
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def refresh_attribute_filter
|
97
|
-
@attribute_filter =
|
97
|
+
@attribute_filter = AttributeFilter.new(Agent.config)
|
98
98
|
end
|
99
99
|
|
100
100
|
# contains all the class-level methods for NewRelic::Agent::Agent
|
@@ -127,13 +127,16 @@ module NewRelic
|
|
127
127
|
# cross application tracing ids and encoding
|
128
128
|
attr_reader :cross_process_id
|
129
129
|
attr_reader :cross_app_encoding_bytes
|
130
|
-
attr_reader :cross_app_monitor
|
131
130
|
# service for communicating with collector
|
132
131
|
attr_accessor :service
|
133
132
|
# Global events dispatcher. This will provides our primary mechanism
|
134
133
|
# for agent-wide events, such as finishing configuration, error notification
|
135
134
|
# and request before/after from Rack.
|
136
135
|
attr_reader :events
|
136
|
+
|
137
|
+
# listens and responds to events that need to process headers
|
138
|
+
# for synthetics and distributed tracing
|
139
|
+
attr_reader :monitors
|
137
140
|
# Transaction and metric renaming rules as provided by the
|
138
141
|
# collector on connect. The former are applied during txns,
|
139
142
|
# the latter during harvest.
|
@@ -147,6 +150,7 @@ module NewRelic
|
|
147
150
|
attr_reader :transaction_event_recorder
|
148
151
|
attr_reader :attribute_filter
|
149
152
|
attr_reader :adaptive_sampler
|
153
|
+
attr_reader :environment_report
|
150
154
|
|
151
155
|
def transaction_event_aggregator
|
152
156
|
@transaction_event_recorder.transaction_event_aggregator
|
@@ -205,7 +209,7 @@ module NewRelic
|
|
205
209
|
end
|
206
210
|
|
207
211
|
def install_pipe_service(channel_id)
|
208
|
-
@service =
|
212
|
+
@service = PipeService.new(channel_id)
|
209
213
|
if connected?
|
210
214
|
@connected_pid = Process.pid
|
211
215
|
else
|
@@ -236,12 +240,18 @@ module NewRelic
|
|
236
240
|
end
|
237
241
|
|
238
242
|
def revert_to_default_configuration
|
239
|
-
|
240
|
-
|
243
|
+
Agent.config.remove_config_type(:manual)
|
244
|
+
Agent.config.remove_config_type(:server)
|
241
245
|
end
|
242
246
|
|
243
247
|
def stop_event_loop
|
244
248
|
@event_loop.stop if @event_loop
|
249
|
+
# Wait the end of the event loop thread.
|
250
|
+
if @worker_thread
|
251
|
+
unless @worker_thread.join(3)
|
252
|
+
::NewRelic::Agent.logger.debug "Event loop thread did not stop within 3 seconds"
|
253
|
+
end
|
254
|
+
end
|
245
255
|
end
|
246
256
|
|
247
257
|
def trap_signals_for_litespeed
|
@@ -332,7 +342,7 @@ module NewRelic
|
|
332
342
|
end
|
333
343
|
|
334
344
|
def log_app_name
|
335
|
-
::NewRelic::Agent.logger.info "Application: #{Agent.config.
|
345
|
+
::NewRelic::Agent.logger.info "Application: #{Agent.config[:app_name].join(", ")}"
|
336
346
|
end
|
337
347
|
|
338
348
|
def log_ignore_url_regexes
|
@@ -345,7 +355,7 @@ module NewRelic
|
|
345
355
|
|
346
356
|
# Logs the configured application names
|
347
357
|
def app_name_configured?
|
348
|
-
names = Agent.config
|
358
|
+
names = Agent.config[:app_name]
|
349
359
|
return names.respond_to?(:any?) && names.any?
|
350
360
|
end
|
351
361
|
|
@@ -456,11 +466,11 @@ module NewRelic
|
|
456
466
|
def defer_for_resque?
|
457
467
|
NewRelic::Agent.config[:dispatcher] == :resque &&
|
458
468
|
NewRelic::LanguageSupport.can_fork? &&
|
459
|
-
!
|
469
|
+
!PipeChannelManager.listener.started?
|
460
470
|
end
|
461
471
|
|
462
472
|
def in_resque_child_process?
|
463
|
-
defined?(@service) && @service.is_a?(
|
473
|
+
defined?(@service) && @service.is_a?(PipeService)
|
464
474
|
end
|
465
475
|
|
466
476
|
# Sanity-check the agent configuration and start the agent,
|
@@ -482,6 +492,7 @@ module NewRelic
|
|
482
492
|
|
483
493
|
unless in_resque_child_process?
|
484
494
|
install_exit_handler
|
495
|
+
environment_for_connect
|
485
496
|
@harvest_samplers.load_samplers unless Agent.config[:disable_samplers]
|
486
497
|
end
|
487
498
|
|
@@ -555,13 +566,16 @@ module NewRelic
|
|
555
566
|
# This is necessary for cases where we're in a forked child and Ruby
|
556
567
|
# might be holding locks for background thread that aren't there anymore.
|
557
568
|
def reset_objects_with_locks
|
558
|
-
@stats_engine =
|
569
|
+
@stats_engine = StatsEngine.new
|
559
570
|
end
|
560
571
|
|
561
572
|
def flush_pipe_data
|
562
|
-
if connected? && @service.is_a?(
|
573
|
+
if connected? && @service.is_a?(PipeService)
|
563
574
|
transmit_data
|
564
|
-
|
575
|
+
transmit_analytic_event_data
|
576
|
+
transmit_custom_event_data
|
577
|
+
transmit_error_event_data
|
578
|
+
transmit_span_event_data
|
565
579
|
end
|
566
580
|
end
|
567
581
|
|
@@ -577,20 +591,46 @@ module NewRelic
|
|
577
591
|
|
578
592
|
LOG_ONCE_KEYS_RESET_PERIOD = 60.0
|
579
593
|
|
594
|
+
# Certain event types may sometimes need to be on the same interval as metrics,
|
595
|
+
# so we will check config assigned in EventHarvestConfig to determine the interval
|
596
|
+
# on which to report them
|
597
|
+
def interval_for event_type
|
598
|
+
interval = Agent.config[:"event_report_period.#{event_type}"]
|
599
|
+
:"#{interval}_second_harvest"
|
600
|
+
end
|
601
|
+
|
602
|
+
ANALYTIC_EVENT_DATA = "analytic_event_data".freeze
|
603
|
+
CUSTOM_EVENT_DATA = "custom_event_data".freeze
|
604
|
+
ERROR_EVENT_DATA = "error_event_data".freeze
|
605
|
+
SPAN_EVENT_DATA = "span_event_data".freeze
|
606
|
+
|
580
607
|
def create_and_run_event_loop
|
608
|
+
data_harvest = :"#{Agent.config[:data_report_period]}_second_harvest"
|
609
|
+
event_harvest = :"#{Agent.config[:event_report_period]}_second_harvest"
|
610
|
+
|
581
611
|
@event_loop = create_event_loop
|
582
|
-
@event_loop.on(
|
612
|
+
@event_loop.on(data_harvest) do
|
583
613
|
transmit_data
|
584
614
|
end
|
585
|
-
|
586
|
-
|
615
|
+
|
616
|
+
@event_loop.on(interval_for ANALYTIC_EVENT_DATA) do
|
617
|
+
transmit_analytic_event_data
|
618
|
+
end
|
619
|
+
@event_loop.on(interval_for CUSTOM_EVENT_DATA) do
|
620
|
+
transmit_custom_event_data
|
621
|
+
end
|
622
|
+
@event_loop.on(interval_for ERROR_EVENT_DATA) do
|
623
|
+
transmit_error_event_data
|
624
|
+
end
|
625
|
+
@event_loop.on(interval_for SPAN_EVENT_DATA) do
|
626
|
+
transmit_span_event_data
|
587
627
|
end
|
588
628
|
@event_loop.on(:reset_log_once_keys) do
|
589
629
|
::NewRelic::Agent.logger.clear_already_logged
|
590
630
|
end
|
591
|
-
@event_loop.fire_every(Agent.config[:data_report_period],
|
592
|
-
@event_loop.fire_every(Agent.config[:event_report_period],
|
593
|
-
@event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD,
|
631
|
+
@event_loop.fire_every(Agent.config[:data_report_period], data_harvest)
|
632
|
+
@event_loop.fire_every(Agent.config[:event_report_period], event_harvest)
|
633
|
+
@event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
|
594
634
|
|
595
635
|
@event_loop.run
|
596
636
|
end
|
@@ -674,7 +714,7 @@ module NewRelic
|
|
674
714
|
end
|
675
715
|
|
676
716
|
::NewRelic::Agent.logger.debug "Creating Ruby Agent worker thread."
|
677
|
-
@worker_thread =
|
717
|
+
@worker_thread = Threading::AgentThread.create('Worker Loop') do
|
678
718
|
deferred_work!(connection_options)
|
679
719
|
end
|
680
720
|
end
|
@@ -717,10 +757,8 @@ module NewRelic
|
|
717
757
|
# /agents/agent-specs/Collector-Response-Handling.md, retry
|
718
758
|
# connections after a specific backoff sequence to prevent
|
719
759
|
# hammering the server.
|
720
|
-
CONNECT_RETRY_PERIODS = [15, 15, 30, 60, 120, 300]
|
721
|
-
|
722
760
|
def connect_retry_period
|
723
|
-
CONNECT_RETRY_PERIODS[connect_attempts] ||
|
761
|
+
NewRelic::CONNECT_RETRY_PERIODS[connect_attempts] || NewRelic::MAX_RETRY_PERIOD
|
724
762
|
end
|
725
763
|
|
726
764
|
def note_connect_failure
|
@@ -760,23 +798,24 @@ module NewRelic
|
|
760
798
|
# require calls in Rails environments, so this method should only
|
761
799
|
# be called synchronously from on the main thread.
|
762
800
|
def environment_for_connect
|
763
|
-
Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
|
801
|
+
@environment_report ||= Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
|
764
802
|
end
|
765
803
|
|
766
|
-
# Constructs and memoizes an event_harvest_config hash to be used in
|
804
|
+
# Constructs and memoizes an event_harvest_config hash to be used in
|
767
805
|
# the payload sent during connect (and reconnect)
|
768
806
|
def event_harvest_config
|
769
807
|
@event_harvest_config ||= Configuration::EventHarvestConfig.from_config(Agent.config)
|
770
808
|
end
|
771
809
|
|
772
810
|
# Builds the payload to send to the connect service,
|
773
|
-
# connects, then configures the agent using the response from
|
811
|
+
# connects, then configures the agent using the response from
|
774
812
|
# the connect service
|
775
813
|
def connect_to_server
|
776
814
|
request_builder = ::NewRelic::Agent::Connect::RequestBuilder.new \
|
777
815
|
@service,
|
778
816
|
Agent.config,
|
779
|
-
event_harvest_config
|
817
|
+
event_harvest_config,
|
818
|
+
environment_for_connect
|
780
819
|
connect_response = @service.connect request_builder.connect_payload
|
781
820
|
|
782
821
|
response_handler = ::NewRelic::Agent::Connect::ResponseHandler.new(self, Agent.config)
|
@@ -990,7 +1029,7 @@ module NewRelic
|
|
990
1029
|
end
|
991
1030
|
|
992
1031
|
def harvest_and_send_timeslice_data
|
993
|
-
|
1032
|
+
TransactionTimeAggregator.harvest!
|
994
1033
|
harvest_and_send_from_container(@stats_engine, :metric_data)
|
995
1034
|
end
|
996
1035
|
|
@@ -1019,17 +1058,20 @@ module NewRelic
|
|
1019
1058
|
def harvest_and_send_analytic_event_data
|
1020
1059
|
harvest_and_send_from_container(transaction_event_aggregator, :analytic_event_data)
|
1021
1060
|
harvest_and_send_from_container(synthetics_event_aggregator, :analytic_event_data)
|
1022
|
-
harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
|
1023
1061
|
end
|
1024
1062
|
|
1025
|
-
def
|
1026
|
-
harvest_and_send_from_container(
|
1063
|
+
def harvest_and_send_custom_event_data
|
1064
|
+
harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
|
1027
1065
|
end
|
1028
1066
|
|
1029
1067
|
def harvest_and_send_error_event_data
|
1030
1068
|
harvest_and_send_from_container @error_collector.error_event_aggregator, :error_event_data
|
1031
1069
|
end
|
1032
1070
|
|
1071
|
+
def harvest_and_send_span_event_data
|
1072
|
+
harvest_and_send_from_container(span_event_aggregator, :span_event_data)
|
1073
|
+
end
|
1074
|
+
|
1033
1075
|
def check_for_and_handle_agent_commands
|
1034
1076
|
begin
|
1035
1077
|
@agent_command_router.check_for_and_handle_agent_commands
|
@@ -1050,18 +1092,30 @@ module NewRelic
|
|
1050
1092
|
NewRelic::Agent.record_metric("Supportability/remote_unavailable/#{endpoint.to_s}", 0.0)
|
1051
1093
|
end
|
1052
1094
|
|
1053
|
-
|
1054
|
-
|
1095
|
+
TRANSACTION_EVENT = "TransactionEvent".freeze
|
1096
|
+
def transmit_analytic_event_data
|
1097
|
+
transmit_single_data_type(:harvest_and_send_analytic_event_data, TRANSACTION_EVENT)
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
CUSTOM_EVENT = "CustomEvent".freeze
|
1101
|
+
def transmit_custom_event_data
|
1102
|
+
transmit_single_data_type(:harvest_and_send_custom_event_data, CUSTOM_EVENT)
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
ERROR_EVENT = "ErrorEvent".freeze
|
1106
|
+
def transmit_error_event_data
|
1107
|
+
transmit_single_data_type(:harvest_and_send_error_event_data, ERROR_EVENT)
|
1055
1108
|
end
|
1056
1109
|
|
1110
|
+
SPAN_EVENT = "SpanEvent".freeze
|
1057
1111
|
def transmit_span_event_data
|
1058
|
-
transmit_single_data_type(:harvest_and_send_span_event_data,
|
1112
|
+
transmit_single_data_type(:harvest_and_send_span_event_data, SPAN_EVENT)
|
1059
1113
|
end
|
1060
1114
|
|
1061
1115
|
def transmit_single_data_type(harvest_method, supportability_name)
|
1062
1116
|
now = Time.now
|
1063
1117
|
|
1064
|
-
msg = "Sending #{
|
1118
|
+
msg = "Sending #{supportability_name} data to New Relic Service"
|
1065
1119
|
::NewRelic::Agent.logger.debug msg
|
1066
1120
|
|
1067
1121
|
@service.session do # use http keep-alive
|
@@ -1108,7 +1162,10 @@ module NewRelic
|
|
1108
1162
|
|
1109
1163
|
@events.notify(:before_shutdown)
|
1110
1164
|
transmit_data
|
1111
|
-
|
1165
|
+
transmit_analytic_event_data
|
1166
|
+
transmit_custom_event_data
|
1167
|
+
transmit_error_event_data
|
1168
|
+
transmit_span_event_data
|
1112
1169
|
|
1113
1170
|
if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
|
1114
1171
|
::NewRelic::Agent.logger.debug "Sending New Relic service agent run shutdown message"
|