newrelic_rpm 6.13.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +231 -0
  4. data/CONTRIBUTING.md +13 -2
  5. data/README.md +2 -2
  6. data/lib/new_relic/agent.rb +5 -8
  7. data/lib/new_relic/agent/agent.rb +4 -5
  8. data/lib/new_relic/agent/audit_logger.rb +10 -0
  9. data/lib/new_relic/agent/autostart.rb +1 -2
  10. data/lib/new_relic/agent/configuration/default_source.rb +412 -220
  11. data/lib/new_relic/agent/configuration/manager.rb +2 -2
  12. data/lib/new_relic/agent/database_adapter.rb +33 -0
  13. data/lib/new_relic/agent/datastores/redis.rb +0 -4
  14. data/lib/new_relic/agent/distributed_tracing.rb +0 -66
  15. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +2 -2
  16. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -1
  17. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -5
  18. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +21 -68
  19. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
  20. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +23 -57
  21. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
  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/controller_instrumentation.rb +1 -0
  28. data/lib/new_relic/agent/instrumentation/curb.rb +9 -259
  29. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  30. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  31. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  32. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  33. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  34. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  35. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -84
  36. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  37. data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
  38. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  39. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  40. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  41. data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
  42. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  43. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  44. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  45. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  46. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  47. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  48. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  49. data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
  50. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  51. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
  52. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  53. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  54. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  55. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -10
  56. data/lib/new_relic/agent/instrumentation/mongo.rb +7 -0
  57. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  58. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  59. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
  60. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  61. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
  62. data/lib/new_relic/agent/instrumentation/padrino.rb +18 -75
  63. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  64. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  65. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  66. data/lib/new_relic/agent/instrumentation/rack.rb +29 -160
  67. data/lib/new_relic/agent/instrumentation/rack/chain.rb +57 -0
  68. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  69. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  70. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +36 -0
  71. data/lib/new_relic/agent/instrumentation/rake.rb +13 -188
  72. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  73. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  74. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  75. data/lib/new_relic/agent/instrumentation/redis.rb +12 -186
  76. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  77. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  78. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  79. data/lib/new_relic/agent/instrumentation/resque.rb +21 -32
  80. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  81. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  82. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
  83. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  84. data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -1
  85. data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -198
  86. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  87. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
  88. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
  89. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  90. data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
  91. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  92. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  93. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  94. data/lib/new_relic/agent/javascript_instrumentor.rb +12 -7
  95. data/lib/new_relic/agent/method_tracer.rb +6 -16
  96. data/lib/new_relic/agent/new_relic_service.rb +16 -13
  97. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  98. data/lib/new_relic/agent/span_event_primitive.rb +10 -8
  99. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  100. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  101. data/lib/new_relic/agent/transaction.rb +1 -4
  102. data/lib/new_relic/agent/transaction/abstract_segment.rb +1 -1
  103. data/lib/new_relic/agent/transaction/distributed_tracer.rb +12 -6
  104. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
  105. data/lib/new_relic/agent/vm/mri_vm.rb +6 -4
  106. data/lib/new_relic/cli/commands/deployments.rb +0 -1
  107. data/lib/new_relic/constants.rb +4 -0
  108. data/lib/new_relic/control/frameworks/rails.rb +11 -9
  109. data/lib/new_relic/control/instance_methods.rb +1 -0
  110. data/lib/new_relic/dependency_detection.rb +119 -9
  111. data/lib/new_relic/environment_report.rb +1 -7
  112. data/lib/new_relic/noticed_error.rb +1 -5
  113. data/lib/new_relic/supportability_helper.rb +3 -2
  114. data/lib/new_relic/version.rb +2 -2
  115. data/lib/tasks/config.html.erb +14 -25
  116. data/lib/tasks/config.rake +8 -7
  117. data/newrelic_rpm.gemspec +2 -2
  118. data/test/agent_helper.rb +1 -0
  119. metadata +55 -32
  120. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  121. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  122. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
  123. data/.github/actions/annotate/README.md +0 -79
  124. data/.github/actions/annotate/action.yml +0 -6
  125. data/.github/actions/annotate/dist/index.js +0 -433
  126. data/.github/actions/annotate/index.js +0 -25
  127. data/.github/actions/annotate/package-lock.json +0 -172
  128. data/.github/actions/annotate/package.json +0 -30
  129. data/.github/actions/annotate/pre-commit +0 -5
  130. data/.github/actions/build-ruby/README.md +0 -79
  131. data/.github/actions/build-ruby/action.yml +0 -15
  132. data/.github/actions/build-ruby/dist/index.js +0 -52683
  133. data/.github/actions/build-ruby/index.js +0 -514
  134. data/.github/actions/build-ruby/package-lock.json +0 -581
  135. data/.github/actions/build-ruby/package.json +0 -32
  136. data/.github/actions/build-ruby/pre-commit +0 -5
  137. data/.github/pull_request_template.md +0 -16
  138. data/.github/workflows/ci.yml +0 -212
  139. data/.github/workflows/pr_review_checklist.yml +0 -22
  140. data/.github/workflows/release.yml +0 -78
  141. data/.github/workflows/scripts/rubygems-authenticate.py +0 -13
  142. data/.github/workflows/scripts/rubygems-publish.rb +0 -32
  143. data/.github/workflows/snyk.yml +0 -27
  144. data/.github/workflows/stale.yml +0 -21
  145. data/cert/cacert.pem +0 -1177
  146. data/lib/new_relic/agent/instrumentation/http.rb +0 -49
  147. data/lib/new_relic/agent/instrumentation/net.rb +0 -87
@@ -9,7 +9,6 @@ module NewRelic
9
9
  module ActsAsSolrInstrumentation
10
10
  module ParserMethodsInstrumentation
11
11
 
12
- if RUBY_VERSION < "2.7.0"
13
12
  def parse_query_with_newrelic(*args)
14
13
  self.class.trace_execution_scoped(["SolrClient/ActsAsSolr/query"]) do
15
14
  begin
@@ -20,20 +19,6 @@ module NewRelic
20
19
  end
21
20
  end
22
21
  end
23
-
24
- else
25
- def parse_query_with_newrelic(*args, **kwargs)
26
- self.class.trace_execution_scoped(["SolrClient/ActsAsSolr/query"]) do
27
- begin
28
- parse_query_without_newrelic(*args, **kwargs)
29
- ensure
30
- return unless txn = ::NewRelic::Agent::Tracer.current_transaction
31
- txn.current_segment.params[:statement] = ::NewRelic::Agent::Database.truncate_query(args.first.inspect) rescue nil
32
- end
33
- end
34
- end
35
-
36
- end
37
22
  end
38
23
  end
39
24
  end
@@ -3,6 +3,10 @@
3
3
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
4
  # frozen_string_literal: true
5
5
 
6
+ require_relative 'bunny/instrumentation'
7
+ require_relative 'bunny/chain'
8
+ require_relative 'bunny/prepend'
9
+
6
10
  DependencyDetection.defer do
7
11
  named :bunny
8
12
 
@@ -18,202 +22,12 @@ DependencyDetection.defer do
18
22
  end
19
23
 
20
24
  executes do
21
- module Bunny
22
- class Exchange
23
- alias_method :publish_without_new_relic, :publish
24
-
25
- def publish payload, opts = {}
26
- begin
27
- destination = NewRelic::Agent::Instrumentation::Bunny.exchange_name(name)
28
-
29
- tracing_enabled =
30
- NewRelic::Agent::CrossAppTracing.cross_app_enabled? ||
31
- NewRelic::Agent.config[:'distributed_tracing.enabled']
32
- opts[:headers] ||= {} if tracing_enabled
33
-
34
- segment = NewRelic::Agent::Messaging.start_amqp_publish_segment(
35
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
36
- destination_name: destination,
37
- headers: opts[:headers],
38
- routing_key: opts[:routing_key] || opts[:key],
39
- reply_to: opts[:reply_to],
40
- correlation_id: opts[:correlation_id],
41
- exchange_type: type
42
- )
43
- rescue => e
44
- NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Exchange#publish", e
45
- publish_without_new_relic payload, opts
46
- else
47
- NewRelic::Agent::Tracer.capture_segment_error segment do
48
- publish_without_new_relic payload, opts
49
- end
50
- ensure
51
- segment.finish if segment
52
- end
53
- end
54
- end
55
-
56
- class Queue
57
- alias_method :pop_without_new_relic, :pop
58
-
59
- def pop(opts = {:manual_ack => false}, &block)
60
- bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
61
- begin
62
- t0 = Time.now
63
- msg = pop_without_new_relic opts, &block
64
- delivery_info, message_properties, _payload = msg
65
- rescue StandardError => error
66
- bunny_error = error
67
- end
68
-
69
- begin
70
- exchange_name, exchange_type = if delivery_info
71
- [ NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange),
72
- NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel) ]
73
- else
74
- [ NewRelic::Agent::Instrumentation::Bunny.exchange_name(NewRelic::EMPTY_STR),
75
- NewRelic::Agent::Instrumentation::Bunny.exchange_type({}, channel) ]
76
- end
77
-
78
- segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
79
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
80
- destination_name: exchange_name,
81
- delivery_info: (delivery_info || {}),
82
- message_properties: (message_properties || {headers: {}}),
83
- exchange_type: exchange_type,
84
- queue_name: name,
85
- start_time: t0
86
- )
87
- rescue => e
88
- NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#pop", e
89
- else
90
- if bunny_error
91
- segment.notice_error bunny_error
92
- raise bunny_error
93
- end
94
- ensure
95
- segment.finish if segment
96
- end
97
-
98
- msg
99
- end
100
-
101
- alias_method :purge_without_new_relic, :purge
102
-
103
- if RUBY_VERSION < "2.7.0"
104
- def purge *args
105
- begin
106
- type = server_named? ? :temporary_queue : :queue
107
- segment = NewRelic::Agent::Tracer.start_message_broker_segment(
108
- action: :purge,
109
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
110
- destination_type: type,
111
- destination_name: name
112
- )
113
- rescue => e
114
- NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#purge", e
115
- purge_without_new_relic(*args)
116
- else
117
- NewRelic::Agent::Tracer.capture_segment_error segment do
118
- purge_without_new_relic(*args)
119
- end
120
- ensure
121
- segment.finish if segment
122
- end
123
- end
124
-
125
- else
126
- def purge *args, **kwargs
127
- begin
128
- type = server_named? ? :temporary_queue : :queue
129
- segment = NewRelic::Agent::Tracer.start_message_broker_segment(
130
- action: :purge,
131
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
132
- destination_type: type,
133
- destination_name: name
134
- )
135
- rescue => e
136
- NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#purge", e
137
- purge_without_new_relic(*args, **kwargs)
138
- else
139
- NewRelic::Agent::Tracer.capture_segment_error segment do
140
- purge_without_new_relic(*args, **kwargs)
141
- end
142
- ensure
143
- segment.finish if segment
144
- end
145
- end
146
- end
147
-
148
- end
149
-
150
- class Consumer
151
- alias_method :call_without_new_relic, :call
152
-
153
- if RUBY_VERSION < "2.7.0"
154
- def call *args
155
- delivery_info, message_properties, _ = args
156
- queue_name = queue.respond_to?(:name) ? queue.name : queue
157
-
158
- NewRelic::Agent::Messaging.wrap_amqp_consume_transaction(
159
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
160
- destination_name: NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange),
161
- delivery_info: delivery_info,
162
- message_properties: message_properties,
163
- exchange_type: NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel),
164
- queue_name: queue_name) do
165
-
166
- call_without_new_relic(*args)
167
- end
168
- end
169
- else
170
- def call *args, **kwargs
171
- delivery_info, message_properties, _ = args
172
- queue_name = queue.respond_to?(:name) ? queue.name : queue
173
-
174
- NewRelic::Agent::Messaging.wrap_amqp_consume_transaction(
175
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
176
- destination_name: NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange),
177
- delivery_info: delivery_info,
178
- message_properties: message_properties,
179
- exchange_type: NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel),
180
- queue_name: queue_name) do
181
-
182
- call_without_new_relic(*args, **kwargs)
183
- end
184
- end
185
- end
186
-
187
-
188
-
189
- end
190
- end
191
- end
192
- end
193
-
194
- module NewRelic
195
- module Agent
196
- module Instrumentation
197
- module Bunny
198
- LIBRARY = 'RabbitMQ'
199
- DEFAULT_NAME = 'Default'
200
- DEFAULT_TYPE = :direct
201
-
202
- SLASH = '/'
203
-
204
- class << self
205
- def exchange_name name
206
- name.empty? ? DEFAULT_NAME : name
207
- end
208
-
209
- def exchange_type delivery_info, channel
210
- if di_exchange = delivery_info[:exchange]
211
- return DEFAULT_TYPE if di_exchange.empty?
212
- return channel.exchanges[delivery_info[:exchange]].type if channel.exchanges[di_exchange]
213
- end
214
- end
215
- end
216
- end
25
+ if use_prepend?
26
+ prepend_instrument ::Bunny::Exchange, ::NewRelic::Agent::Instrumentation::Bunny::Prepend::Exchange
27
+ prepend_instrument ::Bunny::Queue, ::NewRelic::Agent::Instrumentation::Bunny::Prepend::Queue
28
+ prepend_instrument ::Bunny::Consumer, ::NewRelic::Agent::Instrumentation::Bunny::Prepend::Consumer
29
+ else
30
+ chain_instrument NewRelic::Agent::Instrumentation::Bunny
217
31
  end
218
32
  end
219
33
  end
@@ -0,0 +1,45 @@
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 Bunny
7
+ def self.instrument!
8
+ ::Bunny::Exchange.class_eval do
9
+ include NewRelic::Agent::Instrumentation::Bunny::Exchange
10
+
11
+ alias_method :publish_without_new_relic, :publish
12
+
13
+ def publish payload, opts = {}
14
+ publish_with_tracing(payload, opts) { publish_without_new_relic payload, opts }
15
+ end
16
+ end
17
+
18
+ ::Bunny::Queue.class_eval do
19
+ include NewRelic::Agent::Instrumentation::Bunny::Queue
20
+
21
+ alias_method :pop_without_new_relic, :pop
22
+
23
+ def pop(opts = {:manual_ack => false}, &block)
24
+ pop_with_tracing { pop_without_new_relic opts, &block }
25
+ end
26
+
27
+ alias_method :purge_without_new_relic, :purge
28
+
29
+ def purge *args
30
+ purge_with_tracing { purge_without_new_relic(*args) }
31
+ end
32
+ end
33
+
34
+ ::Bunny::Consumer.class_eval do
35
+ include NewRelic::Agent::Instrumentation::Bunny::Consumer
36
+
37
+ alias_method :call_without_new_relic, :call
38
+
39
+ def call *args
40
+ call_with_tracing(*args) { call_without_new_relic(*args) }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,152 @@
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
+ module NewRelic
7
+ module Agent
8
+ module Instrumentation
9
+ module Bunny
10
+ module_function
11
+
12
+ LIBRARY = 'RabbitMQ'
13
+ DEFAULT_NAME = 'Default'
14
+ DEFAULT_TYPE = :direct
15
+ SLASH = '/'
16
+
17
+ def exchange_name name
18
+ name.empty? ? DEFAULT_NAME : name
19
+ end
20
+
21
+ def exchange_type delivery_info, channel
22
+ if di_exchange = delivery_info[:exchange]
23
+ return DEFAULT_TYPE if di_exchange.empty?
24
+ return channel.exchanges[delivery_info[:exchange]].type if channel.exchanges[di_exchange]
25
+ end
26
+ end
27
+
28
+ module Exchange
29
+ include Bunny
30
+
31
+ def publish_with_tracing payload, opts = {}
32
+ begin
33
+ destination = exchange_name(name)
34
+
35
+ tracing_enabled =
36
+ NewRelic::Agent::CrossAppTracing.cross_app_enabled? ||
37
+ NewRelic::Agent.config[:'distributed_tracing.enabled']
38
+ opts[:headers] ||= {} if tracing_enabled
39
+
40
+ segment = NewRelic::Agent::Messaging.start_amqp_publish_segment(
41
+ library: LIBRARY,
42
+ destination_name: destination,
43
+ headers: opts[:headers],
44
+ routing_key: opts[:routing_key] || opts[:key],
45
+ reply_to: opts[:reply_to],
46
+ correlation_id: opts[:correlation_id],
47
+ exchange_type: type
48
+ )
49
+ rescue => e
50
+ NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Exchange#publish", e
51
+ yield
52
+ else
53
+ NewRelic::Agent::Tracer.capture_segment_error segment do
54
+ yield
55
+ end
56
+ ensure
57
+ segment.finish if segment
58
+ end
59
+ end
60
+ end
61
+
62
+ module Queue
63
+ include Bunny
64
+
65
+ def pop_with_tracing
66
+ bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
67
+ begin
68
+ t0 = Time.now
69
+ msg = yield
70
+ delivery_info, message_properties, _payload = msg
71
+ rescue StandardError => error
72
+ bunny_error = error
73
+ end
74
+
75
+ begin
76
+ exch_name, exch_type = if delivery_info
77
+ [ exchange_name(delivery_info.exchange),
78
+ exchange_type(delivery_info, channel) ]
79
+ else
80
+ [ exchange_name(NewRelic::EMPTY_STR),
81
+ exchange_type({}, channel) ]
82
+ end
83
+
84
+ segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
85
+ library: LIBRARY,
86
+ destination_name: exch_name,
87
+ delivery_info: (delivery_info || {}),
88
+ message_properties: (message_properties || {headers: {}}),
89
+ exchange_type: exch_type,
90
+ queue_name: name,
91
+ start_time: t0
92
+ )
93
+ rescue => e
94
+ NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#pop", e
95
+ else
96
+ if bunny_error
97
+ segment.notice_error bunny_error
98
+ raise bunny_error
99
+ end
100
+ ensure
101
+ segment.finish if segment
102
+ end
103
+
104
+ msg
105
+ end
106
+
107
+ def purge_with_tracing
108
+ begin
109
+ type = server_named? ? :temporary_queue : :queue
110
+ segment = NewRelic::Agent::Tracer.start_message_broker_segment(
111
+ action: :purge,
112
+ library: LIBRARY,
113
+ destination_type: type,
114
+ destination_name: name
115
+ )
116
+ rescue => e
117
+ NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#purge", e
118
+ yield
119
+ else
120
+ NewRelic::Agent::Tracer.capture_segment_error segment do
121
+ yield
122
+ end
123
+ ensure
124
+ segment.finish if segment
125
+ end
126
+ end
127
+ end
128
+
129
+ module Consumer
130
+ include Bunny
131
+
132
+ def call_with_tracing *args
133
+ delivery_info, message_properties, _ = args
134
+ queue_name = queue.respond_to?(:name) ? queue.name : queue
135
+
136
+ NewRelic::Agent::Messaging.wrap_amqp_consume_transaction(
137
+ library: LIBRARY,
138
+ destination_name: exchange_name(delivery_info.exchange),
139
+ delivery_info: delivery_info,
140
+ message_properties: message_properties,
141
+ exchange_type: exchange_type(delivery_info, channel),
142
+ queue_name: queue_name) do
143
+
144
+ yield
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,35 @@
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 Bunny::Prepend
7
+ module Exchange
8
+ include NewRelic::Agent::Instrumentation::Bunny::Exchange
9
+
10
+ def publish payload, opts = {}
11
+ publish_with_tracing(payload, opts) { super }
12
+ end
13
+ end
14
+
15
+ module Queue
16
+ include NewRelic::Agent::Instrumentation::Bunny::Queue
17
+
18
+ def pop(opts = {:manual_ack => false}, &block)
19
+ pop_with_tracing { super }
20
+ end
21
+
22
+ def purge *args
23
+ purge_with_tracing { super }
24
+ end
25
+ end
26
+
27
+ module Consumer
28
+ include NewRelic::Agent::Instrumentation::Bunny::Consumer
29
+
30
+ def call *args
31
+ call_with_tracing(*args) { super }
32
+ end
33
+ end
34
+ end
35
+ end