newrelic_rpm 6.15.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +164 -22
  3. data/CONTRIBUTING.md +13 -2
  4. data/README.md +2 -2
  5. data/lib/new_relic/agent.rb +5 -8
  6. data/lib/new_relic/agent/agent.rb +2 -1
  7. data/lib/new_relic/agent/autostart.rb +1 -2
  8. data/lib/new_relic/agent/configuration/default_source.rb +442 -227
  9. data/lib/new_relic/agent/configuration/manager.rb +3 -3
  10. data/lib/new_relic/agent/connect/request_builder.rb +4 -2
  11. data/lib/new_relic/agent/datastores/redis.rb +0 -4
  12. data/lib/new_relic/agent/distributed_tracing.rb +0 -66
  13. data/lib/new_relic/agent/error_collector.rb +52 -37
  14. data/lib/new_relic/agent/error_filter.rb +167 -0
  15. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
  16. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
  17. data/lib/new_relic/agent/instrumentation/bunny.rb +10 -152
  18. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  19. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
  20. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  21. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
  22. data/lib/new_relic/agent/instrumentation/curb.rb +9 -241
  23. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  24. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  25. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  26. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  27. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  29. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -50
  30. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  31. data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
  32. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  33. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  34. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  35. data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
  36. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  37. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  38. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  39. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  40. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  41. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  42. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  43. data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
  44. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  45. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
  46. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  47. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  48. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  49. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -0
  50. data/lib/new_relic/agent/instrumentation/mongo.rb +7 -0
  51. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  52. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  53. data/lib/new_relic/agent/instrumentation/{net_prepend.rb → net_http/instrumentation.rb} +3 -3
  54. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  55. data/lib/new_relic/agent/instrumentation/padrino.rb +18 -53
  56. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  57. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  58. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  59. data/lib/new_relic/agent/instrumentation/rack.rb +29 -139
  60. data/lib/new_relic/agent/instrumentation/rack/chain.rb +58 -0
  61. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  62. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  63. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +37 -0
  64. data/lib/new_relic/agent/instrumentation/rake.rb +13 -154
  65. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  66. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  67. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  68. data/lib/new_relic/agent/instrumentation/redis.rb +12 -107
  69. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  70. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  71. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  72. data/lib/new_relic/agent/instrumentation/resque.rb +21 -32
  73. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  74. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  75. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
  76. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  77. data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -158
  78. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  79. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
  80. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
  81. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  82. data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
  83. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  84. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  85. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  86. data/lib/new_relic/agent/javascript_instrumentor.rb +12 -7
  87. data/lib/new_relic/agent/new_relic_service.rb +15 -13
  88. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  89. data/lib/new_relic/agent/transaction.rb +1 -4
  90. data/lib/new_relic/control/frameworks/rails.rb +11 -9
  91. data/lib/new_relic/control/instance_methods.rb +1 -0
  92. data/lib/new_relic/dependency_detection.rb +116 -10
  93. data/lib/new_relic/noticed_error.rb +4 -8
  94. data/lib/new_relic/supportability_helper.rb +1 -2
  95. data/lib/new_relic/version.rb +2 -2
  96. data/lib/tasks/config.html.erb +14 -25
  97. data/lib/tasks/config.rake +8 -7
  98. data/newrelic_rpm.gemspec +1 -1
  99. metadata +55 -8
  100. data/cert/cacert.pem +0 -1177
  101. data/lib/new_relic/agent/instrumentation/http.rb +0 -49
  102. data/lib/new_relic/agent/instrumentation/net.rb +0 -70
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+ # frozen_string_literal: true
5
+
6
+ require_relative 'instrumentation'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module Instrumentation
11
+ module DelayedJob
12
+ module Prepend
13
+ include NewRelic::Agent::Instrumentation::DelayedJob
14
+
15
+ def initialize(*args)
16
+ initialize_with_tracing { super }
17
+ end
18
+
19
+ def install_newrelic_job_tracer
20
+ Delayed::Job.send :prepend, ::NewRelic::Agent::Instrumentation::DelayedJobTracerPrepend
21
+ end
22
+ end
23
+ end
24
+
25
+ module DelayedJobTracerPrepend
26
+ include NewRelic::Agent::Instrumentation::DelayedJobTracer
27
+
28
+ def invoke_job(*args, &block)
29
+ invoke_job_with_tracing { super }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,9 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
+ require_relative 'delayed_job/chain'
6
+ require_relative 'delayed_job/prepend'
7
+
5
8
  require 'new_relic/agent/instrumentation/controller_instrumentation'
6
9
 
7
10
  module NewRelic
@@ -76,11 +79,7 @@ DependencyDetection.defer do
76
79
  @name = :delayed_job
77
80
 
78
81
  depends_on do
79
- !NewRelic::Agent.config[:disable_dj]
80
- end
81
-
82
- depends_on do
83
- defined?(::Delayed) && defined?(::Delayed::Worker) && !NewRelic::Agent.config[:disable_dj]
82
+ defined?(::Delayed) && defined?(::Delayed::Worker)
84
83
  end
85
84
 
86
85
  executes do
@@ -88,51 +87,10 @@ DependencyDetection.defer do
88
87
  end
89
88
 
90
89
  executes do
91
- Delayed::Worker.class_eval do
92
-
93
- def initialize_with_new_relic(*args)
94
- initialize_without_new_relic(*args)
95
- worker_name = case
96
- when self.respond_to?(:name) then self.name
97
- when self.class.respond_to?(:default_name) then self.class.default_name
98
- end
99
- NewRelic::DelayedJobInjection.worker_name = worker_name
100
-
101
- if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
102
- !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic) )
103
-
104
- ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
105
- install_newrelic_job_tracer
106
- NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
107
- else
108
- NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
109
- end
110
- end
111
-
112
- alias initialize_without_new_relic initialize
113
- alias initialize initialize_with_new_relic
114
-
115
- NR_TRANSACTION_CATEGORY = 'OtherTransaction/DelayedJob'.freeze
116
-
117
- def install_newrelic_job_tracer
118
- Delayed::Job.class_eval do
119
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation
120
-
121
- alias_method :invoke_job_without_new_relic, :invoke_job
122
-
123
- def invoke_job(*args, &block)
124
- options = {
125
- :category => NR_TRANSACTION_CATEGORY,
126
- :path => ::NewRelic::Agent::Instrumentation::DelayedJob::Naming.name_from_payload(payload_object)
127
- }
128
-
129
- perform_action_with_newrelic_trace(options) do
130
- invoke_job_without_new_relic(*args, &block)
131
- end
132
- end
133
-
134
- end
135
- end
90
+ if use_prepend?
91
+ prepend_instrument ::Delayed::Worker, ::NewRelic::Agent::Instrumentation::DelayedJob::Prepend
92
+ else
93
+ chain_instrument ::NewRelic::Agent::Instrumentation::DelayedJob::Chain
136
94
  end
137
95
  end
138
96
  end
@@ -65,7 +65,8 @@ DependencyDetection.defer do
65
65
  end
66
66
 
67
67
  def install_legacy_excon_instrumentation
68
- ::NewRelic::Agent.logger.info 'Installing legacy Excon instrumentation'
68
+ ::NewRelic::Agent::Deprecator.deprecate :install_legacy_excon_instrumentation, :install_middleware_excon_instrumentation, "8.0.0"
69
+ ::NewRelic::Agent.logger.warn 'Installing deprecated legacy Excon instrumentation. This instrumentation will be removed in a future release. Update Excon version to > 0.19.0 for updated instrumentation'
69
70
  require 'new_relic/agent/instrumentation/excon/connection'
70
71
  ::Excon::Connection.install_newrelic_instrumentation
71
72
  end
@@ -2,90 +2,19 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
- require 'new_relic/agent/parameter_filtering'
6
-
7
- module NewRelic
8
- module Agent
9
- module Instrumentation
10
- module GrapeInstrumentation
11
- extend self
12
-
13
- API_ENDPOINT = 'api.endpoint'.freeze
14
- API_VERSION = 'api.version'.freeze
15
- FORMAT_REGEX = /\(\/?\.[\:\w]*\)/.freeze # either :format (< 0.12.0) or .ext (>= 0.12.0)
16
- VERSION_REGEX = /:version(\/|$)/.freeze
17
- MIN_VERSION = Gem::Version.new("0.2.0")
18
- PIPE_STRING = '|'.freeze
19
-
20
- def handle_transaction(endpoint, class_name, version)
21
- return unless endpoint && route = endpoint.route
22
- name_transaction(route, class_name, version)
23
- capture_params(endpoint)
24
- end
25
-
26
- def name_transaction(route, class_name, version)
27
- txn_name = name_for_transaction(route, class_name, version)
28
- segment_name = "Middleware/Grape/#{class_name}/call"
29
- Transaction.set_default_transaction_name(txn_name, :grape)
30
- txn = NewRelic::Agent::Transaction.tl_current
31
- txn.segments.last.name = segment_name
32
- end
33
-
34
- def name_for_transaction(route, class_name, version)
35
- action_name = route.path.sub(FORMAT_REGEX, NewRelic::EMPTY_STR)
36
- method_name = route.request_method
37
- version ||= route.version
38
-
39
- # defaulting does not set rack.env['api.version'] and route.version may return Array
40
- #
41
- version = version.join(PIPE_STRING) if Array === version
42
-
43
- if version
44
- action_name = action_name.sub(VERSION_REGEX, NewRelic::EMPTY_STR)
45
- "#{class_name}-#{version}#{action_name} (#{method_name})"
46
- else
47
- "#{class_name}#{action_name} (#{method_name})"
48
- end
49
- end
50
-
51
- def name_for_transaction_deprecated(route, class_name, version)
52
- action_name = route.route_path.sub(FORMAT_REGEX, NewRelic::EMPTY_STR)
53
- method_name = route.route_method
54
- version ||= route.route_version
55
-
56
- if version
57
- action_name = action_name.sub(VERSION_REGEX, NewRelic::EMPTY_STR)
58
- "#{class_name}-#{version}#{action_name} (#{method_name})"
59
- else
60
- "#{class_name}#{action_name} (#{method_name})"
61
- end
62
- end
63
-
64
- def capture_params(endpoint)
65
- txn = Transaction.tl_current
66
- env = endpoint.request.env
67
- params = ParameterFiltering::apply_filters(env, endpoint.params)
68
- params.delete("route_info")
69
- txn.filtered_params = params
70
- txn.merge_request_parameters(params)
71
- end
72
- end
73
- end
74
- end
75
- end
5
+ require_relative 'grape/instrumentation'
6
+ require_relative 'grape/chain'
7
+ require_relative 'grape/prepend'
76
8
 
77
9
  DependencyDetection.defer do
78
10
  # Why not just :grape? newrelic-grape used that name already, and while we're
79
11
  # not shipping yet, overloading the name interferes with the plugin.
80
12
  named :grape_instrumentation
81
-
82
- depends_on do
83
- ::NewRelic::Agent.config[:disable_grape] == false
84
- end
85
-
13
+ configure_with :grape
14
+
86
15
  depends_on do
87
16
  defined?(::Grape::VERSION) &&
88
- Gem::Version.new(::Grape::VERSION) >= ::NewRelic::Agent::Instrumentation::GrapeInstrumentation::MIN_VERSION
17
+ Gem::Version.new(::Grape::VERSION) >= ::NewRelic::Agent::Instrumentation::Grape::Instrumentation::MIN_VERSION
89
18
  end
90
19
 
91
20
  depends_on do
@@ -103,43 +32,14 @@ DependencyDetection.defer do
103
32
  end
104
33
 
105
34
  executes do
106
- NewRelic::Agent.logger.info 'Installing New Relic supported Grape instrumentation'
107
- instrument_call
108
- end
35
+ ::NewRelic::Agent::Instrumentation::Grape::Instrumentation.prepare!
109
36
 
110
- def instrument_call
111
- if defined?(Grape::VERSION) && Gem::Version.new(::Grape::VERSION) >= Gem::Version.new("0.16.0")
112
- ::NewRelic::Agent::Instrumentation::GrapeInstrumentation.send :remove_method, :name_for_transaction_deprecated
113
- else
114
- ::NewRelic::Agent::Instrumentation::GrapeInstrumentation.send :remove_method, :name_for_transaction
115
- ::NewRelic::Agent::Instrumentation::GrapeInstrumentation.send :alias_method, :name_for_transaction, :name_for_transaction_deprecated
116
- end
117
-
118
- # Since 1.2.0, the class `Grape::API` no longer refers to an API instance, rather, what used to be `Grape::API` is `Grape::API::Instance`
119
- # https://github.com/ruby-grape/grape/blob/c20a73ac1e3f3ba1082005ed61bf69452373ba87/UPGRADING.md#upgrading-to--120
120
- grape_api_class = defined?(Grape::API::Instance) ? ::Grape::API::Instance : ::Grape::API
121
-
122
- grape_api_class.class_eval do
123
- def call_with_new_relic(env)
124
- begin
125
- response = call_without_new_relic(env)
126
- ensure
127
- begin
128
- endpoint = env[::NewRelic::Agent::Instrumentation::GrapeInstrumentation::API_ENDPOINT]
129
- version = env[::NewRelic::Agent::Instrumentation::GrapeInstrumentation::API_VERSION]
130
-
131
- api_class = (self.class.respond_to?(:base) && self.class.base) || self.class
132
- ::NewRelic::Agent::Instrumentation::GrapeInstrumentation.handle_transaction(endpoint, api_class.name, version)
133
- rescue => e
134
- ::NewRelic::Agent.logger.warn("Error in Grape instrumentation", e)
135
- end
136
- end
137
-
138
- response
139
- end
140
-
141
- alias_method :call_without_new_relic, :call
142
- alias_method :call, :call_with_new_relic
37
+ if use_prepend?
38
+ instrumented_class = ::NewRelic::Agent::Instrumentation::Grape::Instrumentation.instrumented_class
39
+ prepend_instrument instrumented_class, ::NewRelic::Agent::Instrumentation::Grape::Prepend
40
+ else
41
+ chain_instrument ::NewRelic::Agent::Instrumentation::Grape::Chain
143
42
  end
144
43
  end
44
+
145
45
  end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Grape
7
+ module Chain
8
+ def self.instrument!
9
+ Grape::Instrumentation.instrumented_class.class_eval do
10
+ def call_with_new_relic env
11
+ begin
12
+ call_without_new_relic env
13
+ ensure
14
+ Grape::Instrumentation.capture_transaction env, self
15
+ end
16
+ end
17
+
18
+ alias_method :call_without_new_relic, :call
19
+ alias_method :call, :call_with_new_relic
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ require 'new_relic/agent/parameter_filtering'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module Grape
9
+ module Instrumentation
10
+
11
+ extend self
12
+
13
+ # Since 1.2.0, the class `Grape::API` no longer refers to an API instance, rather, what used to be `Grape::API` is `Grape::API::Instance`
14
+ # https://github.com/ruby-grape/grape/blob/c20a73ac1e3f3ba1082005ed61bf69452373ba87/UPGRADING.md#upgrading-to--120
15
+ def instrumented_class
16
+ defined?(::Grape::API::Instance) ? ::Grape::API::Instance : ::Grape::API
17
+ end
18
+
19
+ def capture_transaction env, context
20
+ begin
21
+ endpoint = env[API_ENDPOINT]
22
+ version = env[API_VERSION]
23
+
24
+ api_class = (context.class.respond_to?(:base) && context.class.base) || context.class
25
+ handle_transaction(endpoint, api_class.name, version)
26
+ rescue => e
27
+ ::NewRelic::Agent.logger.warn("Error in Grape instrumentation", e)
28
+ end
29
+ end
30
+
31
+ def prepare!
32
+ if defined?(::Grape::VERSION) && Gem::Version.new(::Grape::VERSION) >= Gem::Version.new("0.16.0")
33
+ send :remove_method, :name_for_transaction_deprecated
34
+ else
35
+ send :remove_method, :name_for_transaction
36
+ send :alias_method, :name_for_transaction, :name_for_transaction_deprecated
37
+ end
38
+ end
39
+
40
+ API_ENDPOINT = 'api.endpoint'.freeze
41
+ API_VERSION = 'api.version'.freeze
42
+ FORMAT_REGEX = /\(\/?\.[\:\w]*\)/.freeze # either :format (< 0.12.0) or .ext (>= 0.12.0)
43
+ VERSION_REGEX = /:version(\/|$)/.freeze
44
+ MIN_VERSION = Gem::Version.new("0.2.0")
45
+ PIPE_STRING = '|'.freeze
46
+
47
+ def handle_transaction(endpoint, class_name, version)
48
+ return unless endpoint && route = endpoint.route
49
+ name_transaction(route, class_name, version)
50
+ capture_params(endpoint)
51
+ end
52
+
53
+ def name_transaction(route, class_name, version)
54
+ txn_name = name_for_transaction(route, class_name, version)
55
+ segment_name = "Middleware/Grape/#{class_name}/call"
56
+ NewRelic::Agent::Transaction.set_default_transaction_name(txn_name, :grape)
57
+ txn = NewRelic::Agent::Transaction.tl_current
58
+ txn.segments.last.name = segment_name
59
+ end
60
+
61
+ def name_for_transaction(route, class_name, version)
62
+ action_name = route.path.sub(FORMAT_REGEX, NewRelic::EMPTY_STR)
63
+ method_name = route.request_method
64
+ version ||= route.version
65
+
66
+ # defaulting does not set rack.env['api.version'] and route.version may return Array
67
+ #
68
+ version = version.join(PIPE_STRING) if Array === version
69
+
70
+ if version
71
+ action_name = action_name.sub(VERSION_REGEX, NewRelic::EMPTY_STR)
72
+ "#{class_name}-#{version}#{action_name} (#{method_name})"
73
+ else
74
+ "#{class_name}#{action_name} (#{method_name})"
75
+ end
76
+ end
77
+
78
+ def name_for_transaction_deprecated(route, class_name, version)
79
+ action_name = route.route_path.sub(FORMAT_REGEX, NewRelic::EMPTY_STR)
80
+ method_name = route.route_method
81
+ version ||= route.route_version
82
+ if version
83
+ action_name = action_name.sub(VERSION_REGEX, NewRelic::EMPTY_STR)
84
+ "#{class_name}-#{version}#{action_name} (#{method_name})"
85
+ else
86
+ "#{class_name}#{action_name} (#{method_name})"
87
+ end
88
+ end
89
+
90
+ def capture_params(endpoint)
91
+ txn = ::NewRelic::Agent::Transaction.tl_current
92
+ env = endpoint.request.env
93
+ params = ::NewRelic::Agent::ParameterFiltering::apply_filters(env, endpoint.params)
94
+ params.delete("route_info")
95
+ txn.filtered_params = params
96
+ txn.merge_request_parameters(params)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Grape
7
+ module Prepend
8
+ def call env
9
+ begin
10
+ super env
11
+ ensure
12
+ Grape::Instrumentation.capture_transaction env, self
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,6 +2,10 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
 
5
+ require_relative 'httpclient/instrumentation'
6
+ require_relative 'httpclient/chain'
7
+ require_relative 'httpclient/prepend'
8
+
5
9
  DependencyDetection.defer do
6
10
  named :httpclient
7
11
 
@@ -25,36 +29,10 @@ DependencyDetection.defer do
25
29
  end
26
30
 
27
31
  executes do
28
- class HTTPClient
29
- def do_get_block_with_newrelic(req, proxy, conn, &block)
30
- wrapped_request = NewRelic::Agent::HTTPClients::HTTPClientRequest.new(req)
31
- segment = NewRelic::Agent::Tracer.start_external_request_segment(
32
- library: wrapped_request.type,
33
- uri: wrapped_request.uri,
34
- procedure: wrapped_request.method
35
- )
36
-
37
- begin
38
- response = nil
39
- segment.add_request_headers wrapped_request
40
-
41
- NewRelic::Agent::Tracer.capture_segment_error segment do
42
- do_get_block_without_newrelic(req, proxy, conn, &block)
43
- end
44
- response = conn.pop
45
- conn.push response
46
-
47
- wrapped_response = ::NewRelic::Agent::HTTPClients::HTTPClientResponse.new(response)
48
- segment.process_response_headers wrapped_response
49
-
50
- response
51
- ensure
52
- segment.finish if segment
53
- end
54
- end
55
-
56
- alias do_get_block_without_newrelic do_get_block
57
- alias do_get_block do_get_block_with_newrelic
32
+ if use_prepend?
33
+ prepend_instrument ::HTTPClient, NewRelic::Agent::Instrumentation::HTTPClient::Prepend
34
+ else
35
+ chain_instrument NewRelic::Agent::Instrumentation::HTTPClient::Chain
58
36
  end
59
37
  end
60
38
  end