newrelic_rpm 3.17.2.327 → 3.18.0.329
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +32 -10
- data/CHANGELOG.md +43 -3
- data/Rakefile +0 -21
- data/lib/new_relic/agent/cross_app_tracing.rb +34 -269
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +10 -2
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +18 -9
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +12 -6
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +13 -6
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +13 -6
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +14 -3
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +10 -15
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -7
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -19
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +0 -1
- data/lib/new_relic/agent/instrumentation/curb.rb +9 -7
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +4 -0
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +15 -5
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +17 -12
- data/lib/new_relic/agent/instrumentation/http.rb +12 -5
- data/lib/new_relic/agent/instrumentation/httpclient.rb +13 -4
- data/lib/new_relic/agent/instrumentation/net.rb +13 -2
- data/lib/new_relic/agent/instrumentation/rails5/action_controller.rb +2 -10
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +8 -3
- data/lib/new_relic/agent/method_tracer_helpers.rb +3 -1
- data/lib/new_relic/agent/parameter_filtering.rb +1 -1
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +0 -18
- data/lib/new_relic/agent/supported_versions.rb +1 -0
- data/lib/new_relic/agent/transaction/abstract_segment.rb +7 -9
- data/lib/new_relic/agent/transaction/external_request_segment.rb +139 -0
- data/lib/new_relic/agent/transaction/segment.rb +1 -1
- data/lib/new_relic/agent/transaction/tracing.rb +10 -1
- data/lib/new_relic/recipes/capistrano3.rb +3 -1
- data/lib/new_relic/version.rb +2 -2
- data/lib/tasks/multiverse.rb +27 -7
- data/test/environments/rails42/Gemfile +1 -0
- data/test/multiverse/lib/multiverse.rb +32 -0
- data/test/multiverse/lib/multiverse/runner.rb +2 -2
- data/test/multiverse/lib/multiverse/suite.rb +43 -22
- data/test/multiverse/suites/active_record/Envfile +3 -1
- data/test/multiverse/suites/activemerchant/Envfile +5 -1
- data/test/multiverse/suites/agent_only/Envfile +1 -0
- data/test/multiverse/suites/capistrano/deployment_test.rb +6 -9
- data/test/multiverse/suites/capistrano2/deployment_test.rb +6 -6
- data/test/multiverse/suites/curb/curb_test.rb +2 -3
- data/test/multiverse/suites/datamapper/Envfile +4 -0
- data/test/multiverse/suites/datamapper/datamapper_test.rb +106 -36
- data/test/multiverse/suites/delayed_job/Envfile +3 -3
- data/test/multiverse/suites/excon/excon_test.rb +1 -1
- data/test/multiverse/suites/grape/grape_test.rb +1 -1
- data/test/multiverse/suites/grape/grape_test_api.rb +1 -1
- data/test/multiverse/suites/grape/grape_versioning_test.rb +1 -1
- data/test/multiverse/suites/grape/grape_versioning_test_api.rb +1 -1
- data/test/multiverse/suites/grape/unsupported_version_test.rb +1 -1
- data/test/multiverse/suites/httpclient/Envfile +2 -0
- data/test/multiverse/suites/httpclient/httpclient_test.rb +1 -1
- data/test/multiverse/suites/httprb/Envfile +2 -0
- data/test/multiverse/suites/httprb/httprb_test.rb +1 -1
- data/test/multiverse/suites/json/Envfile +7 -2
- data/test/multiverse/suites/memcached/Envfile +2 -0
- data/test/multiverse/suites/mongo/Envfile +2 -0
- data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +95 -33
- data/test/multiverse/suites/mongo/mongo2_instrumentation_test.rb +62 -23
- data/test/multiverse/suites/net_http/Envfile +2 -0
- data/test/multiverse/suites/net_http/net_http_test.rb +7 -3
- data/test/multiverse/suites/padrino/Envfile +2 -0
- data/test/multiverse/suites/rack/Envfile +2 -0
- data/test/multiverse/suites/rack/url_map_test.rb +4 -0
- data/test/multiverse/suites/rails/Envfile +34 -29
- data/test/multiverse/suites/rake/Envfile +11 -6
- data/test/multiverse/suites/redis/Envfile +2 -0
- data/test/multiverse/suites/redis/redis_instrumentation_test.rb +31 -12
- data/test/multiverse/suites/sidekiq/Envfile +6 -2
- data/test/multiverse/suites/sinatra/Envfile +2 -0
- data/test/multiverse/suites/typhoeus/Envfile +31 -27
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +4 -3
- data/test/multiverse/suites/yajl/Envfile +4 -2
- data/test/new_relic/agent/datastores_test.rb +0 -10
- data/test/new_relic/agent/instrumentation/action_cable_subscriber_test.rb +2 -2
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +64 -65
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +11 -9
- data/test/new_relic/agent/instrumentation/instance_identification_test.rb +9 -8
- data/test/new_relic/agent/instrumentation/mongodb_command_subscriber_test.rb +7 -11
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +4 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +0 -9
- data/test/new_relic/agent/method_tracer_test.rb +24 -8
- data/test/new_relic/agent/parameter_filtering_test.rb +2 -2
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -0
- data/test/new_relic/agent/transaction/abstract_segment_test.rb +25 -16
- data/test/new_relic/agent/transaction/datastore_segment_test.rb +55 -38
- data/test/new_relic/agent/transaction/external_request_segment_test.rb +330 -0
- data/test/new_relic/agent/transaction/segment_test.rb +28 -4
- data/test/new_relic/agent/transaction/tracing_test.rb +60 -22
- data/test/new_relic/agent_test.rb +2 -1
- data/test/new_relic/collection_helper_test.rb +1 -0
- data/test/new_relic/dispatcher_test.rb +1 -0
- data/test/new_relic/fake_external_server.rb +1 -1
- data/test/new_relic/filtering_test_app.rb +1 -1
- data/test/new_relic/http_client_test_cases.rb +38 -20
- data/test/new_relic/rack/error_collector_test.rb +1 -0
- data/test/performance/suites/external_segment.rb +82 -0
- data/test/script/before_install/update_bundler.sh +12 -0
- data/test/script/external_server.rb +31 -0
- metadata +8 -5
- data/test/multiverse/lib/multiverse/environment.rb +0 -19
- data/test/new_relic/agent/cross_app_tracing_test.rb +0 -71
- data/test/script/before_install/jruby_bundler.sh +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c1e2869b811ed3b76c7a71c8386d238e53fef6b
|
4
|
+
data.tar.gz: cdd29e0fce09cca5e0c72d07a2471b33ffe57282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1207f33db770af8824c989fea1658d55ac2a9e1630f2fea50044a498908257e6d51081aaecaae94f09a8238ceba070b7b3744026f390c98e377b688a2c59c3ea
|
7
|
+
data.tar.gz: 61ee001c5fc41aabfdb89b3ba741bfc9a37eb3b74bb8b16ef1e374f918dd3baba9ab1308e968c38c89b146a1720af347324e808031f968f365f16135cfc4b7c2
|
data/.travis.yml
CHANGED
@@ -10,8 +10,8 @@ sudo: required
|
|
10
10
|
before_install:
|
11
11
|
- ./test/script/before_install/revert_rubygems.sh
|
12
12
|
- gem --version
|
13
|
-
- ./test/script/before_install/jruby_bundler.sh
|
14
13
|
- ./test/script/before_install/gemstash_mirror.sh
|
14
|
+
- ./test/script/before_install/update_bundler.sh
|
15
15
|
- bundle --version
|
16
16
|
|
17
17
|
install: bundle install
|
@@ -33,9 +33,10 @@ notifications:
|
|
33
33
|
|
34
34
|
rvm:
|
35
35
|
# Run slowest builds first to try and optimize overall cycle time.
|
36
|
-
- jruby-1.7.23
|
36
|
+
- jruby-1.7.23
|
37
37
|
- jruby-9.1.2.0
|
38
|
-
- 2.
|
38
|
+
- 2.4.0
|
39
|
+
- 2.3.3
|
39
40
|
- 2.2.6
|
40
41
|
- 2.1.10
|
41
42
|
- 2.0.0-p648
|
@@ -76,32 +77,53 @@ env:
|
|
76
77
|
- TYPE=FUNCTIONAL GROUP=serialization
|
77
78
|
- TYPE=FUNCTIONAL GROUP=sinatra
|
78
79
|
- TYPE=FUNCTIONAL GROUP=rest
|
79
|
-
- TYPE=FUNCTIONAL GROUP=
|
80
|
+
- TYPE=FUNCTIONAL GROUP=background_2
|
80
81
|
- TYPE=NULLVERSE
|
81
82
|
|
82
83
|
matrix:
|
83
84
|
allow_failures:
|
84
85
|
- rvm: rbx-2.5.8
|
86
|
+
- rvm: ree
|
85
87
|
fast_finish: true
|
86
88
|
exclude:
|
87
89
|
- rvm: rbx-2.5.8 # Currently hangs
|
88
90
|
env: TYPE=FUNCTIONAL GROUP=agent
|
89
91
|
|
90
92
|
# Unsupported Rails/Ruby combinations
|
93
|
+
# 2.4
|
94
|
+
- rvm: 2.4.0
|
95
|
+
env: TYPE=UNIT ENVIRONMENT=rails21
|
96
|
+
- rvm: 2.4.0
|
97
|
+
env: TYPE=UNIT ENVIRONMENT=rails22
|
98
|
+
- rvm: 2.4.0
|
99
|
+
env: TYPE=UNIT ENVIRONMENT=rails23
|
100
|
+
- rvm: 2.4.0
|
101
|
+
env: TYPE=UNIT ENVIRONMENT=rails30
|
102
|
+
- rvm: 2.4.0
|
103
|
+
env: TYPE=UNIT ENVIRONMENT=rails31
|
104
|
+
- rvm: 2.4.0
|
105
|
+
env: TYPE=UNIT ENVIRONMENT=rails32
|
106
|
+
- rvm: 2.4.0
|
107
|
+
env: TYPE=UNIT ENVIRONMENT=rails40
|
108
|
+
- rvm: 2.4.0
|
109
|
+
env: TYPE=UNIT ENVIRONMENT=rails41
|
110
|
+
- rvm: 2.4.0
|
111
|
+
env: TYPE=UNIT ENVIRONMENT=rails42
|
112
|
+
|
91
113
|
# 2.3
|
92
|
-
- rvm: 2.3.
|
114
|
+
- rvm: 2.3.3
|
93
115
|
env: TYPE=UNIT ENVIRONMENT=rails21
|
94
|
-
- rvm: 2.3.
|
116
|
+
- rvm: 2.3.3
|
95
117
|
env: TYPE=UNIT ENVIRONMENT=rails22
|
96
|
-
- rvm: 2.3.
|
118
|
+
- rvm: 2.3.3
|
97
119
|
env: TYPE=UNIT ENVIRONMENT=rails23
|
98
120
|
|
99
121
|
# 2.2
|
100
|
-
- rvm: 2.2.
|
122
|
+
- rvm: 2.2.6
|
101
123
|
env: TYPE=UNIT ENVIRONMENT=rails21
|
102
|
-
- rvm: 2.2.
|
124
|
+
- rvm: 2.2.6
|
103
125
|
env: TYPE=UNIT ENVIRONMENT=rails22
|
104
|
-
- rvm: 2.2.
|
126
|
+
- rvm: 2.2.6
|
105
127
|
env: TYPE=UNIT ENVIRONMENT=rails23
|
106
128
|
|
107
129
|
# 2.1
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,50 @@
|
|
1
1
|
# New Relic Ruby Agent Release Notes #
|
2
2
|
|
3
|
-
|
3
|
+
## v3.18.0 ##
|
4
4
|
|
5
|
-
*
|
5
|
+
* Ruby 2.4.0 support
|
6
6
|
|
7
|
-
The
|
7
|
+
The agent is now tested against the official release of ruby 2.4.0,
|
8
|
+
excluding incompatible packages.
|
9
|
+
|
10
|
+
* Agent-based metrics will not be recorded outside of active transactions
|
11
|
+
|
12
|
+
The agent has historically recorded metrics outside of a transaction. In
|
13
|
+
practice, this usually occurs in applications that run background job
|
14
|
+
processors. The agent would record metrics for queries the
|
15
|
+
background job processor is making between transactions. This can lead
|
16
|
+
to display issues on the background overview page and the presence of
|
17
|
+
metrics generated by the background job processor can mask the application
|
18
|
+
generated metrics on the database page. The agent will no longer generate
|
19
|
+
metrics outside of a transaction. Custom metrics recorded using
|
20
|
+
`NewRelic::Agent.record_metric` will continue to be recorded regardless
|
21
|
+
of whether there is an active transaction.
|
22
|
+
|
23
|
+
* Include ControllerInstrumentation module with ActiveSupport.on_load
|
24
|
+
|
25
|
+
The agent will now use the `on_load :action_controller` hook to include
|
26
|
+
the ControllerInstrumentation module in to both the `Base` and `API`
|
27
|
+
classes of ActionController for Rails 5. This ensures that the proper
|
28
|
+
load order is retained, minimizing side-effects of having the agent in
|
29
|
+
an application.
|
30
|
+
|
31
|
+
* Ensure values for revisions on Capistrano deploy notices
|
32
|
+
|
33
|
+
Previously, running the task to look up the changelog could
|
34
|
+
generate an error, if there weren't previous and current revisions
|
35
|
+
defined. This has now been fixed. Thanks Winfield Peterson for the
|
36
|
+
contribution!
|
37
|
+
|
38
|
+
* External Segment Rewrites
|
39
|
+
|
40
|
+
The agent has made internal changes to how it represents segments for
|
41
|
+
external web requests.
|
42
|
+
|
43
|
+
## v3.17.2 ##
|
44
|
+
|
45
|
+
* compatibility with ruby 2.4.0-preview3
|
46
|
+
|
47
|
+
the ruby agent has been updated to work on ruby 2.4.0-preview3.
|
8
48
|
|
9
49
|
* Early Access Sinatra 2.0 instrumentation
|
10
50
|
|
data/Rakefile
CHANGED
@@ -22,27 +22,6 @@ namespace :test do
|
|
22
22
|
|
23
23
|
agent_home = File.expand_path(File.dirname(__FILE__))
|
24
24
|
|
25
|
-
# Agent-specific setup to enforce getting our proper suites directory
|
26
|
-
task :multiverse_setup do
|
27
|
-
ENV["SUITES_DIRECTORY"] = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'multiverse', 'suites'))
|
28
|
-
end
|
29
|
-
|
30
|
-
task :multiverse => :multiverse_setup
|
31
|
-
|
32
|
-
desc "Test the multiverse testing framework by executing tests in test/multiverse/test. Get meta with it."
|
33
|
-
task 'multiverse:self', [:suite, :mode] => [] do |t, args|
|
34
|
-
args.with_defaults(:suite => "", :mode => "")
|
35
|
-
puts ("Testing the multiverse testing framework...")
|
36
|
-
test_files = FileList['test/multiverse/test/*_test.rb']
|
37
|
-
ruby test_files.join(" ")
|
38
|
-
end
|
39
|
-
|
40
|
-
task 'multiverse:prime', [:suite] => [] do |t, args|
|
41
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'test', 'multiverse', 'lib', 'multiverse', 'environment'))
|
42
|
-
opts = Multiverse::Runner.parse_args(args)
|
43
|
-
Multiverse::Runner.prime(args.suite, opts)
|
44
|
-
end
|
45
|
-
|
46
25
|
desc "Run agent performance tests"
|
47
26
|
task :performance, [:suite, :name] => [] do |t, args|
|
48
27
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test', 'performance', 'lib', 'performance'))
|
@@ -7,135 +7,22 @@ module NewRelic
|
|
7
7
|
module Agent
|
8
8
|
module CrossAppTracing
|
9
9
|
|
10
|
-
# Exception raised if there is a problem with cross app transactions.
|
11
|
-
class Error < RuntimeError; end
|
12
|
-
|
13
10
|
# The cross app response header for "outgoing" calls
|
14
|
-
NR_APPDATA_HEADER = 'X-NewRelic-App-Data'
|
11
|
+
NR_APPDATA_HEADER = 'X-NewRelic-App-Data'.freeze
|
15
12
|
|
16
13
|
# The cross app id header for "outgoing" calls
|
17
|
-
NR_ID_HEADER = 'X-NewRelic-ID'
|
14
|
+
NR_ID_HEADER = 'X-NewRelic-ID'.freeze
|
18
15
|
|
19
16
|
# The cross app transaction header for "outgoing" calls
|
20
|
-
NR_TXN_HEADER = 'X-NewRelic-Transaction'
|
17
|
+
NR_TXN_HEADER = 'X-NewRelic-Transaction'.freeze
|
21
18
|
|
22
19
|
# The cross app synthetics header
|
23
|
-
NR_SYNTHETICS_HEADER = 'X-NewRelic-Synthetics'
|
24
|
-
|
25
|
-
# The index of the transaction GUID in the appdata header of responses
|
26
|
-
APPDATA_TXN_GUID_INDEX = 5
|
27
|
-
|
20
|
+
NR_SYNTHETICS_HEADER = 'X-NewRelic-Synthetics'.freeze
|
28
21
|
|
29
22
|
###############
|
30
23
|
module_function
|
31
24
|
###############
|
32
25
|
|
33
|
-
# Send the given +request+, adding metrics appropriate to the
|
34
|
-
# response when it comes back.
|
35
|
-
#
|
36
|
-
# See the documentation for +start_trace+ for an explanation of what
|
37
|
-
# +request+ should look like.
|
38
|
-
#
|
39
|
-
def tl_trace_http_request(request)
|
40
|
-
state = NewRelic::Agent::TransactionState.tl_get
|
41
|
-
return yield unless state.is_execution_traced?
|
42
|
-
|
43
|
-
# It's important to set t0 outside the ensured block, otherwise there's
|
44
|
-
# a race condition if we raise after begin but before t0's set.
|
45
|
-
t0 = Time.now
|
46
|
-
begin
|
47
|
-
node = start_trace(state, t0, request)
|
48
|
-
response = yield
|
49
|
-
ensure
|
50
|
-
finish_trace(state, t0, node, request, response)
|
51
|
-
end
|
52
|
-
|
53
|
-
return response
|
54
|
-
end
|
55
|
-
|
56
|
-
# Set up the necessary state for cross-application tracing before the
|
57
|
-
# given +request+ goes out.
|
58
|
-
#
|
59
|
-
# The +request+ object passed in must respond to the following methods:
|
60
|
-
#
|
61
|
-
# * type - Return a String describing the underlying library being used
|
62
|
-
# to make the request (e.g. 'Net::HTTP' or 'Typhoeus')
|
63
|
-
# * host - Return a String with the hostname or IP of the host being
|
64
|
-
# communicated with.
|
65
|
-
# * method - Return a String with the HTTP method name for this request
|
66
|
-
# * [](key) - Lookup an HTTP request header by name
|
67
|
-
# * []=(key, val) - Set an HTTP request header by name
|
68
|
-
# * uri - Full URI of the request
|
69
|
-
#
|
70
|
-
# This method returns the transaction node if it was sucessfully pushed.
|
71
|
-
def start_trace(state, t0, request)
|
72
|
-
inject_request_headers(state, request) if cross_app_enabled?
|
73
|
-
stack = state.traced_method_stack
|
74
|
-
node = stack.push_frame(state, :http_request, t0)
|
75
|
-
|
76
|
-
return node
|
77
|
-
rescue => err
|
78
|
-
NewRelic::Agent.logger.error "Uncaught exception while tracing HTTP request", err
|
79
|
-
return nil
|
80
|
-
rescue Exception => e
|
81
|
-
NewRelic::Agent.logger.debug "Unexpected exception raised while tracing HTTP request", e
|
82
|
-
|
83
|
-
raise e
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
# Finish tracing the HTTP +request+ that started at +t0+ with the information in
|
88
|
-
# +response+ and the given +http+ connection.
|
89
|
-
#
|
90
|
-
# The +request+ must conform to the same interface described in the documentation
|
91
|
-
# for +start_trace+.
|
92
|
-
#
|
93
|
-
# The +response+ must respond to the following methods:
|
94
|
-
#
|
95
|
-
# * [](key) - Reads response headers.
|
96
|
-
# * to_hash - Converts response headers to a Hash
|
97
|
-
#
|
98
|
-
def finish_trace(state, t0, node, request, response)
|
99
|
-
unless t0
|
100
|
-
NewRelic::Agent.logger.error("HTTP request trace finished without start time. This is probably an agent bug.")
|
101
|
-
return
|
102
|
-
end
|
103
|
-
|
104
|
-
t1 = Time.now
|
105
|
-
duration = t1.to_f - t0.to_f
|
106
|
-
|
107
|
-
begin
|
108
|
-
if request
|
109
|
-
# Figure out which metrics we need to report based on the request and response
|
110
|
-
# The last (most-specific) one is scoped.
|
111
|
-
metrics = metrics_for(request, response)
|
112
|
-
scoped_metric = metrics.pop
|
113
|
-
|
114
|
-
stats_engine.record_scoped_and_unscoped_metrics(
|
115
|
-
state, scoped_metric, metrics, duration)
|
116
|
-
|
117
|
-
# If we don't have node, something failed during start_trace so
|
118
|
-
# the current node isn't the HTTP call it should have been.
|
119
|
-
if node
|
120
|
-
node.name = scoped_metric
|
121
|
-
add_transaction_trace_parameters(request, response)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
ensure
|
125
|
-
# If we have a node, always pop the traced method stack to avoid
|
126
|
-
# an inconsistent state, which prevents tracing of whole transaction.
|
127
|
-
if node
|
128
|
-
stack = state.traced_method_stack
|
129
|
-
stack.pop_frame(state, node, scoped_metric, t1)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
rescue NewRelic::Agent::CrossAppTracing::Error => err
|
133
|
-
NewRelic::Agent.logger.debug "while cross app tracing", err
|
134
|
-
rescue => err
|
135
|
-
NewRelic::Agent.logger.error "Uncaught exception while finishing an HTTP request trace", err
|
136
|
-
end
|
137
|
-
|
138
|
-
# Return +true+ if cross app tracing is enabled in the config.
|
139
26
|
def cross_app_enabled?
|
140
27
|
valid_cross_process_id? &&
|
141
28
|
valid_encoding_key? &&
|
@@ -143,138 +30,51 @@ module NewRelic
|
|
143
30
|
end
|
144
31
|
|
145
32
|
def valid_cross_process_id?
|
146
|
-
NewRelic::Agent.config[:cross_process_id] && NewRelic::Agent.config[:cross_process_id].length > 0
|
33
|
+
if NewRelic::Agent.config[:cross_process_id] && NewRelic::Agent.config[:cross_process_id].length > 0
|
34
|
+
true
|
35
|
+
else
|
36
|
+
NewRelic::Agent.logger.debug "No cross_process_id configured"
|
37
|
+
false
|
38
|
+
end
|
147
39
|
end
|
148
40
|
|
149
41
|
def valid_encoding_key?
|
150
|
-
NewRelic::Agent.config[:encoding_key] && NewRelic::Agent.config[:encoding_key].length > 0
|
42
|
+
if NewRelic::Agent.config[:encoding_key] && NewRelic::Agent.config[:encoding_key].length > 0
|
43
|
+
true
|
44
|
+
else
|
45
|
+
NewRelic::Agent.logger.debug "No encoding_key set"
|
46
|
+
false
|
47
|
+
end
|
151
48
|
end
|
152
49
|
|
153
50
|
def cross_application_tracer_enabled?
|
154
51
|
NewRelic::Agent.config[:"cross_application_tracer.enabled"] || NewRelic::Agent.config[:cross_application_tracing]
|
155
52
|
end
|
156
53
|
|
157
|
-
# Fetcher for the cross app encoding key. Raises a
|
158
|
-
# NewRelic::Agent::CrossAppTracing::Error if the key isn't configured.
|
159
|
-
def cross_app_encoding_key
|
160
|
-
NewRelic::Agent.config[:encoding_key] or
|
161
|
-
raise NewRelic::Agent::CrossAppTracing::Error, "No encoding_key set."
|
162
|
-
end
|
163
|
-
|
164
54
|
def obfuscator
|
165
|
-
@obfuscator ||= NewRelic::Agent::Obfuscator.new(
|
55
|
+
@obfuscator ||= NewRelic::Agent::Obfuscator.new(NewRelic::Agent.config[:encoding_key])
|
166
56
|
end
|
167
57
|
|
168
|
-
|
169
|
-
|
170
|
-
cross_app_id = NewRelic::Agent.config[:cross_process_id] or
|
171
|
-
raise NewRelic::Agent::CrossAppTracing::Error, "no cross app ID configured"
|
172
|
-
|
173
|
-
state.is_cross_app_caller = true
|
174
|
-
txn_guid = state.request_guid
|
175
|
-
txn = state.current_transaction
|
176
|
-
if txn
|
177
|
-
trip_id = txn.cat_trip_id(state)
|
178
|
-
path_hash = txn.cat_path_hash(state)
|
179
|
-
|
180
|
-
if txn.raw_synthetics_header
|
181
|
-
request[NR_SYNTHETICS_HEADER] = txn.raw_synthetics_header
|
182
|
-
end
|
183
|
-
end
|
58
|
+
def insert_request_headers(request, txn_guid, trip_id, path_hash, synthetics_header)
|
59
|
+
cross_app_id = NewRelic::Agent.config[:cross_process_id]
|
184
60
|
txn_data = NewRelic::JSONWrapper.dump([txn_guid, false, trip_id, path_hash])
|
185
61
|
|
186
62
|
request[NR_ID_HEADER] = obfuscator.obfuscate(cross_app_id)
|
187
63
|
request[NR_TXN_HEADER] = obfuscator.obfuscate(txn_data)
|
188
|
-
|
189
|
-
|
190
|
-
NewRelic::Agent.logger.debug "Not injecting x-process header", err
|
191
|
-
end
|
192
|
-
|
193
|
-
def add_transaction_trace_parameters(request, response)
|
194
|
-
filtered_uri = ::NewRelic::Agent::HTTPClients::URIUtil.filter_uri(request.uri)
|
195
|
-
transaction_sampler.add_node_parameters(:uri => filtered_uri)
|
196
|
-
if response && response_is_crossapp?(response)
|
197
|
-
add_cat_transaction_trace_parameters(response)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
# Extract any custom parameters from +response+ if it's cross-application and
|
203
|
-
# add them to the current TT node.
|
204
|
-
def add_cat_transaction_trace_parameters( response )
|
205
|
-
appdata = extract_appdata( response )
|
206
|
-
transaction_sampler.add_node_parameters( \
|
207
|
-
:transaction_guid => appdata[APPDATA_TXN_GUID_INDEX] )
|
208
|
-
end
|
209
|
-
|
210
|
-
|
211
|
-
# Return the set of metric names that correspond to
|
212
|
-
# the given +request+ and +response+.
|
213
|
-
# +response+ may be nil in the case that the request produced an error
|
214
|
-
# without ever receiving an HTTP response.
|
215
|
-
def metrics_for( request, response )
|
216
|
-
metrics = common_metrics( request )
|
217
|
-
|
218
|
-
if response && response_is_crossapp?( response )
|
219
|
-
begin
|
220
|
-
metrics.concat metrics_for_crossapp_response( request, response )
|
221
|
-
rescue => err
|
222
|
-
# Fall back to regular metrics if there's a problem with x-process metrics
|
223
|
-
NewRelic::Agent.logger.debug "%p while fetching x-process metrics: %s" %
|
224
|
-
[ err.class, err.message ]
|
225
|
-
metrics.concat metrics_for_regular_request( request )
|
226
|
-
end
|
227
|
-
else
|
228
|
-
metrics.concat metrics_for_regular_request( request )
|
64
|
+
if synthetics_header
|
65
|
+
request[NR_SYNTHETICS_HEADER] = synthetics_header
|
229
66
|
end
|
230
|
-
|
231
|
-
return metrics
|
232
67
|
end
|
233
68
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
metrics = [ "External/all" ]
|
238
|
-
metrics << "External/#{request.host}/all"
|
239
|
-
|
240
|
-
if NewRelic::Agent::Transaction.recording_web_transaction?
|
241
|
-
metrics << "External/allWeb"
|
69
|
+
def response_has_crossapp_header?(response)
|
70
|
+
if !!response[NR_APPDATA_HEADER]
|
71
|
+
true
|
242
72
|
else
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
return metrics
|
247
|
-
end
|
248
|
-
|
249
|
-
|
250
|
-
# Returns +true+ if Cross Application Tracing is enabled, and the given +response+
|
251
|
-
# has the appropriate headers.
|
252
|
-
def response_is_crossapp?( response )
|
253
|
-
return false unless cross_app_enabled?
|
254
|
-
unless response[NR_APPDATA_HEADER]
|
255
|
-
return false
|
73
|
+
NewRelic::Agent.logger.debug "No #{NR_APPDATA_HEADER} header"
|
74
|
+
false
|
256
75
|
end
|
257
|
-
|
258
|
-
return true
|
259
76
|
end
|
260
77
|
|
261
|
-
|
262
|
-
# Return the set of metric objects appropriate for the given cross app
|
263
|
-
# +response+.
|
264
|
-
def metrics_for_crossapp_response( request, response )
|
265
|
-
xp_id, txn_name, _q_time, _r_time, _req_len, _ = extract_appdata( response )
|
266
|
-
|
267
|
-
check_crossapp_id( xp_id )
|
268
|
-
check_transaction_name( txn_name )
|
269
|
-
|
270
|
-
metrics = []
|
271
|
-
metrics << "ExternalApp/#{request.host}/#{xp_id}/all"
|
272
|
-
metrics << "ExternalTransaction/#{request.host}/#{xp_id}/#{txn_name}"
|
273
|
-
|
274
|
-
return metrics
|
275
|
-
end
|
276
|
-
|
277
|
-
|
278
78
|
# Extract x-process application data from the specified +response+ and return
|
279
79
|
# it as an array of the form:
|
280
80
|
#
|
@@ -286,54 +86,19 @@ module NewRelic
|
|
286
86
|
# <request content length in bytes>,
|
287
87
|
# <transaction GUID>
|
288
88
|
# ]
|
289
|
-
def extract_appdata(
|
290
|
-
appdata = response[NR_APPDATA_HEADER]
|
291
|
-
raise NewRelic::Agent::CrossAppTracing::Error,
|
292
|
-
"Can't derive metrics for response: no #{NR_APPDATA_HEADER} header!"
|
293
|
-
|
294
|
-
decoded_appdata = obfuscator.deobfuscate( appdata )
|
295
|
-
decoded_appdata.set_encoding( ::Encoding::UTF_8 ) if
|
296
|
-
decoded_appdata.respond_to?( :set_encoding )
|
297
|
-
|
298
|
-
return NewRelic::JSONWrapper.load( decoded_appdata )
|
299
|
-
end
|
89
|
+
def extract_appdata(response)
|
90
|
+
appdata = response[NR_APPDATA_HEADER]
|
300
91
|
|
92
|
+
decoded_appdata = obfuscator.deobfuscate(appdata)
|
93
|
+
decoded_appdata.set_encoding(::Encoding::UTF_8) if
|
94
|
+
decoded_appdata.respond_to?(:set_encoding)
|
301
95
|
|
302
|
-
|
303
|
-
# +request+.
|
304
|
-
def metrics_for_regular_request( request )
|
305
|
-
metrics = []
|
306
|
-
metrics << "External/#{request.host}/#{request.type}/#{request.method}"
|
307
|
-
|
308
|
-
return metrics
|
309
|
-
end
|
310
|
-
|
311
|
-
|
312
|
-
# Fetch a reference to the stats engine.
|
313
|
-
def stats_engine
|
314
|
-
NewRelic::Agent.instance.stats_engine
|
315
|
-
end
|
316
|
-
|
317
|
-
def transaction_sampler
|
318
|
-
NewRelic::Agent.instance.transaction_sampler
|
96
|
+
NewRelic::JSONWrapper.load(decoded_appdata)
|
319
97
|
end
|
320
98
|
|
321
|
-
|
322
|
-
|
323
|
-
def check_crossapp_id( id )
|
324
|
-
id =~ /\A\d+#\d+\z/ or
|
325
|
-
raise NewRelic::Agent::CrossAppTracing::Error,
|
326
|
-
"malformed cross application ID %p" % [ id ]
|
99
|
+
def valid_cross_app_id?(xp_id)
|
100
|
+
!!(xp_id =~ /\A\d+#\d+\z/)
|
327
101
|
end
|
328
|
-
|
329
|
-
|
330
|
-
# Check the given +name+ to ensure it conforms to the format of a valid transaction
|
331
|
-
# name.
|
332
|
-
def check_transaction_name( name )
|
333
|
-
# No-op -- apparently absolutely anything is a valid transaction name?
|
334
|
-
# This is here for when that inevitably comes back to haunt us.
|
335
|
-
end
|
336
|
-
|
337
102
|
end
|
338
103
|
end
|
339
104
|
end
|