newrelic_rpm 9.9.0 → 9.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/.build_ignore +1 -0
  3. data/CHANGELOG.md +463 -1
  4. data/CONTRIBUTING.md +2 -2
  5. data/README.md +16 -17
  6. data/Rakefile +1 -1
  7. data/lib/boot/strap.rb +102 -0
  8. data/lib/new_relic/agent/agent.rb +6 -0
  9. data/lib/new_relic/agent/agent_helpers/connect.rb +3 -0
  10. data/lib/new_relic/agent/agent_helpers/harvest.rb +3 -0
  11. data/lib/new_relic/agent/agent_helpers/shutdown.rb +3 -0
  12. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +1 -0
  13. data/lib/new_relic/agent/agent_helpers/startup.rb +7 -0
  14. data/lib/new_relic/agent/agent_logger.rb +1 -0
  15. data/lib/new_relic/agent/aws.rb +68 -0
  16. data/lib/new_relic/agent/configuration/default_source.rb +603 -105
  17. data/lib/new_relic/agent/configuration/environment_source.rb +5 -1
  18. data/lib/new_relic/agent/configuration/manager.rb +28 -2
  19. data/lib/new_relic/agent/configuration/yaml_source.rb +7 -2
  20. data/lib/new_relic/agent/database/obfuscation_helpers.rb +11 -11
  21. data/lib/new_relic/agent/database/obfuscator.rb +1 -0
  22. data/lib/new_relic/agent/database.rb +41 -1
  23. data/lib/new_relic/agent/database_adapter.rb +1 -1
  24. data/lib/new_relic/agent/datastores/redis.rb +1 -1
  25. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +1 -1
  26. data/lib/new_relic/agent/distributed_tracing.rb +4 -2
  27. data/lib/new_relic/agent/error_collector.rb +37 -10
  28. data/lib/new_relic/agent/external.rb +2 -0
  29. data/lib/new_relic/agent/health_check.rb +136 -0
  30. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/action_dispatch.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/action_mailbox.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/action_mailer.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_job.rb +1 -1
  36. data/lib/new_relic/agent/instrumentation/active_job_subscriber.rb +6 -2
  37. data/lib/new_relic/agent/instrumentation/active_merchant.rb +0 -13
  38. data/lib/new_relic/agent/instrumentation/active_record.rb +7 -12
  39. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +7 -3
  40. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +11 -9
  41. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +2 -2
  42. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +9 -16
  43. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +0 -2
  44. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +0 -2
  45. data/lib/new_relic/agent/instrumentation/async_http.rb +2 -3
  46. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/chain.rb +21 -0
  47. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb +66 -0
  48. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/prepend.rb +15 -0
  49. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose.rb +22 -0
  50. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/chain.rb +21 -0
  51. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb +91 -0
  52. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/prepend.rb +15 -0
  53. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis.rb +22 -0
  54. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/chain.rb +33 -0
  55. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb +93 -0
  56. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/prepend.rb +23 -0
  57. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda.rb +23 -0
  58. data/lib/new_relic/agent/instrumentation/aws_sqs/chain.rb +37 -0
  59. data/lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb +67 -0
  60. data/lib/new_relic/agent/instrumentation/aws_sqs/prepend.rb +21 -0
  61. data/lib/new_relic/agent/instrumentation/aws_sqs.rb +23 -0
  62. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +14 -0
  63. data/lib/new_relic/agent/instrumentation/bunny.rb +3 -4
  64. data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +1 -3
  65. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -0
  66. data/lib/new_relic/agent/instrumentation/curb.rb +4 -5
  67. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +0 -23
  68. data/lib/new_relic/agent/instrumentation/dynamodb/chain.rb +27 -0
  69. data/lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb +64 -0
  70. data/lib/new_relic/agent/instrumentation/dynamodb/prepend.rb +19 -0
  71. data/lib/new_relic/agent/instrumentation/dynamodb.rb +23 -0
  72. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +1 -2
  73. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +53 -7
  74. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +1 -3
  75. data/lib/new_relic/agent/instrumentation/ethon.rb +1 -5
  76. data/lib/new_relic/agent/instrumentation/excon.rb +1 -17
  77. data/lib/new_relic/agent/instrumentation/fiber/chain.rb +1 -1
  78. data/lib/new_relic/agent/instrumentation/fiber/prepend.rb +1 -1
  79. data/lib/new_relic/agent/instrumentation/fiber.rb +0 -2
  80. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +0 -3
  81. data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
  82. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +0 -1
  83. data/lib/new_relic/agent/instrumentation/httpclient.rb +1 -5
  84. data/lib/new_relic/agent/instrumentation/httprb.rb +0 -1
  85. data/lib/new_relic/agent/instrumentation/httpx/instrumentation.rb +1 -1
  86. data/lib/new_relic/agent/instrumentation/httpx.rb +1 -5
  87. data/lib/new_relic/agent/instrumentation/logger.rb +1 -3
  88. data/lib/new_relic/agent/instrumentation/logstasher/chain.rb +21 -0
  89. data/lib/new_relic/agent/instrumentation/logstasher/instrumentation.rb +24 -0
  90. data/lib/new_relic/agent/instrumentation/logstasher/prepend.rb +13 -0
  91. data/lib/new_relic/agent/instrumentation/logstasher.rb +25 -0
  92. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +1 -1
  93. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +2 -2
  94. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +1 -1
  95. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +1 -1
  96. data/lib/new_relic/agent/instrumentation/memcache.rb +0 -1
  97. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +1 -1
  98. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +3 -3
  99. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -1
  100. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +0 -2
  101. data/lib/new_relic/agent/instrumentation/opensearch/chain.rb +21 -0
  102. data/lib/new_relic/agent/instrumentation/opensearch/instrumentation.rb +66 -0
  103. data/lib/{tasks/instrumentation_generator/templates/instrumentation.tt → new_relic/agent/instrumentation/opensearch/prepend.rb} +4 -4
  104. data/lib/new_relic/agent/instrumentation/opensearch.rb +23 -0
  105. data/lib/new_relic/agent/instrumentation/padrino.rb +3 -3
  106. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +3 -0
  107. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +9 -5
  108. data/lib/new_relic/agent/instrumentation/rake.rb +1 -2
  109. data/lib/new_relic/agent/instrumentation/rdkafka/chain.rb +72 -0
  110. data/lib/new_relic/agent/instrumentation/rdkafka/instrumentation.rb +70 -0
  111. data/lib/new_relic/agent/instrumentation/rdkafka/prepend.rb +67 -0
  112. data/lib/new_relic/agent/instrumentation/rdkafka.rb +25 -0
  113. data/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb +26 -0
  114. data/lib/new_relic/agent/instrumentation/redis/constants.rb +2 -2
  115. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +14 -11
  116. data/lib/new_relic/agent/instrumentation/redis/middleware.rb +3 -0
  117. data/lib/new_relic/agent/instrumentation/redis.rb +11 -5
  118. data/lib/new_relic/agent/instrumentation/resque.rb +8 -6
  119. data/lib/new_relic/agent/instrumentation/roda.rb +5 -5
  120. data/lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb +55 -0
  121. data/lib/new_relic/agent/instrumentation/ruby_kafka/instrumentation.rb +67 -0
  122. data/lib/new_relic/agent/instrumentation/ruby_kafka/prepend.rb +60 -0
  123. data/lib/new_relic/agent/instrumentation/ruby_kafka.rb +25 -0
  124. data/lib/new_relic/agent/instrumentation/ruby_openai.rb +2 -2
  125. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delay_extensions.rb +24 -0
  126. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +2 -2
  127. data/lib/new_relic/agent/instrumentation/sidekiq.rb +9 -15
  128. data/lib/new_relic/agent/instrumentation/sinatra.rb +3 -19
  129. data/lib/new_relic/agent/instrumentation/stripe.rb +1 -1
  130. data/lib/new_relic/agent/instrumentation/stripe_subscriber.rb +22 -1
  131. data/lib/new_relic/agent/instrumentation/thread.rb +0 -2
  132. data/lib/new_relic/agent/instrumentation/tilt.rb +0 -4
  133. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +2 -2
  134. data/lib/new_relic/agent/instrumentation/typhoeus.rb +0 -1
  135. data/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb +11 -5
  136. data/lib/new_relic/agent/instrumentation/view_component.rb +0 -2
  137. data/lib/new_relic/agent/javascript_instrumentor.rb +2 -3
  138. data/lib/new_relic/agent/llm/chat_completion_summary.rb +1 -1
  139. data/lib/new_relic/agent/llm/embedding.rb +1 -1
  140. data/lib/new_relic/agent/local_log_decorator.rb +20 -3
  141. data/lib/new_relic/agent/log_event_aggregator.rb +119 -28
  142. data/lib/new_relic/agent/logging.rb +1 -1
  143. data/lib/new_relic/agent/messaging.rb +16 -5
  144. data/lib/new_relic/agent/method_tracer.rb +3 -0
  145. data/lib/new_relic/agent/monitors/inbound_request_monitor.rb +1 -1
  146. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +1 -1
  147. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +2 -2
  148. data/lib/new_relic/agent/new_relic_service.rb +8 -2
  149. data/lib/new_relic/agent/opentelemetry/context/propagation/trace_propagator.rb +66 -0
  150. data/lib/new_relic/agent/opentelemetry/context/propagation.rb +15 -0
  151. data/lib/{tasks/instrumentation_generator/templates/Envfile.tt → new_relic/agent/opentelemetry/context.rb} +9 -5
  152. data/lib/new_relic/agent/opentelemetry/trace/span.rb +31 -0
  153. data/lib/new_relic/agent/opentelemetry/trace/tracer.rb +129 -0
  154. data/lib/new_relic/agent/opentelemetry/trace/tracer_provider.rb +18 -0
  155. data/lib/new_relic/agent/opentelemetry/trace.rb +15 -0
  156. data/lib/new_relic/agent/opentelemetry/transaction_patch.rb +69 -0
  157. data/lib/new_relic/agent/opentelemetry_bridge.rb +32 -0
  158. data/lib/new_relic/agent/parameter_filtering.rb +1 -1
  159. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  160. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  161. data/lib/new_relic/agent/serverless_handler.rb +247 -12
  162. data/lib/new_relic/agent/serverless_handler_event_sources.json +155 -0
  163. data/lib/new_relic/agent/serverless_handler_event_sources.rb +49 -0
  164. data/lib/new_relic/agent/span_event_primitive.rb +16 -11
  165. data/lib/new_relic/agent/system_info.rb +14 -0
  166. data/lib/new_relic/agent/threading/backtrace_node.rb +10 -1
  167. data/lib/new_relic/agent/tracer.rb +1 -1
  168. data/lib/new_relic/agent/transaction/abstract_segment.rb +2 -1
  169. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  170. data/lib/new_relic/agent/transaction/distributed_tracer.rb +3 -3
  171. data/lib/new_relic/agent/transaction/external_request_segment.rb +0 -10
  172. data/lib/new_relic/agent/transaction/message_broker_segment.rb +4 -1
  173. data/lib/new_relic/agent/transaction/request_attributes.rb +14 -7
  174. data/lib/new_relic/agent/transaction/trace_context.rb +34 -5
  175. data/lib/new_relic/agent/transaction/tracing.rb +3 -3
  176. data/lib/new_relic/agent/transaction.rb +4 -7
  177. data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -1
  178. data/lib/new_relic/agent/utilization/ecs.rb +22 -0
  179. data/lib/new_relic/agent/utilization/ecs_v4.rb +22 -0
  180. data/lib/new_relic/agent/utilization_data.rb +40 -5
  181. data/lib/new_relic/agent/vm/c_ruby_vm.rb +3 -3
  182. data/lib/new_relic/agent.rb +124 -2
  183. data/lib/new_relic/constants.rb +1 -0
  184. data/lib/new_relic/control/frameworks/grape.rb +14 -0
  185. data/lib/new_relic/control/frameworks/padrino.rb +14 -0
  186. data/lib/new_relic/control/frameworks/rails4.rb +1 -3
  187. data/lib/new_relic/control/instance_methods.rb +6 -0
  188. data/lib/new_relic/control/instrumentation.rb +1 -1
  189. data/lib/new_relic/control/private_instance_methods.rb +4 -0
  190. data/lib/new_relic/control/security_interface.rb +57 -0
  191. data/lib/new_relic/control.rb +1 -1
  192. data/lib/new_relic/dependency_detection.rb +11 -14
  193. data/lib/new_relic/environment_report.rb +2 -2
  194. data/lib/new_relic/helper.rb +22 -0
  195. data/lib/new_relic/language_support.rb +3 -1
  196. data/lib/new_relic/local_environment.rb +1 -4
  197. data/lib/new_relic/rack/browser_monitoring.rb +20 -8
  198. data/lib/new_relic/version.rb +1 -1
  199. data/lib/sequel/extensions/new_relic_instrumentation.rb +3 -2
  200. data/lib/tasks/config.rake +7 -3
  201. data/lib/tasks/gha.rake +31 -0
  202. data/lib/tasks/helpers/config.html.erb +3 -2
  203. data/lib/tasks/helpers/format.rb +1 -1
  204. data/lib/tasks/helpers/newrelicyml.rb +80 -13
  205. data/newrelic.yml +425 -162
  206. data/newrelic_rpm.gemspec +3 -1
  207. data/test/agent_helper.rb +24 -2
  208. metadata +91 -22
  209. data/lib/tasks/instrumentation_generator/README.md +0 -63
  210. data/lib/tasks/instrumentation_generator/TODO.md +0 -33
  211. data/lib/tasks/instrumentation_generator/instrumentation.thor +0 -121
  212. data/lib/tasks/instrumentation_generator/templates/chain.tt +0 -21
  213. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +0 -7
  214. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +0 -29
  215. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +0 -3
  216. data/lib/tasks/instrumentation_generator/templates/newrelic.yml.tt +0 -19
  217. data/lib/tasks/instrumentation_generator/templates/prepend.tt +0 -13
  218. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +0 -3
  219. data/lib/tasks/instrumentation_generator/templates/test.tt +0 -15
@@ -0,0 +1,23 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ require_relative 'instrumentation'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module AwsSdkLambda::Prepend
9
+ include NewRelic::Agent::Instrumentation::AwsSdkLambda
10
+
11
+ def invoke(*args)
12
+ invoke_with_new_relic(*args) { super }
13
+ end
14
+
15
+ def invoke_async(*args)
16
+ invoke_async_with_new_relic(*args) { super }
17
+ end
18
+
19
+ def invoke_with_response_stream(*args)
20
+ invoke_with_response_stream_with_new_relic(*args) { super }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ DependencyDetection.defer do
6
+ named :aws_sdk_lambda
7
+
8
+ depends_on do
9
+ defined?(Aws::Lambda::Client)
10
+ end
11
+
12
+ executes do
13
+ require_relative 'aws_sdk_lambda/instrumentation'
14
+
15
+ if use_prepend?
16
+ require_relative 'aws_sdk_lambda/prepend'
17
+ prepend_instrument Aws::Lambda::Client, NewRelic::Agent::Instrumentation::AwsSdkLambda::Prepend
18
+ else
19
+ require_relative 'aws_sdk_lambda/chain'
20
+ chain_instrument NewRelic::Agent::Instrumentation::AwsSdkLambda::Chain
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module AwsSqs::Chain
7
+ def self.instrument!
8
+ ::Aws::SQS::Client.class_eval do
9
+ include NewRelic::Agent::Instrumentation::AwsSqs
10
+
11
+ alias_method(:send_message_without_new_relic, :send_message)
12
+
13
+ def send_message(*args)
14
+ send_message_with_new_relic(*args) do
15
+ send_message_without_new_relic(*args)
16
+ end
17
+ end
18
+
19
+ alias_method(:send_message_batch_without_new_relic, :send_message_batch)
20
+
21
+ def send_message_batch(*args)
22
+ send_message_batch_with_new_relic(*args) do
23
+ send_message_batch_without_new_relic(*args)
24
+ end
25
+ end
26
+
27
+ alias_method(:receive_message_without_new_relic, :receive_message)
28
+
29
+ def receive_message(*args)
30
+ receive_message_with_new_relic(*args) do
31
+ receive_message_without_new_relic(*args)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,67 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module AwsSqs
7
+ MESSAGING_LIBRARY = 'SQS'
8
+
9
+ def send_message_with_new_relic(*args)
10
+ with_tracing(:produce, args) do
11
+ yield
12
+ end
13
+ end
14
+
15
+ def send_message_batch_with_new_relic(*args)
16
+ with_tracing(:produce, args) do
17
+ yield
18
+ end
19
+ end
20
+
21
+ def receive_message_with_new_relic(*args)
22
+ with_tracing(:consume, args) do
23
+ yield
24
+ end
25
+ end
26
+
27
+ def with_tracing(action, params)
28
+ segment = nil
29
+ begin
30
+ info = get_url_info(params[0])
31
+ segment = NewRelic::Agent::Tracer.start_message_broker_segment(
32
+ action: action,
33
+ library: MESSAGING_LIBRARY,
34
+ destination_type: :queue,
35
+ destination_name: info[:queue_name]
36
+ )
37
+ add_aws_attributes(segment, info)
38
+ rescue => e
39
+ NewRelic::Agent.logger.error('Error starting message broker segment in Aws::SQS::Client', e)
40
+ end
41
+ NewRelic::Agent::Tracer.capture_segment_error(segment) do
42
+ yield
43
+ end
44
+ ensure
45
+ segment&.finish
46
+ end
47
+
48
+ private
49
+
50
+ def add_aws_attributes(segment, info)
51
+ return unless segment
52
+
53
+ segment.add_agent_attribute('messaging.system', 'aws_sqs')
54
+ segment.add_agent_attribute('cloud.region', config&.region)
55
+ segment.add_agent_attribute('cloud.account.id', info[:account_id])
56
+ segment.add_agent_attribute('messaging.destination.name', info[:queue_name])
57
+ end
58
+
59
+ def get_url_info(params)
60
+ split = params[:queue_url].split('/')
61
+ {
62
+ queue_name: split.last,
63
+ account_id: split[-2]
64
+ }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,21 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module AwsSqs::Prepend
7
+ include NewRelic::Agent::Instrumentation::AwsSqs
8
+
9
+ def send_message(*args)
10
+ send_message_with_new_relic(*args) { super }
11
+ end
12
+
13
+ def send_message_batch(*args)
14
+ send_message_batch_with_new_relic(*args) { super }
15
+ end
16
+
17
+ def receive_message(*args)
18
+ receive_message_with_new_relic(*args) { super }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ require_relative 'aws_sqs/instrumentation'
6
+ require_relative 'aws_sqs/chain'
7
+ require_relative 'aws_sqs/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :aws_sqs
11
+
12
+ depends_on do
13
+ defined?(Aws::SQS::Client)
14
+ end
15
+
16
+ executes do
17
+ if use_prepend?
18
+ prepend_instrument Aws::SQS::Client, NewRelic::Agent::Instrumentation::AwsSqs::Prepend
19
+ else
20
+ chain_instrument NewRelic::Agent::Instrumentation::AwsSqs::Chain
21
+ end
22
+ end
23
+ end
@@ -48,6 +48,12 @@ module NewRelic
48
48
  correlation_id: opts[:correlation_id],
49
49
  exchange_type: type
50
50
  )
51
+ if segment
52
+ segment.add_agent_attribute('server.address', channel&.connection&.hostname)
53
+ segment.add_agent_attribute('server.port', channel&.connection&.port)
54
+ segment.add_agent_attribute('messaging.destination.name', destination) # for produce, this is exchange name
55
+ segment.add_agent_attribute('messaging.rabbitmq.destination.routing_key', opts[:routing_key])
56
+ end
51
57
  rescue => e
52
58
  NewRelic::Agent.logger.error('Error starting message broker segment in Bunny::Exchange#publish', e)
53
59
  yield
@@ -94,6 +100,14 @@ module NewRelic
94
100
  queue_name: name,
95
101
  start_time: t0
96
102
  )
103
+ if segment
104
+ segment.add_agent_attribute('server.address', channel&.connection&.hostname)
105
+ segment.add_agent_attribute('server.port', channel&.connection&.port)
106
+ segment.add_agent_attribute('messaging.destination.name', name) # for consume, this is queue name
107
+ segment.add_agent_attribute('messaging.destination_publish.name', exch_name)
108
+ segment.add_agent_attribute('message.queueName', name)
109
+ segment.add_agent_attribute('messaging.rabbitmq.destination.routing_key', delivery_info&.routing_key)
110
+ end
97
111
  rescue => e
98
112
  NewRelic::Agent.logger.error('Error starting message broker segment in Bunny::Queue#pop', e)
99
113
  else
@@ -14,7 +14,6 @@ DependencyDetection.defer do
14
14
  end
15
15
 
16
16
  executes do
17
- NewRelic::Agent.logger.info('Installing Bunny instrumentation')
18
17
  require 'new_relic/agent/distributed_tracing/cross_app_tracing'
19
18
  require 'new_relic/agent/messaging'
20
19
  require 'new_relic/agent/transaction/message_broker_segment'
@@ -22,9 +21,9 @@ DependencyDetection.defer do
22
21
 
23
22
  executes do
24
23
  if use_prepend?
25
- prepend_instrument Bunny::Exchange, NewRelic::Agent::Instrumentation::Bunny::Prepend::Exchange
26
- prepend_instrument Bunny::Queue, NewRelic::Agent::Instrumentation::Bunny::Prepend::Queue
27
- prepend_instrument Bunny::Consumer, NewRelic::Agent::Instrumentation::Bunny::Prepend::Consumer
24
+ prepend_instrument Bunny::Exchange, NewRelic::Agent::Instrumentation::Bunny::Prepend::Exchange, 'Bunny::Exchange'
25
+ prepend_instrument Bunny::Queue, NewRelic::Agent::Instrumentation::Bunny::Prepend::Queue, 'Bunny::Queue'
26
+ prepend_instrument Bunny::Consumer, NewRelic::Agent::Instrumentation::Bunny::Prepend::Consumer, 'Bunny::Consumer'
28
27
  else
29
28
  chain_instrument NewRelic::Agent::Instrumentation::Bunny::Chain
30
29
  end
@@ -12,12 +12,10 @@ DependencyDetection.defer do
12
12
  depends_on do
13
13
  defined?(Concurrent) &&
14
14
  defined?(Concurrent::VERSION) &&
15
- Gem::Version.new(Concurrent::VERSION) >= Gem::Version.new('1.1.5')
15
+ NewRelic::Helper.version_satisfied?(Concurrent::VERSION, '>=', '1.1.5')
16
16
  end
17
17
 
18
18
  executes do
19
- NewRelic::Agent.logger.info('Installing concurrent-ruby instrumentation')
20
-
21
19
  if use_prepend?
22
20
  prepend_instrument(Concurrent::ThreadPoolExecutor, NewRelic::Agent::Instrumentation::ConcurrentRuby::Prepend)
23
21
 
@@ -54,6 +54,7 @@ module NewRelic
54
54
  # Have NewRelic ignore actions in this controller. Specify the actions as hash options
55
55
  # using :except and :only. If no actions are specified, all actions are ignored.
56
56
  #
57
+ # @!scope class
57
58
  # @api public
58
59
  #
59
60
  def newrelic_ignore(specifiers = {})
@@ -65,6 +66,7 @@ module NewRelic
65
66
  # actions that are not user facing or that skew your overall apdex measurement.
66
67
  # Accepts :except and :only options, as with #newrelic_ignore.
67
68
  #
69
+ # @!scope class
68
70
  # @api public
69
71
  #
70
72
  def newrelic_ignore_apdex(specifiers = {})
@@ -72,6 +74,7 @@ module NewRelic
72
74
  newrelic_ignore_aspect(NR_IGNORE_APDEX_KEY, specifiers)
73
75
  end
74
76
 
77
+ # @!scope class
75
78
  # @api public
76
79
  def newrelic_ignore_enduser(specifiers = {})
77
80
  NewRelic::Agent.record_api_supportability_metric(:newrelic_ignore_enduser)
@@ -159,6 +162,7 @@ module NewRelic
159
162
  # See NewRelic::Agent::Instrumentation::ControllerInstrumentation#perform_action_with_newrelic_trace
160
163
  # for the full list of available options.
161
164
  #
165
+ # @!scope class
162
166
  # @api public
163
167
  #
164
168
  def add_transaction_tracer(method, options = {})
@@ -12,21 +12,20 @@ DependencyDetection.defer do
12
12
 
13
13
  depends_on do
14
14
  defined?(Curl) && defined?(Curl::CURB_VERSION) &&
15
- Gem::Version.new(Curl::CURB_VERSION) >= CURB_MIN_VERSION
15
+ NewRelic::Helper.version_satisfied?(Curl::CURB_VERSION, '>=', CURB_MIN_VERSION)
16
16
  end
17
17
 
18
18
  executes do
19
- NewRelic::Agent.logger.info('Installing Curb instrumentation')
20
19
  require 'new_relic/agent/distributed_tracing/cross_app_tracing'
21
20
  require 'new_relic/agent/http_clients/curb_wrappers'
22
21
  end
23
22
 
24
23
  executes do
25
24
  if use_prepend?
26
- prepend_instrument Curl::Easy, NewRelic::Agent::Instrumentation::Curb::Easy::Prepend
27
- prepend_instrument Curl::Multi, NewRelic::Agent::Instrumentation::Curb::Multi::Prepend
25
+ prepend_instrument Curl::Easy, NewRelic::Agent::Instrumentation::Curb::Easy::Prepend, 'Curb::Easy'
26
+ prepend_instrument Curl::Multi, NewRelic::Agent::Instrumentation::Curb::Multi::Prepend, 'Curb::Multi'
28
27
  else
29
- chain_instrument NewRelic::Agent::Instrumentation::Curb::Chain
28
+ chain_instrument NewRelic::Agent::Instrumentation::Curb::Chain, NewRelic::Agent::Instrumentation::Curb::Multi::INSTRUMENTATION_NAME
30
29
  end
31
30
  end
32
31
  end
@@ -82,10 +82,6 @@ DependencyDetection.defer do
82
82
  defined?(Delayed) && defined?(Delayed::Worker)
83
83
  end
84
84
 
85
- executes do
86
- NewRelic::Agent.logger.info('Installing DelayedJob instrumentation [part 1/2]')
87
- end
88
-
89
85
  executes do
90
86
  if use_prepend?
91
87
  prepend_instrument Delayed::Worker, NewRelic::Agent::Instrumentation::DelayedJob::Prepend
@@ -93,23 +89,4 @@ DependencyDetection.defer do
93
89
  chain_instrument NewRelic::Agent::Instrumentation::DelayedJob::Chain
94
90
  end
95
91
  end
96
-
97
- executes do
98
- next unless delayed_job_version < Gem::Version.new('4.1.0')
99
-
100
- deprecation_msg = 'Instrumentation for DelayedJob versions below 4.1.0 is deprecated.' \
101
- 'It will stop being monitored in version 9.0.0. ' \
102
- 'Please upgrade your DelayedJob version to continue receiving full support. ' \
103
-
104
- NewRelic::Agent.logger.log_once(
105
- :warn,
106
- :deprecated_delayed_job_version,
107
- deprecation_msg
108
- )
109
- end
110
-
111
- def delayed_job_version
112
- # the following line needs else branch coverage
113
- Gem.loaded_specs['delayed_job'].version if Gem.loaded_specs['delayed_job'] # rubocop:disable Style/SafeNavigation
114
- end
115
92
  end
@@ -0,0 +1,27 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module DynamoDB::Chain
7
+ def self.instrument!
8
+ ::Aws::DynamoDB::Client.class_eval do
9
+ include NewRelic::Agent::Instrumentation::DynamoDB
10
+
11
+ NewRelic::Agent::Instrumentation::DynamoDB::INSTRUMENTED_METHODS.each do |method_name|
12
+ alias_method("#{method_name}_without_new_relic".to_sym, method_name.to_sym)
13
+
14
+ define_method(method_name) do |*args|
15
+ instrument_method_with_new_relic(method_name, *args) { send("#{method_name}_without_new_relic".to_sym, *args) }
16
+ end
17
+ end
18
+
19
+ alias_method(:build_request_without_new_relic, :build_request)
20
+
21
+ def build_request(*args)
22
+ build_request_with_new_relic(*args) { build_request_without_new_relic(*args) }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module DynamoDB
7
+ INSTRUMENTED_METHODS = %w[
8
+ create_table
9
+ delete_item
10
+ delete_table
11
+ get_item
12
+ put_item
13
+ query
14
+ scan
15
+ update_item
16
+ ].freeze
17
+
18
+ PRODUCT = 'DynamoDB'
19
+ DEFAULT_HOST = 'dynamodb.amazonaws.com'
20
+
21
+ def instrument_method_with_new_relic(method_name, *args)
22
+ return yield unless NewRelic::Agent::Tracer.tracing_enabled?
23
+
24
+ NewRelic::Agent.record_instrumentation_invocation(PRODUCT)
25
+
26
+ segment = NewRelic::Agent::Tracer.start_datastore_segment(
27
+ product: PRODUCT,
28
+ operation: method_name,
29
+ host: config&.endpoint&.host || DEFAULT_HOST,
30
+ port_path_or_id: config&.endpoint&.port,
31
+ collection: args[0][:table_name]
32
+ )
33
+
34
+ arn = get_arn(args[0])
35
+ segment&.add_agent_attribute('cloud.resource_id', arn) if arn
36
+
37
+ @nr_captured_request = nil # clear request just in case
38
+ begin
39
+ NewRelic::Agent::Tracer.capture_segment_error(segment) { yield }
40
+ ensure
41
+ segment&.add_agent_attribute('aws.operation', method_name)
42
+ segment&.add_agent_attribute('aws.requestId', @nr_captured_request&.context&.http_response&.headers&.[]('x-amzn-requestid'))
43
+ segment&.add_agent_attribute('aws.region', config&.region)
44
+ segment&.finish
45
+ end
46
+ end
47
+
48
+ def build_request_with_new_relic(*args)
49
+ @nr_captured_request = yield
50
+ end
51
+
52
+ def nr_account_id
53
+ return @nr_account_id if defined?(@nr_account_id)
54
+
55
+ @nr_account_id = NewRelic::Agent::Aws.get_account_id(config)
56
+ end
57
+
58
+ def get_arn(params)
59
+ return unless params[:table_name]
60
+
61
+ NewRelic::Agent::Aws.create_arn(PRODUCT.downcase, "table/#{params[:table_name]}", config&.region, nr_account_id)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module DynamoDB::Prepend
7
+ include NewRelic::Agent::Instrumentation::DynamoDB
8
+
9
+ INSTRUMENTED_METHODS.each do |method_name|
10
+ define_method(method_name) do |*args|
11
+ instrument_method_with_new_relic(method_name, *args) { super(*args) }
12
+ end
13
+ end
14
+
15
+ def build_request(*args)
16
+ build_request_with_new_relic(*args) { super }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ require_relative 'dynamodb/instrumentation'
6
+ require_relative 'dynamodb/chain'
7
+ require_relative 'dynamodb/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :dynamodb
11
+
12
+ depends_on do
13
+ defined?(Aws::DynamoDB::Client)
14
+ end
15
+
16
+ executes do
17
+ if use_prepend?
18
+ prepend_instrument Aws::DynamoDB::Client, NewRelic::Agent::Instrumentation::DynamoDB::Prepend
19
+ else
20
+ chain_instrument NewRelic::Agent::Instrumentation::DynamoDB::Chain
21
+ end
22
+ end
23
+ end
@@ -5,8 +5,7 @@
5
5
  module NewRelic::Agent::Instrumentation
6
6
  module Elasticsearch::Chain
7
7
  def self.instrument!
8
- to_instrument = if ::Gem::Version.create(::Elasticsearch::VERSION) <
9
- ::Gem::Version.create('8.0.0')
8
+ to_instrument = if NewRelic::Helper.version_satisfied?(::Elasticsearch::VERSION, '<', '8.0.0')
10
9
  ::Elasticsearch::Transport::Client
11
10
  else
12
11
  ::Elastic::Transport::Client
@@ -8,6 +8,54 @@ module NewRelic::Agent::Instrumentation
8
8
  module Elasticsearch
9
9
  PRODUCT_NAME = 'Elasticsearch'
10
10
  OPERATION = 'perform_request'
11
+
12
+ # Pattern to use with client caller location strings. Look for a location
13
+ # that contains '/lib/elasticsearch/api/' and is NOT followed by the
14
+ # string held in the OPERATION constant
15
+ OPERATION_PATTERN = %r{/lib/elasticsearch/api/(?!.+#{OPERATION})}.freeze
16
+
17
+ # Use the OPERATION_PATTERN pattern to find the appropriate caller location
18
+ # that will contain the client instance method (example: 'search') and
19
+ # return that method name.
20
+ #
21
+ # A Ruby caller location matching the OPERATION_PATTERN will contain an
22
+ # elasticsearch client instance method name (such as "search"), and that
23
+ # method name will be used as the operation name.
24
+ #
25
+ # With Ruby < 3.4 the method name is listed as:
26
+ #
27
+ # `search'
28
+ #
29
+ # with an opening backtick and a closing single tick. And only the
30
+ # method name itself is listed.
31
+ #
32
+ # With Ruby 3.4+ the method name is listed as:
33
+ #
34
+ # 'Elasticsearch::API::Actions#search'
35
+ #
36
+ # with opening and closing single ticks and the class defining the
37
+ # instance method listed.
38
+ #
39
+ # (?:) = ?: prevents capturing
40
+ # (?:`|') = allow ` or '
41
+ # (?:.+#) = allow the class name and '#' prefix to exist but ignore it
42
+ # ([^']+)' = after the opening ` or ', capturing everything up to the
43
+ # closing '. [^']+ = one or more characters that are not '
44
+ #
45
+ # Example Ruby 3.3.1 input:
46
+ #
47
+ # /Users/fallwith/.rubies/ruby-3.3.1/lib/ruby/gems/3.3.0/gems/elasticsearch-api-7.17.10/lib/elasticsearch/api/actions/index.rb:74:in `index'
48
+ #
49
+ # Example Ruby 3.4.0-preview1 input:
50
+ #
51
+ # /Users/fallwith/.rubies/ruby-3.4.0-preview1/lib/ruby/gems/3.4.0+0/gems/elasticsearch-api-7.17.10/lib/elasticsearch/api/actions/index.rb:74:in 'Elasticsearch::API::Actions#index'
52
+ #
53
+ # Example output for both Rubies:
54
+ #
55
+ # index
56
+
57
+ INSTANCE_METHOD_PATTERN = /:in (?:`|')(?:.+#)?([^']+)'\z/.freeze
58
+
11
59
  INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
12
60
 
13
61
  # We need the positional arguments `params` and `body`
@@ -40,13 +88,10 @@ module NewRelic::Agent::Instrumentation
40
88
  private
41
89
 
42
90
  def nr_operation
43
- operation_index = caller_locations.index do |line|
44
- string = line.to_s
45
- string.include?('lib/elasticsearch/api') && !string.include?(OPERATION)
46
- end
47
- return nil unless operation_index
91
+ location = caller_locations.detect { |loc| loc.to_s.match?(OPERATION_PATTERN) }
92
+ return unless location && location.to_s =~ INSTANCE_METHOD_PATTERN
48
93
 
49
- caller_locations[operation_index].to_s.split('`')[-1].gsub(/\W/, '')
94
+ Regexp.last_match(1)
50
95
  end
51
96
 
52
97
  def nr_reported_query(query)
@@ -57,7 +102,8 @@ module NewRelic::Agent::Instrumentation
57
102
  end
58
103
 
59
104
  def nr_cluster_name
60
- return @nr_cluster_name if @nr_cluster_name
105
+ return unless NewRelic::Agent.config[:'elasticsearch.capture_cluster_name']
106
+ return @nr_cluster_name if defined?(@nr_cluster_name)
61
107
  return if nr_hosts.empty?
62
108
 
63
109
  NewRelic::Agent.disable_all_tracing do
@@ -14,9 +14,7 @@ DependencyDetection.defer do
14
14
  end
15
15
 
16
16
  executes do
17
- NewRelic::Agent.logger.info('Installing Elasticsearch instrumentation')
18
-
19
- to_instrument = if Gem::Version.create(Elasticsearch::VERSION) < Gem::Version.create('8.0.0')
17
+ to_instrument = if NewRelic::Helper.version_satisfied?(Elasticsearch::VERSION, '<', '8.0.0')
20
18
  Elasticsearch::Transport::Client
21
19
  else
22
20
  Elastic::Transport::Client
@@ -18,11 +18,7 @@ DependencyDetection.defer do
18
18
  end
19
19
 
20
20
  depends_on do
21
- defined?(Ethon) && Gem::Version.new(Ethon::VERSION) >= Gem::Version.new('0.12.0')
22
- end
23
-
24
- executes do
25
- NewRelic::Agent.logger.info('Installing ethon instrumentation')
21
+ defined?(Ethon) && NewRelic::Helper.version_satisfied?(Ethon::VERSION, '>=', '0.12.0')
26
22
  end
27
23
 
28
24
  executes do
@@ -26,29 +26,13 @@ DependencyDetection.defer do
26
26
 
27
27
  executes do
28
28
  excon_version = Gem::Version.new(Excon::VERSION)
29
- if excon_version >= EXCON_MIN_VERSION
29
+ if NewRelic::Helper.version_satisfied?(excon_version, '>=', EXCON_MIN_VERSION)
30
30
  install_excon_instrumentation(excon_version)
31
31
  else
32
32
  NewRelic::Agent.logger.warn("Excon instrumentation requires at least version #{EXCON_MIN_VERSION}")
33
33
  end
34
34
  end
35
35
 
36
- executes do
37
- next unless Gem::Version.new(Excon::VERSION) < Gem::Version.new('0.56.0')
38
-
39
- deprecation_msg = 'Instrumentation for Excon versions below 0.56.0 is deprecated.' \
40
- 'They will stop being monitored in version 9.0.0. ' \
41
- 'Please upgrade your Excon version to continue receiving full support. '
42
-
43
- NewRelic::Agent.logger.log_once(
44
- :warn,
45
- :deprecated_excon_version,
46
- deprecation_msg
47
- )
48
-
49
- NewRelic::Agent.record_metric('Supportability/Deprecated/Excon', 1)
50
- end
51
-
52
36
  def install_excon_instrumentation(excon_version)
53
37
  require 'new_relic/agent/distributed_tracing/cross_app_tracing'
54
38
  require 'new_relic/agent/http_clients/excon_wrappers'
@@ -10,7 +10,7 @@ module NewRelic::Agent::Instrumentation
10
10
 
11
11
  alias_method(:initialize_without_new_relic, :initialize)
12
12
 
13
- if RUBY_VERSION < '2.7.0'
13
+ if NewRelic::Helper.version_satisfied?(RUBY_VERSION, '<', '2.7.0')
14
14
  def initialize(*_args, &block)
15
15
  traced_block = add_thread_tracing(&block)
16
16
  initialize_with_newrelic_tracing { initialize_without_new_relic(&traced_block) }
@@ -9,7 +9,7 @@ module NewRelic::Agent::Instrumentation
9
9
  module Prepend
10
10
  include NewRelic::Agent::Instrumentation::MonitoredFiber
11
11
 
12
- if RUBY_VERSION < '2.7.0'
12
+ if NewRelic::Helper.version_satisfied?(RUBY_VERSION, '<', '2.7.0')
13
13
  def initialize(*_args, &block)
14
14
  traced_block = add_thread_tracing(&block)
15
15
  initialize_with_newrelic_tracing { super(&traced_block) }