newrelic_rpm 8.16.0 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +3 -41
  4. data/.rubocop_todo.yml +13 -14
  5. data/.simplecov +1 -1
  6. data/CHANGELOG.md +184 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +1 -1
  9. data/Guardfile +7 -7
  10. data/README.md +3 -2
  11. data/Rakefile +8 -8
  12. data/Thorfile +1 -1
  13. data/bin/nrdebug +36 -36
  14. data/init.rb +1 -1
  15. data/lib/new_relic/agent/agent.rb +3 -16
  16. data/lib/new_relic/agent/agent_helpers/connect.rb +5 -10
  17. data/lib/new_relic/agent/agent_helpers/harvest.rb +4 -4
  18. data/lib/new_relic/agent/agent_helpers/shutdown.rb +5 -5
  19. data/lib/new_relic/agent/agent_helpers/special_startup.rb +3 -4
  20. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +47 -39
  21. data/lib/new_relic/agent/agent_helpers/startup.rb +13 -13
  22. data/lib/new_relic/agent/agent_helpers/transmit.rb +6 -6
  23. data/lib/new_relic/agent/agent_logger.rb +9 -9
  24. data/lib/new_relic/agent/attribute_filter.rb +2 -4
  25. data/lib/new_relic/agent/attribute_processing.rb +2 -2
  26. data/lib/new_relic/agent/audit_logger.rb +5 -5
  27. data/lib/new_relic/agent/autostart.rb +1 -1
  28. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  29. data/lib/new_relic/agent/commands/agent_command_router.rb +5 -4
  30. data/lib/new_relic/agent/commands/thread_profiler_session.rb +8 -8
  31. data/lib/new_relic/agent/configuration/default_source.rb +155 -530
  32. data/lib/new_relic/agent/configuration/environment_source.rb +2 -2
  33. data/lib/new_relic/agent/configuration/high_security_source.rb +3 -5
  34. data/lib/new_relic/agent/configuration/manager.rb +2 -2
  35. data/lib/new_relic/agent/configuration/security_policy_source.rb +10 -26
  36. data/lib/new_relic/agent/configuration/server_source.rb +24 -24
  37. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -4
  38. data/lib/new_relic/agent/connect/request_builder.rb +1 -1
  39. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  40. data/lib/new_relic/agent/custom_event_aggregator.rb +4 -4
  41. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  42. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  43. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  44. data/lib/new_relic/agent/database.rb +4 -18
  45. data/lib/new_relic/agent/datastores/metric_helper.rb +5 -5
  46. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -11
  47. data/lib/new_relic/agent/datastores/redis.rb +6 -6
  48. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +8 -10
  49. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -10
  50. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +7 -7
  51. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
  52. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +6 -6
  53. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +7 -7
  54. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +4 -4
  55. data/lib/new_relic/agent/distributed_tracing.rb +5 -5
  56. data/lib/new_relic/agent/error_collector.rb +36 -8
  57. data/lib/new_relic/agent/error_filter.rb +5 -5
  58. data/lib/new_relic/agent/error_trace_aggregator.rb +5 -4
  59. data/lib/new_relic/agent/event_loop.rb +3 -3
  60. data/lib/new_relic/agent/external.rb +1 -1
  61. data/lib/new_relic/agent/harvester.rb +1 -3
  62. data/lib/new_relic/agent/heap.rb +2 -1
  63. data/lib/new_relic/agent/hostname.rb +1 -1
  64. data/lib/new_relic/agent/http_clients/abstract.rb +9 -21
  65. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +7 -3
  66. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +7 -5
  67. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +4 -0
  68. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +6 -2
  69. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  70. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +8 -5
  71. data/lib/new_relic/agent/http_clients/uri_util.rb +2 -2
  72. data/lib/new_relic/agent/instrumentation/action_controller_other_subscriber.rb +5 -2
  73. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +3 -2
  74. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +3 -3
  75. data/lib/new_relic/agent/instrumentation/active_job.rb +2 -2
  76. data/lib/new_relic/agent/instrumentation/active_record.rb +3 -2
  77. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +38 -35
  78. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
  79. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +2 -2
  80. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +3 -2
  81. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +3 -3
  82. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +6 -4
  83. data/lib/new_relic/agent/instrumentation/curb/chain.rb +1 -1
  84. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +5 -5
  85. data/lib/new_relic/agent/instrumentation/curb.rb +1 -1
  86. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +2 -1
  87. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +1 -1
  88. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -1
  89. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +1 -1
  90. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +3 -3
  91. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +1 -1
  92. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
  93. data/lib/new_relic/agent/instrumentation/excon.rb +3 -3
  94. data/lib/new_relic/agent/instrumentation/fiber/chain.rb +20 -0
  95. data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +24 -0
  96. data/lib/new_relic/agent/instrumentation/fiber/prepend.rb +18 -0
  97. data/lib/new_relic/agent/instrumentation/fiber.rb +25 -0
  98. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +4 -4
  99. data/lib/new_relic/agent/instrumentation/grape.rb +4 -4
  100. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +2 -1
  101. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +3 -3
  102. data/lib/new_relic/agent/instrumentation/httprb.rb +1 -1
  103. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  104. data/lib/new_relic/agent/instrumentation/logger.rb +1 -1
  105. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +2 -2
  106. data/lib/new_relic/agent/instrumentation/memcache.rb +8 -8
  107. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +3 -3
  108. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +1 -1
  109. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +5 -5
  110. data/lib/new_relic/agent/instrumentation/net_http.rb +2 -2
  111. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +3 -3
  113. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  114. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +1 -1
  115. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -2
  116. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  117. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +8 -15
  118. data/lib/new_relic/agent/instrumentation/rake.rb +3 -3
  119. data/lib/new_relic/agent/instrumentation/redis/constants.rb +1 -1
  120. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +2 -1
  121. data/lib/new_relic/agent/instrumentation/redis.rb +1 -1
  122. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  123. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  124. data/lib/new_relic/agent/instrumentation/sequel.rb +8 -9
  125. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +10 -10
  126. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +1 -1
  127. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +1 -1
  128. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  129. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +6 -5
  130. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  131. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +3 -7
  132. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +2 -1
  133. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +5 -5
  134. data/lib/new_relic/agent/javascript_instrumentor.rb +29 -24
  135. data/lib/new_relic/agent/linking_metadata.rb +2 -2
  136. data/lib/new_relic/agent/log_event_aggregator.rb +15 -15
  137. data/lib/new_relic/agent/logging.rb +73 -33
  138. data/lib/new_relic/agent/messaging.rb +7 -5
  139. data/lib/new_relic/agent/method_tracer.rb +6 -6
  140. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  141. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -5
  142. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -1
  143. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  144. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +2 -2
  145. data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +0 -1
  146. data/lib/new_relic/agent/new_relic_service.rb +15 -15
  147. data/lib/new_relic/agent/obfuscator.rb +1 -1
  148. data/lib/new_relic/agent/parameter_filtering.rb +6 -6
  149. data/lib/new_relic/agent/pipe_channel_manager.rb +7 -6
  150. data/lib/new_relic/agent/pipe_service.rb +5 -3
  151. data/lib/new_relic/agent/priority_sampled_buffer.rb +1 -1
  152. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +0 -1
  153. data/lib/new_relic/agent/sampler.rb +1 -1
  154. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  155. data/lib/new_relic/agent/samplers/cpu_sampler.rb +5 -5
  156. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +9 -9
  157. data/lib/new_relic/agent/samplers/memory_sampler.rb +9 -9
  158. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  159. data/lib/new_relic/agent/span_event_aggregator.rb +4 -4
  160. data/lib/new_relic/agent/span_event_primitive.rb +2 -2
  161. data/lib/new_relic/agent/sql_sampler.rb +2 -2
  162. data/lib/new_relic/agent/stats.rb +1 -1
  163. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  164. data/lib/new_relic/agent/system_info.rb +10 -10
  165. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  166. data/lib/new_relic/agent/threading/backtrace_node.rb +3 -3
  167. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -7
  168. data/lib/new_relic/agent/threading/thread_profile.rb +5 -5
  169. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  170. data/lib/new_relic/agent/tracer.rb +18 -8
  171. data/lib/new_relic/agent/transaction/abstract_segment.rb +9 -9
  172. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  173. data/lib/new_relic/agent/transaction/distributed_tracer.rb +7 -6
  174. data/lib/new_relic/agent/transaction/distributed_tracing.rb +6 -6
  175. data/lib/new_relic/agent/transaction/external_request_segment.rb +11 -11
  176. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -1
  177. data/lib/new_relic/agent/transaction/request_attributes.rb +2 -2
  178. data/lib/new_relic/agent/transaction/segment.rb +1 -1
  179. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  180. data/lib/new_relic/agent/transaction/trace.rb +1 -1
  181. data/lib/new_relic/agent/transaction/trace_context.rb +4 -4
  182. data/lib/new_relic/agent/transaction/trace_node.rb +8 -7
  183. data/lib/new_relic/agent/transaction/tracing.rb +4 -4
  184. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  185. data/lib/new_relic/agent/transaction.rb +56 -52
  186. data/lib/new_relic/agent/transaction_error_primitive.rb +5 -5
  187. data/lib/new_relic/agent/transaction_event_aggregator.rb +4 -4
  188. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -3
  189. data/lib/new_relic/agent/transaction_sampler.rb +3 -3
  190. data/lib/new_relic/agent/transaction_time_aggregator.rb +7 -3
  191. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  192. data/lib/new_relic/agent/utilization/azure.rb +3 -3
  193. data/lib/new_relic/agent/utilization/gcp.rb +3 -3
  194. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  195. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  196. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  197. data/lib/new_relic/agent/vm/mri_vm.rb +9 -8
  198. data/lib/new_relic/agent/worker_loop.rb +1 -1
  199. data/lib/new_relic/agent.rb +79 -35
  200. data/lib/new_relic/cli/command.rb +3 -3
  201. data/lib/new_relic/cli/commands/deployments.rb +26 -25
  202. data/lib/new_relic/cli/commands/install.rb +23 -23
  203. data/lib/new_relic/collection_helper.rb +2 -2
  204. data/lib/new_relic/constants.rb +7 -8
  205. data/lib/new_relic/control/class_methods.rb +3 -3
  206. data/lib/new_relic/control/frameworks/rails.rb +30 -18
  207. data/lib/new_relic/control/instance_methods.rb +6 -6
  208. data/lib/new_relic/control/instrumentation.rb +1 -1
  209. data/lib/new_relic/control/private_instance_methods.rb +1 -1
  210. data/lib/new_relic/dependency_detection.rb +4 -17
  211. data/lib/new_relic/environment_report.rb +4 -4
  212. data/lib/new_relic/helper.rb +2 -1
  213. data/lib/new_relic/language_support.rb +1 -1
  214. data/lib/new_relic/latest_changes.rb +5 -5
  215. data/lib/new_relic/local_environment.rb +0 -10
  216. data/lib/new_relic/noticed_error.rb +20 -18
  217. data/lib/new_relic/rack/browser_monitoring.rb +20 -16
  218. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  219. data/lib/new_relic/recipes/capistrano_legacy.rb +6 -6
  220. data/lib/new_relic/recipes/helpers/send_deployment.rb +5 -5
  221. data/lib/new_relic/supportability_helper.rb +2 -1
  222. data/lib/new_relic/version.rb +2 -2
  223. data/lib/newrelic_rpm.rb +4 -4
  224. data/lib/sequel/extensions/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +5 -5
  225. data/lib/sequel/plugins/{newrelic_instrumentation.rb → new_relic_instrumentation.rb} +4 -4
  226. data/lib/tasks/config.rake +12 -12
  227. data/lib/tasks/coverage_report.rake +3 -3
  228. data/lib/tasks/helpers/format.rb +10 -10
  229. data/lib/tasks/helpers/removers.rb +5 -5
  230. data/lib/tasks/install.rake +4 -4
  231. data/lib/tasks/instrumentation_generator/instrumentation.thor +7 -10
  232. data/lib/tasks/instrumentation_generator/templates/Envfile.tt +1 -1
  233. data/lib/tasks/multiverse.rb +12 -6
  234. data/lib/tasks/tests.rake +6 -6
  235. data/newrelic.yml +5 -8
  236. data/newrelic_rpm.gemspec +29 -26
  237. data/test/agent_helper.rb +25 -24
  238. metadata +13 -14
  239. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -83
  240. data/lib/new_relic/agent/instrumentation/authlogic.rb +0 -33
  241. data/lib/new_relic/agent/instrumentation/data_mapper.rb +0 -215
  242. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +0 -36
  243. data/lib/new_relic/agent/instrumentation/sunspot.rb +0 -41
@@ -7,11 +7,11 @@ module NewRelic
7
7
  module DistributedTraceMetrics
8
8
  extend self
9
9
 
10
- ALL_SUFFIX = "all"
11
- ALL_WEB_SUFFIX = "allWeb"
12
- ALL_OTHER_SUFFIX = "allOther"
10
+ ALL_SUFFIX = 'all'
11
+ ALL_WEB_SUFFIX = 'allWeb'
12
+ ALL_OTHER_SUFFIX = 'allOther'
13
13
 
14
- UNKNOWN_CALLER_PREFIX = "%s/Unknown/Unknown/Unknown/%s"
14
+ UNKNOWN_CALLER_PREFIX = '%s/Unknown/Unknown/Unknown/%s'
15
15
 
16
16
  def transaction_type_suffix
17
17
  if Transaction.recording_web_transaction?
@@ -45,14 +45,14 @@ module NewRelic
45
45
  end
46
46
 
47
47
  def record_caller_by_duration_metrics(transaction, payload)
48
- prefix = prefix_for_metric("DurationByCaller", transaction, payload)
48
+ prefix = prefix_for_metric('DurationByCaller', transaction, payload)
49
49
  record_unscoped_metric(transaction, prefix, transaction.duration)
50
50
  end
51
51
 
52
52
  def record_transport_duration_metrics(transaction, payload)
53
53
  return unless payload
54
54
 
55
- prefix = prefix_for_metric("TransportDuration", transaction, payload)
55
+ prefix = prefix_for_metric('TransportDuration', transaction, payload)
56
56
  duration = transaction.calculate_transport_duration(payload)
57
57
  record_unscoped_metric(transaction, prefix, duration)
58
58
  end
@@ -60,7 +60,7 @@ module NewRelic
60
60
  def record_errors_by_caller_metrics(transaction, payload)
61
61
  return unless transaction.exceptions.size > 0
62
62
 
63
- prefix = prefix_for_metric("ErrorsByCaller", transaction, payload)
63
+ prefix = prefix_for_metric('ErrorsByCaller', transaction, payload)
64
64
  record_unscoped_metric(transaction, prefix, 1)
65
65
  end
66
66
 
@@ -17,7 +17,7 @@ module NewRelic
17
17
  extend Coerce
18
18
 
19
19
  VERSION = [0, 1].freeze
20
- PARENT_TYPE = "App"
20
+ PARENT_TYPE = 'App'
21
21
 
22
22
  # Key names for serialization
23
23
  VERSION_KEY = 'v'
@@ -11,12 +11,12 @@ module NewRelic
11
11
  NewRelic::UNKNOWN,
12
12
  NewRelic::HTTP,
13
13
  NewRelic::HTTPS,
14
- "Kafka",
15
- "JMS",
16
- "IronMQ",
17
- "AMQP",
18
- "Queue",
19
- "Other"
14
+ 'Kafka',
15
+ 'JMS',
16
+ 'IronMQ',
17
+ 'AMQP',
18
+ 'Queue',
19
+ 'Other'
20
20
  ].freeze
21
21
 
22
22
  URL_SCHEMES = {
@@ -29,14 +29,14 @@ module NewRelic
29
29
  TP_UNDEFINED_FIELDS = "(?<#{UNDEFINED_FIELDS_KEY}>-[a-zA-Z\\d-]*)"
30
30
  TRACE_PARENT_REGEX = /\A#{TP_VERSION}-#{TP_TRACE_ID}-#{TP_PARENT_ID}-#{TP_TRACE_FLAGS}#{TP_UNDEFINED_FIELDS}?\z/
31
31
 
32
- TRACE_PARENT_FORMAT_STRING = "%02x-%s-%s-%02x"
32
+ TRACE_PARENT_FORMAT_STRING = '%02x-%s-%s-%02x'
33
33
 
34
34
  MAX_TRACE_STATE_SIZE = 512 # bytes
35
35
  MAX_TRACE_STATE_ENTRY_SIZE = 128 # bytes
36
36
 
37
- SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION = "Supportability/TraceContext/TraceParent/Parse/Exception"
38
- SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION = "Supportability/TraceContext/TraceState/Parse/Exception"
39
- SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY = "Supportability/TraceContext/TraceState/InvalidNrEntry"
37
+ SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION = 'Supportability/TraceContext/TraceParent/Parse/Exception'
38
+ SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION = 'Supportability/TraceContext/TraceState/Parse/Exception'
39
+ SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY = 'Supportability/TraceContext/TraceState/InvalidNrEntry'
40
40
 
41
41
  class << self
42
42
  def insert(format: NewRelic::FORMAT_NON_RACK,
@@ -78,7 +78,7 @@ module NewRelic
78
78
  end
79
79
 
80
80
  def create_trace_state_entry(entry_key, payload)
81
- "#{entry_key}=#{payload}".dup
81
+ +"#{entry_key}=#{payload}"
82
82
  end
83
83
 
84
84
  private
@@ -138,7 +138,7 @@ module NewRelic
138
138
 
139
139
  payload = nil
140
140
  trace_state_size = 0
141
- trace_state_vendors = String.new
141
+ trace_state_vendors = +''
142
142
  trace_state = header.split(COMMA).map(&:strip)
143
143
  trace_state.reject! do |entry|
144
144
  if entry == NewRelic::EMPTY_STR
@@ -223,7 +223,7 @@ module NewRelic
223
223
  max_size = MAX_TRACE_STATE_SIZE - trace_state_entry_size
224
224
  return @trace_state_entries.join(COMMA).prepend(COMMA) if @trace_state_size < max_size
225
225
 
226
- joined_trace_state = ''.dup
226
+ joined_trace_state = +''
227
227
 
228
228
  used_size = 0
229
229
 
@@ -9,8 +9,8 @@ module NewRelic
9
9
  class TraceContextPayload
10
10
  VERSION = 0
11
11
  PARENT_TYPE = 0
12
- DELIMITER = "-".freeze
13
- SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
12
+ DELIMITER = '-'.freeze
13
+ SUPPORTABILITY_PARSE_EXCEPTION = 'Supportability/TraceContext/Parse/Exception'.freeze
14
14
 
15
15
  TRUE_CHAR = '1'.freeze
16
16
  FALSE_CHAR = '0'.freeze
@@ -64,7 +64,7 @@ module NewRelic
64
64
  def handle_invalid_payload(error: nil, message: nil)
65
65
  NewRelic::Agent.increment_metric(SUPPORTABILITY_PARSE_EXCEPTION)
66
66
  if error
67
- NewRelic::Agent.logger.warn("Error parsing trace context payload", error)
67
+ NewRelic::Agent.logger.warn('Error parsing trace context payload', error)
68
68
  elsif message
69
69
  NewRelic::Agent.logger.warn("Error parsing trace context payload: #{message}")
70
70
  end
@@ -118,7 +118,7 @@ module NewRelic
118
118
  result << DELIMITER << (id || NewRelic::EMPTY_STR)
119
119
  result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
120
120
  result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
121
- result << DELIMITER << sprintf("%.6f", priority)
121
+ result << DELIMITER << sprintf('%.6f', priority)
122
122
  result << DELIMITER << timestamp.to_s # required
123
123
  result
124
124
  end
@@ -45,11 +45,11 @@ module NewRelic
45
45
  record_api_supportability_metric(:insert_distributed_trace_headers)
46
46
 
47
47
  unless Agent.config[:'distributed_tracing.enabled']
48
- NewRelic::Agent.logger.warn("Not configured to insert distributed trace headers")
48
+ NewRelic::Agent.logger.warn('Not configured to insert distributed trace headers')
49
49
  return nil
50
50
  end
51
51
 
52
- return unless valid_api_argument_class?(headers, "headers", Hash)
52
+ return unless valid_api_argument_class?(headers, 'headers', Hash)
53
53
 
54
54
  return unless transaction = Transaction.tl_current
55
55
 
@@ -99,12 +99,12 @@ module NewRelic
99
99
  record_api_supportability_metric(:accept_distributed_trace_headers)
100
100
 
101
101
  unless Agent.config[:'distributed_tracing.enabled']
102
- NewRelic::Agent.logger.warn("Not configured to accept distributed trace headers")
102
+ NewRelic::Agent.logger.warn('Not configured to accept distributed trace headers')
103
103
  return nil
104
104
  end
105
105
 
106
- return unless valid_api_argument_class?(headers, "headers", Hash)
107
- return unless valid_api_argument_class?(transport_type, "transport_type", String)
106
+ return unless valid_api_argument_class?(headers, 'headers', Hash)
107
+ return unless valid_api_argument_class?(transport_type, 'transport_type', String)
108
108
 
109
109
  return unless transaction = Transaction.tl_current
110
110
 
@@ -26,7 +26,7 @@ module NewRelic
26
26
  @error_filter = NewRelic::Agent::ErrorFilter.new
27
27
 
28
28
  %w[
29
- ignore_errors ignore_classes ignore_messages ignore_status_codes
29
+ ignore_classes ignore_messages ignore_status_codes
30
30
  expected_classes expected_messages expected_status_codes
31
31
  ].each do |w|
32
32
  Agent.config.register_callback(:"error_collector.#{w}") do |value|
@@ -156,13 +156,13 @@ module NewRelic
156
156
  end
157
157
 
158
158
  def aggregated_metric_names(txn)
159
- metric_names = ["Errors/all"]
159
+ metric_names = ['Errors/all']
160
160
  return metric_names unless txn
161
161
 
162
162
  if txn.recording_web_transaction?
163
- metric_names << "Errors/allWeb"
163
+ metric_names << 'Errors/allWeb'
164
164
  else
165
- metric_names << "Errors/allOther"
165
+ metric_names << 'Errors/allOther'
166
166
  end
167
167
 
168
168
  metric_names
@@ -227,7 +227,7 @@ module NewRelic
227
227
  def notice_error(exception, options = {}, span_id = nil)
228
228
  state = ::NewRelic::Agent::Tracer.state
229
229
  transaction = state.current_transaction
230
- status_code = transaction ? transaction.http_response_code : nil
230
+ status_code = transaction&.http_response_code
231
231
 
232
232
  return if skip_notice_error?(exception, status_code)
233
233
 
@@ -242,8 +242,8 @@ module NewRelic
242
242
  noticed_error = create_noticed_error(exception, options)
243
243
  error_trace_aggregator.add_to_error_queue(noticed_error)
244
244
  transaction = state.current_transaction
245
- payload = transaction ? transaction.payload : nil
246
- span_id ||= transaction && transaction.current_segment ? transaction.current_segment.guid : nil
245
+ payload = transaction&.payload
246
+ span_id ||= transaction&.current_segment ? transaction.current_segment.guid : nil
247
247
  error_event_aggregator.record(noticed_error, payload, span_id)
248
248
  exception
249
249
  rescue => e
@@ -277,7 +277,7 @@ module NewRelic
277
277
  noticed_error.line_number = sense_method(exception, :line_number)
278
278
  noticed_error.stack_trace = truncate_trace(extract_stack_trace(exception))
279
279
 
280
- noticed_error.expected = !!options.delete(:expected) || expected?(exception)
280
+ noticed_error.expected = !options.delete(:expected).nil? || expected?(exception)
281
281
 
282
282
  noticed_error.attributes_from_notice_error = options.delete(:custom_params) || {}
283
283
 
@@ -285,6 +285,8 @@ module NewRelic
285
285
  # get treated as custom attributes, so merge them into that hash.
286
286
  noticed_error.attributes_from_notice_error.merge!(options)
287
287
 
288
+ update_error_group_name(noticed_error, exception, options)
289
+
288
290
  noticed_error
289
291
  end
290
292
 
@@ -306,6 +308,32 @@ module NewRelic
306
308
  @error_event_aggregator.reset!
307
309
  nil
308
310
  end
311
+
312
+ private
313
+
314
+ def update_error_group_name(noticed_error, exception, options)
315
+ return unless error_group_callback
316
+
317
+ callback_hash = build_customer_callback_hash(noticed_error, exception, options)
318
+ result = error_group_callback.call(callback_hash)
319
+ noticed_error.error_group = result
320
+ rescue StandardError => e
321
+ NewRelic::Agent.logger.error("Failed to obtain error group from customer callback: #{e.class} - #{e.message}")
322
+ end
323
+
324
+ def build_customer_callback_hash(noticed_error, exception, options)
325
+ {error: exception,
326
+ customAttributes: noticed_error.custom_attributes,
327
+ 'request.uri': noticed_error.request_uri,
328
+ 'http.statusCode': noticed_error.agent_attributes[:'http.statusCode'],
329
+ 'http.method': noticed_error.intrinsic_attributes[:'http.method'],
330
+ 'error.expected': noticed_error.expected,
331
+ options: options}
332
+ end
333
+
334
+ def error_group_callback
335
+ NewRelic::Agent.error_group_callback
336
+ end
309
337
  end
310
338
  end
311
339
  end
@@ -19,7 +19,7 @@ module NewRelic
19
19
 
20
20
  def load_all
21
21
  %i[
22
- ignore_errors ignore_classes ignore_messages ignore_status_codes
22
+ ignore_classes ignore_messages ignore_status_codes
23
23
  expected_classes expected_messages expected_status_codes
24
24
  ].each { |setting| load_from_config(setting) }
25
25
  end
@@ -31,7 +31,7 @@ module NewRelic
31
31
  return if new_value.nil? || (new_value.respond_to?(:empty?) && new_value.empty?)
32
32
 
33
33
  case setting.to_sym
34
- when :ignore_errors, :ignore_classes
34
+ when :ignore_classes
35
35
  new_value = new_value.split(',').map!(&:strip) if new_value.is_a?(String)
36
36
  errors = @ignore_classes = new_value
37
37
  when :ignore_messages
@@ -80,7 +80,7 @@ module NewRelic
80
80
  @ignore_messages.update(errors)
81
81
  log_filter(:ignore_messages, errors)
82
82
  when String
83
- if errors =~ /^[\d\,\-]+$/
83
+ if /^[\d\,\-]+$/.match?(errors)
84
84
  @ignore_status_codes |= parse_status_codes(errors)
85
85
  log_filter(:ignore_status_codes, errors)
86
86
  else
@@ -104,7 +104,7 @@ module NewRelic
104
104
  @expected_messages.update(errors)
105
105
  log_filter(:expected_messages, errors)
106
106
  when String
107
- if errors =~ /^[\d\,\-]+$/
107
+ if /^[\d\,\-]+$/.match?(errors)
108
108
  @expected_status_codes |= parse_status_codes(errors)
109
109
  log_filter(:expected_status_codes, errors)
110
110
  else
@@ -120,7 +120,7 @@ module NewRelic
120
120
 
121
121
  def log_filter(setting, errors)
122
122
  case setting
123
- when :ignore_errors, :ignore_classes
123
+ when :ignore_classes
124
124
  errors.each do |error|
125
125
  ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}'")
126
126
  end
@@ -81,13 +81,14 @@ module NewRelic
81
81
  # Already seen this class once? Bail!
82
82
  return if @errors.any? { |err| err.exception_class_name == exception.class.name }
83
83
 
84
- trace = exception.backtrace || caller.dup
85
- noticed_error = NewRelic::NoticedError.new("NewRelic/AgentError", exception)
86
- noticed_error.stack_trace = trace
84
+ noticed_error = NewRelic::Agent.instance.error_collector.create_noticed_error(exception,
85
+ {metric: 'NewRelic/AgentError'})
86
+ noticed_error.stack_trace = caller.dup unless exception.backtrace
87
+
87
88
  @errors << noticed_error
88
89
  end
89
90
  rescue => e
90
- NewRelic::Agent.logger.info("Unable to capture internal agent error due to an exception:", e)
91
+ NewRelic::Agent.logger.info('Unable to capture internal agent error due to an exception:', e)
91
92
  end
92
93
 
93
94
  def register_config_callbacks
@@ -96,7 +96,7 @@ module NewRelic
96
96
  end
97
97
 
98
98
  def run
99
- ::NewRelic::Agent.logger.debug("Running event loop")
99
+ ::NewRelic::Agent.logger.debug('Running event loop')
100
100
  while !stopped?
101
101
  run_once
102
102
  end
@@ -161,7 +161,7 @@ module NewRelic
161
161
  end
162
162
 
163
163
  def reschedule_timer_for_event(e)
164
- @timers[e].reschedule if @timers[e]
164
+ @timers[e]&.reschedule
165
165
  end
166
166
 
167
167
  def on(event, &blk)
@@ -187,7 +187,7 @@ module NewRelic
187
187
  begin
188
188
  @self_pipe_wr.write_nonblock('.')
189
189
  rescue Errno::EAGAIN
190
- ::NewRelic::Agent.logger.debug("Failed to wakeup event loop")
190
+ ::NewRelic::Agent.logger.debug('Failed to wakeup event loop')
191
191
  end
192
192
  end
193
193
  end
@@ -97,7 +97,7 @@ module NewRelic
97
97
  obfuscator.obfuscate(::JSON.dump(rmd))
98
98
  end
99
99
  rescue => e
100
- NewRelic::Agent.logger.error("error during get_response_metadata", e)
100
+ NewRelic::Agent.logger.error('error during get_response_metadata', e)
101
101
  end
102
102
 
103
103
  private
@@ -14,9 +14,7 @@ module NewRelic
14
14
  @starting_pid = nil
15
15
  @after_forker = after_forker
16
16
 
17
- if events
18
- events.subscribe(:start_transaction, &method(:on_transaction))
19
- end
17
+ events&.subscribe(:start_transaction, &method(:on_transaction))
20
18
  end
21
19
 
22
20
  def on_transaction(*_)
@@ -26,7 +26,8 @@ module NewRelic
26
26
  def initialize(items = nil, &priority_fn)
27
27
  @items = []
28
28
  @priority_fn = priority_fn || ->(x) { x }
29
- items.each { |item| push(item) } if items
29
+ # the following line needs else branch coverage
30
+ items.each { |item| push(item) } if items # rubocop:disable Style/SafeNavigation
30
31
  end
31
32
 
32
33
  def [](index)
@@ -39,7 +39,7 @@ module NewRelic
39
39
 
40
40
  def self.heroku_dyno_name_prefix(dyno_name)
41
41
  get_dyno_prefixes.find do |dyno_prefix|
42
- dyno_name.start_with?(dyno_prefix + ".")
42
+ dyno_name.start_with?(dyno_prefix + '.')
43
43
  end
44
44
  end
45
45
 
@@ -5,8 +5,8 @@
5
5
  module NewRelic
6
6
  module Agent
7
7
  module HTTPClients
8
- MUST_IMPLEMENT_ERROR = "Subclasses of %s must implement a :%s method"
9
- WHINY_NIL_ERROR = "%s cannot initialize with a nil wrapped_response object."
8
+ MUST_IMPLEMENT_ERROR = 'Subclasses of %s must implement a :%s method'
9
+ WHINY_NIL_ERROR = '%s cannot initialize with a nil wrapped_response object.'
10
10
 
11
11
  # This class provides a public interface for wrapping HTTP requests. This
12
12
  # may be used to create wrappers that are compatible with New Relic's
@@ -14,28 +14,16 @@ module NewRelic
14
14
  #
15
15
  # @api public
16
16
  class AbstractRequest
17
- def []
18
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
19
- end
20
-
21
- def []=
22
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
23
- end
24
-
25
- def type
26
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
27
- end
28
-
29
- def host_from_header
30
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
17
+ %i[[] []= type host_from_header host method headers uri].each do |name|
18
+ define_method(name) do
19
+ not_implemented(name)
20
+ end
31
21
  end
32
22
 
33
- def host
34
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
35
- end
23
+ private
36
24
 
37
- def method
38
- raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
25
+ def not_implemented(method_name)
26
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, method_name]
39
27
  end
40
28
  end
41
29
 
@@ -33,16 +33,20 @@ module NewRelic
33
33
  end
34
34
 
35
35
  def [](key)
36
- @curlobj.headers[key]
36
+ headers[key]
37
37
  end
38
38
 
39
39
  def []=(key, value)
40
- @curlobj.headers[key] = value
40
+ headers[key] = value
41
41
  end
42
42
 
43
43
  def uri
44
44
  @uri ||= URIUtil.parse_and_normalize_url(@curlobj.url)
45
45
  end
46
+
47
+ def headers
48
+ @curlobj.headers
49
+ end
46
50
  end
47
51
 
48
52
  class CurbResponse < AbstractResponse
@@ -62,7 +66,7 @@ module NewRelic
62
66
  def append_header_data(data)
63
67
  key, value = data.split(/:\s*/, 2)
64
68
  @headers[key.downcase] = value
65
- @wrapped_response._nr_header_str ||= String.new
69
+ @wrapped_response._nr_header_str ||= +''
66
70
  @wrapped_response._nr_header_str << data
67
71
  end
68
72
 
@@ -46,7 +46,7 @@ module NewRelic
46
46
  class ExconHTTPRequest < AbstractRequest
47
47
  attr_reader :method
48
48
 
49
- EXCON = "Excon"
49
+ EXCON = 'Excon'
50
50
  LHOST = 'host'
51
51
  UHOST = 'Host'
52
52
  COLON = ':'
@@ -65,7 +65,6 @@ module NewRelic
65
65
  end
66
66
 
67
67
  def host_from_header
68
- headers = @datum[:headers]
69
68
  if hostname = (headers[LHOST] || headers[UHOST])
70
69
  hostname.split(COLON).first
71
70
  end
@@ -76,18 +75,21 @@ module NewRelic
76
75
  end
77
76
 
78
77
  def [](key)
79
- @datum[:headers][key]
78
+ headers[key]
80
79
  end
81
80
 
82
81
  def []=(key, value)
83
- @datum[:headers] ||= {}
84
- @datum[:headers][key] = value
82
+ headers[key] = value
85
83
  end
86
84
 
87
85
  def uri
88
86
  url = "#{@scheme}://#{host}:#{@port}#{@path}"
89
87
  URIUtil.parse_and_normalize_url(url)
90
88
  end
89
+
90
+ def headers
91
+ @datum[:headers]
92
+ end
91
93
  end
92
94
  end
93
95
  end
@@ -56,6 +56,10 @@ module NewRelic
56
56
  def []=(key, value)
57
57
  @wrapped_request.headers[key] = value
58
58
  end
59
+
60
+ def headers
61
+ @wrapped_request.headers.to_hash
62
+ end
59
63
  end
60
64
  end
61
65
  end
@@ -25,7 +25,7 @@ module NewRelic
25
25
  class HTTPClientRequest < AbstractRequest
26
26
  attr_reader :request
27
27
 
28
- HTTP_CLIENT = "HTTPClient".freeze
28
+ HTTP_CLIENT = 'HTTPClient'.freeze
29
29
  LHOST = 'host'.freeze
30
30
  UHOST = 'Host'.freeze
31
31
  COLON = ':'.freeze
@@ -57,12 +57,16 @@ module NewRelic
57
57
  end
58
58
 
59
59
  def [](key)
60
- request.headers[key]
60
+ headers[key]
61
61
  end
62
62
 
63
63
  def []=(key, value)
64
64
  request.http_header[key] = value
65
65
  end
66
+
67
+ def headers
68
+ request.headers
69
+ end
66
70
  end
67
71
  end
68
72
  end
@@ -61,7 +61,7 @@ module NewRelic
61
61
  ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@request.path)
62
62
  else
63
63
  connection_address = @connection.address
64
- if connection_address =~ Resolv::IPv6::Regex
64
+ if Resolv::IPv6::Regex.match?(connection_address)
65
65
  connection_address = "[#{connection_address}]"
66
66
  end
67
67
 
@@ -71,6 +71,10 @@ module NewRelic
71
71
  )
72
72
  end
73
73
  end
74
+
75
+ def headers
76
+ @request.instance_variable_get(:@header)
77
+ end
74
78
  end
75
79
  end
76
80
  end
@@ -42,7 +42,7 @@ module NewRelic
42
42
  end
43
43
  end
44
44
 
45
- TYPHOEUS = "Typhoeus".freeze
45
+ TYPHOEUS = 'Typhoeus'.freeze
46
46
 
47
47
  def type
48
48
  TYPHOEUS
@@ -66,14 +66,17 @@ module NewRelic
66
66
  end
67
67
 
68
68
  def [](key)
69
- return nil unless @request.options && @request.options[:headers]
69
+ return nil unless @request.options && headers
70
70
 
71
- @request.options[:headers][key]
71
+ headers[key]
72
72
  end
73
73
 
74
74
  def []=(key, value)
75
- @request.options[:headers] ||= {}
76
- @request.options[:headers][key] = value
75
+ headers[key] = value
76
+ end
77
+
78
+ def headers
79
+ @request.options[:headers] || {}
77
80
  end
78
81
 
79
82
  def uri
@@ -36,11 +36,11 @@ module NewRelic
36
36
  uri = ::URI.parse(url)
37
37
  end
38
38
  end
39
- uri.host.downcase! unless uri.host.nil?
39
+ uri.host&.downcase!
40
40
  uri
41
41
  end
42
42
 
43
- QUESTION_MARK = "?"
43
+ QUESTION_MARK = '?'
44
44
 
45
45
  def self.strip_query_string(fragment)
46
46
  if fragment.include?(QUESTION_MARK)
@@ -27,11 +27,14 @@ module NewRelic
27
27
  end
28
28
 
29
29
  def controller_name_for_metric(payload)
30
+ return unless payload
30
31
  # redirect_to
31
- return payload[:request].controller_class.controller_path if payload[:request] && payload[:request].controller_class
32
+ return payload[:request].controller_class.controller_path if payload[:request].respond_to?(:controller_class) && payload[:request].controller_class&.respond_to?(:controller_path)
32
33
 
33
34
  # unpermitted_parameters
34
- ::NewRelic::LanguageSupport.constantize(payload[:context][:controller]).controller_path if payload[:context] && payload[:context][:controller]
35
+ if payload[:context]&.[](:controller) && constantized_class = ::NewRelic::LanguageSupport.constantize(payload[:context][:controller])
36
+ constantized_class.respond_to?(:controller_path) ? constantized_class.controller_path : nil
37
+ end
35
38
  end
36
39
  end
37
40
  end