newrelic_rpm 6.12.0.367 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/CHANGELOG.md +269 -8
  4. data/CONTRIBUTING.md +54 -11
  5. data/README.md +40 -16
  6. data/ROADMAP.md +24 -0
  7. data/lib/new_relic/agent.rb +3 -10
  8. data/lib/new_relic/agent/agent.rb +6 -4
  9. data/lib/new_relic/agent/audit_logger.rb +10 -0
  10. data/lib/new_relic/agent/autostart.rb +1 -2
  11. data/lib/new_relic/agent/configuration/default_source.rb +294 -102
  12. data/lib/new_relic/agent/configuration/manager.rb +2 -2
  13. data/lib/new_relic/agent/database_adapter.rb +33 -0
  14. data/lib/new_relic/agent/datastores/redis.rb +0 -4
  15. data/lib/new_relic/agent/distributed_tracing.rb +0 -66
  16. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +2 -2
  17. data/lib/new_relic/agent/http_clients/uri_util.rb +8 -8
  18. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -5
  19. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +21 -68
  20. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
  21. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +23 -57
  22. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -15
  23. data/lib/new_relic/agent/instrumentation/bunny.rb +10 -196
  24. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  25. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
  26. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  27. data/lib/new_relic/agent/instrumentation/curb.rb +9 -259
  28. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  29. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  30. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  31. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  32. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  33. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  34. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -84
  35. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  36. data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
  37. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  38. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  39. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  40. data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
  41. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  42. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  43. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  44. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  46. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  47. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  48. data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
  49. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  50. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
  51. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  52. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  53. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  54. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -10
  55. data/lib/new_relic/agent/instrumentation/mongo.rb +7 -0
  56. data/lib/new_relic/agent/instrumentation/net_http.rb +39 -0
  57. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  58. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
  59. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  60. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
  61. data/lib/new_relic/agent/instrumentation/padrino.rb +18 -75
  62. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  63. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  64. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  65. data/lib/new_relic/agent/instrumentation/rack.rb +29 -160
  66. data/lib/new_relic/agent/instrumentation/rack/chain.rb +57 -0
  67. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  68. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  69. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +36 -0
  70. data/lib/new_relic/agent/instrumentation/rake.rb +13 -187
  71. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  72. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  73. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  74. data/lib/new_relic/agent/instrumentation/redis.rb +10 -188
  75. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  76. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  77. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  78. data/lib/new_relic/agent/instrumentation/resque.rb +8 -28
  79. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  80. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +33 -0
  81. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  82. data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -1
  83. data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -198
  84. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  85. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
  86. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +118 -0
  87. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  88. data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
  89. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  90. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  91. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  92. data/lib/new_relic/agent/method_tracer.rb +6 -16
  93. data/lib/new_relic/agent/new_relic_service.rb +19 -5
  94. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  95. data/lib/new_relic/agent/span_event_primitive.rb +10 -8
  96. data/lib/new_relic/agent/sql_sampler.rb +1 -1
  97. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  98. data/lib/new_relic/agent/transaction.rb +1 -4
  99. data/lib/new_relic/agent/transaction/abstract_segment.rb +1 -1
  100. data/lib/new_relic/agent/transaction/distributed_tracer.rb +12 -6
  101. data/lib/new_relic/agent/transaction/external_request_segment.rb +2 -2
  102. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
  103. data/lib/new_relic/agent/transaction/segment.rb +9 -5
  104. data/lib/new_relic/agent/vm/mri_vm.rb +6 -4
  105. data/lib/new_relic/cli/commands/deployments.rb +0 -1
  106. data/lib/new_relic/constants.rb +4 -0
  107. data/lib/new_relic/control/frameworks/rails.rb +11 -9
  108. data/lib/new_relic/control/instance_methods.rb +1 -0
  109. data/lib/new_relic/dependency_detection.rb +119 -9
  110. data/lib/new_relic/environment_report.rb +1 -7
  111. data/lib/new_relic/noticed_error.rb +1 -5
  112. data/lib/new_relic/supportability_helper.rb +3 -2
  113. data/lib/new_relic/version.rb +2 -2
  114. data/lib/tasks/multiverse.rb +9 -0
  115. data/newrelic_rpm.gemspec +2 -3
  116. data/test/agent_helper.rb +7 -0
  117. metadata +55 -12
  118. data/.travis.yml +0 -240
  119. data/CODE_OF_CONDUCT.md +0 -46
  120. data/cert/cacert.pem +0 -1177
  121. data/lib/new_relic/agent/instrumentation/http.rb +0 -49
  122. data/lib/new_relic/agent/instrumentation/net.rb +0 -87
  123. data/lib/new_relic/metrics.rb +0 -13
@@ -0,0 +1,63 @@
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 Curb
12
+ module Easy
13
+ module Prepend
14
+ include NewRelic::Agent::Instrumentation::Curb::Easy
15
+
16
+ def http_head(*args, &blk)
17
+ http_head_with_tracing { super }
18
+ end
19
+
20
+ def http_post(*args, &blk)
21
+ http_post_with_tracing { super }
22
+ end
23
+
24
+ def http_put(*args, &blk)
25
+ http_put_with_tracing { super }
26
+ end
27
+
28
+ def http verb
29
+ http_with_tracing(verb) { super }
30
+ end
31
+
32
+ def perform
33
+ perform_with_tracing { super }
34
+ end
35
+
36
+ def method verb
37
+ method_with_tracing { super }
38
+ end
39
+
40
+ def header_str
41
+ header_str_with_tracing { super }
42
+ end
43
+ end
44
+ end
45
+
46
+ module Multi
47
+ module Prepend
48
+ include NewRelic::Agent::Instrumentation::Curb::Multi
49
+
50
+ def add(curl)
51
+ add_with_tracing(curl) { super }
52
+ end
53
+
54
+ def perform(&blk)
55
+ perform_with_tracing { super }
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
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
+ require_relative 'instrumentation'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module DelayedJob
9
+ module Chain
10
+ def self.instrument!
11
+ Delayed::Worker.class_eval do
12
+ include NewRelic::Agent::Instrumentation::DelayedJob
13
+
14
+ def initialize_with_new_relic(*args)
15
+ initialize_with_tracing { initialize_without_new_relic(*args) }
16
+ end
17
+
18
+ alias initialize_without_new_relic initialize
19
+ alias initialize initialize_with_new_relic
20
+
21
+
22
+ def install_newrelic_job_tracer
23
+ Delayed::Job.class_eval do
24
+ include NewRelic::Agent::Instrumentation::DelayedJobTracer
25
+
26
+ alias_method :invoke_job_without_new_relic, :invoke_job
27
+
28
+ def invoke_job(*args, &block)
29
+ invoke_job_with_tracing { invoke_job_without_new_relic(*args, &block) }
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,53 @@
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
+
7
+ module NewRelic
8
+ module Agent
9
+ module Instrumentation
10
+ module DelayedJob
11
+
12
+ def initialize_with_tracing
13
+ yield
14
+ worker_name = case
15
+ when self.respond_to?(:name) then self.name
16
+ when self.class.respond_to?(:default_name) then self.class.default_name
17
+ end
18
+ NewRelic::DelayedJobInjection.worker_name = worker_name
19
+
20
+ if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
21
+ !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic) )
22
+
23
+ ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
24
+ install_newrelic_job_tracer
25
+ NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
26
+ else
27
+ NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ module DelayedJobTracer
34
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
35
+
36
+ NR_TRANSACTION_CATEGORY = 'OtherTransaction/DelayedJob'.freeze
37
+
38
+ def invoke_job_with_tracing
39
+ options = {
40
+ :category => NR_TRANSACTION_CATEGORY,
41
+ :path => ::NewRelic::Agent::Instrumentation::DelayedJob::Naming.name_from_payload(payload_object)
42
+ }
43
+
44
+ perform_action_with_newrelic_trace(options) do
45
+ yield
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -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,85 +87,10 @@ DependencyDetection.defer do
88
87
  end
89
88
 
90
89
  executes do
91
- Delayed::Worker.class_eval do
92
-
93
- if RUBY_VERSION < "2.7.0"
94
- def initialize_with_new_relic(*args)
95
- initialize_without_new_relic(*args)
96
- worker_name = case
97
- when self.respond_to?(:name) then self.name
98
- when self.class.respond_to?(:default_name) then self.class.default_name
99
- end
100
- NewRelic::DelayedJobInjection.worker_name = worker_name
101
-
102
- if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
103
- !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic) )
104
-
105
- ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
106
- install_newrelic_job_tracer
107
- NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
108
- else
109
- NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
110
- end
111
- end
112
- else
113
- def initialize_with_new_relic(*args, **kwargs)
114
- initialize_without_new_relic(*args, **kwargs)
115
- worker_name = case
116
- when self.respond_to?(:name) then self.name
117
- when self.class.respond_to?(:default_name) then self.class.default_name
118
- end
119
- NewRelic::DelayedJobInjection.worker_name = worker_name
120
-
121
- if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
122
- !(::Delayed::Job.method_defined?(:invoke_job_without_new_relic) )
123
-
124
- ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
125
- install_newrelic_job_tracer
126
- NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
127
- else
128
- NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
129
- end
130
- end
131
- end
132
-
133
- alias initialize_without_new_relic initialize
134
- alias initialize initialize_with_new_relic
135
-
136
- NR_TRANSACTION_CATEGORY = 'OtherTransaction/DelayedJob'.freeze
137
-
138
- def install_newrelic_job_tracer
139
- Delayed::Job.class_eval do
140
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation
141
-
142
- alias_method :invoke_job_without_new_relic, :invoke_job
143
-
144
- if RUBY_VERSION < "2.7.0"
145
- def invoke_job(*args, &block)
146
- options = {
147
- :category => NR_TRANSACTION_CATEGORY,
148
- :path => ::NewRelic::Agent::Instrumentation::DelayedJob::Naming.name_from_payload(payload_object)
149
- }
150
-
151
- perform_action_with_newrelic_trace(options) do
152
- invoke_job_without_new_relic(*args, &block)
153
- end
154
- end
155
- else
156
- def invoke_job(*args, **kwargs, &block)
157
- options = {
158
- :category => NR_TRANSACTION_CATEGORY,
159
- :path => ::NewRelic::Agent::Instrumentation::DelayedJob::Naming.name_from_payload(payload_object)
160
- }
161
-
162
- perform_action_with_newrelic_trace(options) do
163
- invoke_job_without_new_relic(*args, **kwargs, &block)
164
- end
165
- end
166
- end
167
-
168
- end
169
- 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
170
94
  end
171
95
  end
172
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