newrelic_rpm 9.0.0 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -16
  4. data/.rubocop_todo.yml +4 -43
  5. data/.simplecov +1 -1
  6. data/CHANGELOG.md +60 -2
  7. data/Gemfile +1 -1
  8. data/Guardfile +7 -7
  9. data/README.md +1 -2
  10. data/Rakefile +8 -8
  11. data/Thorfile +1 -1
  12. data/bin/nrdebug +20 -20
  13. data/init.rb +1 -1
  14. data/lib/new_relic/agent/agent.rb +3 -16
  15. data/lib/new_relic/agent/agent_helpers/connect.rb +4 -9
  16. data/lib/new_relic/agent/agent_helpers/harvest.rb +4 -4
  17. data/lib/new_relic/agent/agent_helpers/shutdown.rb +5 -5
  18. data/lib/new_relic/agent/agent_helpers/special_startup.rb +2 -2
  19. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +47 -39
  20. data/lib/new_relic/agent/agent_helpers/startup.rb +13 -13
  21. data/lib/new_relic/agent/agent_helpers/transmit.rb +6 -6
  22. data/lib/new_relic/agent/agent_logger.rb +9 -9
  23. data/lib/new_relic/agent/attribute_filter.rb +2 -2
  24. data/lib/new_relic/agent/attribute_processing.rb +2 -2
  25. data/lib/new_relic/agent/audit_logger.rb +5 -5
  26. data/lib/new_relic/agent/autostart.rb +1 -1
  27. data/lib/new_relic/agent/commands/agent_command.rb +2 -2
  28. data/lib/new_relic/agent/commands/agent_command_router.rb +5 -4
  29. data/lib/new_relic/agent/commands/thread_profiler_session.rb +5 -5
  30. data/lib/new_relic/agent/configuration/default_source.rb +57 -56
  31. data/lib/new_relic/agent/configuration/environment_source.rb +2 -2
  32. data/lib/new_relic/agent/configuration/high_security_source.rb +3 -3
  33. data/lib/new_relic/agent/configuration/manager.rb +2 -2
  34. data/lib/new_relic/agent/configuration/security_policy_source.rb +10 -10
  35. data/lib/new_relic/agent/configuration/server_source.rb +24 -24
  36. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -4
  37. data/lib/new_relic/agent/connect/request_builder.rb +1 -1
  38. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  39. data/lib/new_relic/agent/custom_event_aggregator.rb +4 -4
  40. data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
  41. data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
  42. data/lib/new_relic/agent/database/obfuscator.rb +2 -2
  43. data/lib/new_relic/agent/database.rb +4 -4
  44. data/lib/new_relic/agent/datastores/metric_helper.rb +5 -5
  45. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -11
  46. data/lib/new_relic/agent/datastores/redis.rb +6 -6
  47. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +7 -8
  48. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +10 -10
  49. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +7 -7
  50. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
  51. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +6 -6
  52. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +7 -7
  53. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +4 -4
  54. data/lib/new_relic/agent/distributed_tracing.rb +5 -5
  55. data/lib/new_relic/agent/error_collector.rb +35 -7
  56. data/lib/new_relic/agent/error_filter.rb +2 -2
  57. data/lib/new_relic/agent/error_trace_aggregator.rb +5 -4
  58. data/lib/new_relic/agent/event_loop.rb +3 -3
  59. data/lib/new_relic/agent/external.rb +1 -1
  60. data/lib/new_relic/agent/harvester.rb +1 -3
  61. data/lib/new_relic/agent/heap.rb +2 -1
  62. data/lib/new_relic/agent/hostname.rb +1 -1
  63. data/lib/new_relic/agent/http_clients/abstract.rb +9 -21
  64. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +7 -3
  65. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +7 -5
  66. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +4 -0
  67. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +6 -2
  68. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  69. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +8 -5
  70. data/lib/new_relic/agent/http_clients/uri_util.rb +2 -2
  71. data/lib/new_relic/agent/instrumentation/action_controller_other_subscriber.rb +5 -2
  72. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +3 -2
  73. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +3 -3
  74. data/lib/new_relic/agent/instrumentation/active_job.rb +1 -1
  75. data/lib/new_relic/agent/instrumentation/active_record.rb +3 -2
  76. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +38 -35
  77. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +3 -3
  78. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +2 -2
  79. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +3 -2
  80. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +3 -3
  81. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +5 -3
  82. data/lib/new_relic/agent/instrumentation/curb/chain.rb +1 -1
  83. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +5 -5
  84. data/lib/new_relic/agent/instrumentation/curb.rb +1 -1
  85. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +2 -1
  86. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +1 -1
  87. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -1
  88. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +1 -1
  89. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +3 -3
  90. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +1 -1
  91. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
  92. data/lib/new_relic/agent/instrumentation/excon.rb +3 -3
  93. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +4 -4
  94. data/lib/new_relic/agent/instrumentation/grape.rb +3 -3
  95. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +2 -1
  96. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +3 -3
  97. data/lib/new_relic/agent/instrumentation/httprb.rb +1 -1
  98. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
  99. data/lib/new_relic/agent/instrumentation/logger.rb +1 -1
  100. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +2 -2
  101. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  102. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +3 -3
  103. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +1 -1
  104. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +5 -5
  105. data/lib/new_relic/agent/instrumentation/net_http.rb +1 -1
  106. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
  107. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +3 -3
  108. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  109. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +1 -1
  110. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -2
  111. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
  112. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +7 -7
  113. data/lib/new_relic/agent/instrumentation/rake.rb +2 -2
  114. data/lib/new_relic/agent/instrumentation/redis/constants.rb +1 -1
  115. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +2 -1
  116. data/lib/new_relic/agent/instrumentation/resque/helper.rb +1 -1
  117. data/lib/new_relic/agent/instrumentation/sequel.rb +4 -4
  118. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +10 -10
  119. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +1 -1
  120. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +1 -1
  121. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  122. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +6 -5
  123. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  124. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +2 -1
  125. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +5 -5
  126. data/lib/new_relic/agent/javascript_instrumentor.rb +29 -24
  127. data/lib/new_relic/agent/linking_metadata.rb +2 -2
  128. data/lib/new_relic/agent/log_event_aggregator.rb +15 -15
  129. data/lib/new_relic/agent/logging.rb +73 -33
  130. data/lib/new_relic/agent/messaging.rb +7 -5
  131. data/lib/new_relic/agent/method_tracer.rb +6 -6
  132. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  133. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +4 -4
  134. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -1
  135. data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
  136. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +2 -2
  137. data/lib/new_relic/agent/new_relic_service.rb +14 -14
  138. data/lib/new_relic/agent/obfuscator.rb +1 -1
  139. data/lib/new_relic/agent/parameter_filtering.rb +6 -6
  140. data/lib/new_relic/agent/pipe_channel_manager.rb +7 -6
  141. data/lib/new_relic/agent/pipe_service.rb +5 -3
  142. data/lib/new_relic/agent/priority_sampled_buffer.rb +1 -1
  143. data/lib/new_relic/agent/sampler.rb +1 -1
  144. data/lib/new_relic/agent/sampler_collection.rb +1 -1
  145. data/lib/new_relic/agent/samplers/cpu_sampler.rb +5 -5
  146. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +9 -9
  147. data/lib/new_relic/agent/samplers/memory_sampler.rb +9 -9
  148. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  149. data/lib/new_relic/agent/span_event_aggregator.rb +4 -4
  150. data/lib/new_relic/agent/span_event_primitive.rb +2 -2
  151. data/lib/new_relic/agent/sql_sampler.rb +2 -2
  152. data/lib/new_relic/agent/stats.rb +1 -1
  153. data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
  154. data/lib/new_relic/agent/system_info.rb +10 -10
  155. data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
  156. data/lib/new_relic/agent/threading/backtrace_node.rb +3 -3
  157. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -7
  158. data/lib/new_relic/agent/threading/thread_profile.rb +5 -5
  159. data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
  160. data/lib/new_relic/agent/tracer.rb +8 -7
  161. data/lib/new_relic/agent/transaction/abstract_segment.rb +7 -7
  162. data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
  163. data/lib/new_relic/agent/transaction/distributed_tracer.rb +7 -6
  164. data/lib/new_relic/agent/transaction/distributed_tracing.rb +6 -6
  165. data/lib/new_relic/agent/transaction/external_request_segment.rb +11 -11
  166. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -1
  167. data/lib/new_relic/agent/transaction/request_attributes.rb +2 -2
  168. data/lib/new_relic/agent/transaction/segment.rb +1 -1
  169. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
  170. data/lib/new_relic/agent/transaction/trace.rb +1 -1
  171. data/lib/new_relic/agent/transaction/trace_context.rb +4 -4
  172. data/lib/new_relic/agent/transaction/trace_node.rb +8 -7
  173. data/lib/new_relic/agent/transaction/tracing.rb +2 -2
  174. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
  175. data/lib/new_relic/agent/transaction.rb +39 -36
  176. data/lib/new_relic/agent/transaction_error_primitive.rb +5 -5
  177. data/lib/new_relic/agent/transaction_event_aggregator.rb +4 -4
  178. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -3
  179. data/lib/new_relic/agent/transaction_sampler.rb +3 -3
  180. data/lib/new_relic/agent/transaction_time_aggregator.rb +7 -3
  181. data/lib/new_relic/agent/utilization/aws.rb +1 -1
  182. data/lib/new_relic/agent/utilization/azure.rb +3 -3
  183. data/lib/new_relic/agent/utilization/gcp.rb +3 -3
  184. data/lib/new_relic/agent/utilization/pcf.rb +1 -1
  185. data/lib/new_relic/agent/utilization/vendor.rb +1 -1
  186. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
  187. data/lib/new_relic/agent/vm/mri_vm.rb +9 -8
  188. data/lib/new_relic/agent/worker_loop.rb +1 -1
  189. data/lib/new_relic/agent.rb +78 -16
  190. data/lib/new_relic/cli/command.rb +3 -3
  191. data/lib/new_relic/cli/commands/deployments.rb +26 -25
  192. data/lib/new_relic/cli/commands/install.rb +14 -14
  193. data/lib/new_relic/collection_helper.rb +2 -2
  194. data/lib/new_relic/constants.rb +7 -8
  195. data/lib/new_relic/control/class_methods.rb +3 -3
  196. data/lib/new_relic/control/frameworks/rails.rb +30 -18
  197. data/lib/new_relic/control/instance_methods.rb +5 -5
  198. data/lib/new_relic/control/instrumentation.rb +1 -1
  199. data/lib/new_relic/control/private_instance_methods.rb +1 -1
  200. data/lib/new_relic/dependency_detection.rb +4 -17
  201. data/lib/new_relic/environment_report.rb +4 -4
  202. data/lib/new_relic/helper.rb +2 -1
  203. data/lib/new_relic/language_support.rb +1 -1
  204. data/lib/new_relic/latest_changes.rb +5 -5
  205. data/lib/new_relic/noticed_error.rb +20 -18
  206. data/lib/new_relic/rack/browser_monitoring.rb +20 -16
  207. data/lib/new_relic/recipes/capistrano3.rb +1 -1
  208. data/lib/new_relic/recipes/capistrano_legacy.rb +6 -6
  209. data/lib/new_relic/recipes/helpers/send_deployment.rb +5 -5
  210. data/lib/new_relic/supportability_helper.rb +2 -0
  211. data/lib/new_relic/version.rb +1 -1
  212. data/lib/newrelic_rpm.rb +3 -3
  213. data/lib/sequel/extensions/new_relic_instrumentation.rb +3 -3
  214. data/lib/sequel/plugins/new_relic_instrumentation.rb +1 -1
  215. data/lib/tasks/config.rake +12 -12
  216. data/lib/tasks/coverage_report.rake +3 -3
  217. data/lib/tasks/helpers/format.rb +9 -9
  218. data/lib/tasks/helpers/removers.rb +5 -5
  219. data/lib/tasks/install.rake +4 -4
  220. data/lib/tasks/multiverse.rb +12 -6
  221. data/lib/tasks/tests.rake +6 -6
  222. data/newrelic_rpm.gemspec +13 -13
  223. data/test/agent_helper.rb +25 -24
  224. metadata +2 -2
@@ -10,7 +10,7 @@ module NewRelic
10
10
  module Agent
11
11
  module Database
12
12
  MAX_QUERY_LENGTH = 16384
13
- ELLIPSIS = "...".freeze
13
+ ELLIPSIS = '...'.freeze
14
14
 
15
15
  extend self
16
16
 
@@ -150,7 +150,7 @@ module NewRelic
150
150
  begin
151
151
  @connections[config] = yield(config)
152
152
  rescue => e
153
- ::NewRelic::Agent.logger.error("Caught exception trying to get connection to DB for explain.", e)
153
+ ::NewRelic::Agent.logger.error('Caught exception trying to get connection to DB for explain.', e)
154
154
  nil
155
155
  end
156
156
  end
@@ -174,7 +174,7 @@ module NewRelic
174
174
 
175
175
  attr_accessor :sql, :config, :explainer, :binds, :name, :host, :port_path_or_id, :database_name
176
176
 
177
- DEFAULT_QUERY_NAME = "SQL".freeze
177
+ DEFAULT_QUERY_NAME = 'SQL'.freeze
178
178
 
179
179
  def initialize(sql, config = {}, explainer = nil, binds = nil, name = DEFAULT_QUERY_NAME, host = nil, port_path_or_id = nil, database_name = nil)
180
180
  @sql = Database.capture_query(sql)
@@ -219,7 +219,7 @@ module NewRelic
219
219
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
220
220
  plan = @explainer.call(self)
221
221
  ::NewRelic::Agent.record_metric(
222
- "Supportability/Database/execute_explain_plan",
222
+ 'Supportability/Database/execute_explain_plan',
223
223
  Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
224
224
  )
225
225
  return process_resultset(plan, adapter) if plan
@@ -6,12 +6,12 @@ module NewRelic
6
6
  module Agent
7
7
  module Datastores
8
8
  module MetricHelper
9
- ROLLUP_METRIC = "Datastore/all".freeze
10
- OTHER = "Other".freeze
9
+ ROLLUP_METRIC = 'Datastore/all'.freeze
10
+ OTHER = 'Other'.freeze
11
11
 
12
- ALL = "all".freeze
13
- ALL_WEB = "allWeb".freeze
14
- ALL_OTHER = "allOther".freeze
12
+ ALL = 'all'.freeze
13
+ ALL_WEB = 'allWeb'.freeze
14
+ ALL_OTHER = 'allOther'.freeze
15
15
 
16
16
  def self.statement_metric_for(product, collection, operation)
17
17
  "Datastore/statement/#{product}/#{collection}/#{operation}"
@@ -53,7 +53,7 @@ module NewRelic
53
53
 
54
54
  [name.to_s, collection]
55
55
  rescue => e
56
- NewRelic::Agent.logger.debug("Failure during Mongo metric generation", e)
56
+ NewRelic::Agent.logger.debug('Failure during Mongo metric generation', e)
57
57
  nil
58
58
  end
59
59
 
@@ -64,10 +64,10 @@ module NewRelic
64
64
  NAMES_IN_SELECTOR = [
65
65
  :findandmodify,
66
66
 
67
- "aggregate",
68
- "count",
69
- "group",
70
- "mapreduce",
67
+ 'aggregate',
68
+ 'count',
69
+ 'group',
70
+ 'mapreduce',
71
71
 
72
72
  :distinct,
73
73
 
@@ -91,18 +91,18 @@ module NewRelic
91
91
  if command_key
92
92
  command_key.to_sym
93
93
  else
94
- NewRelic::Agent.increment_metric("Supportability/Mongo/UnknownCollection")
94
+ NewRelic::Agent.increment_metric('Supportability/Mongo/UnknownCollection')
95
95
  payload[:selector].first.first unless command_key
96
96
  end
97
97
  end
98
98
 
99
- CMD_COLLECTION = "$cmd".freeze
99
+ CMD_COLLECTION = '$cmd'.freeze
100
100
 
101
101
  def self.get_collection_from_selector(command_key, payload)
102
102
  if command_key
103
103
  payload[:selector][command_key]
104
104
  else
105
- NewRelic::Agent.increment_metric("Supportability/Mongo/UnknownCollection")
105
+ NewRelic::Agent.increment_metric('Supportability/Mongo/UnknownCollection')
106
106
  CMD_COLLECTION
107
107
  end
108
108
  end
@@ -124,11 +124,11 @@ module NewRelic
124
124
  end
125
125
 
126
126
  def self.create_index?(name, payload)
127
- name == :insert && payload[:collection] == "system.indexes"
127
+ name == :insert && payload[:collection] == 'system.indexes'
128
128
  end
129
129
 
130
130
  def self.drop_indexes?(name, payload)
131
- name == :deleteIndexes && payload[:selector] && payload[:selector][:index] == "*"
131
+ name == :deleteIndexes && payload[:selector] && payload[:selector][:index] == '*'
132
132
  end
133
133
 
134
134
  def self.drop_index?(name, payload)
@@ -166,7 +166,7 @@ module NewRelic
166
166
  end
167
167
 
168
168
  def self.collection_name_from_group_selector(payload)
169
- payload[:selector]["group"]["ns"]
169
+ payload[:selector]['group']['ns']
170
170
  end
171
171
 
172
172
  def self.collection_name_from_rename_selector(payload)
@@ -6,7 +6,7 @@ module NewRelic
6
6
  module Agent
7
7
  module Datastores
8
8
  module Redis
9
- BINARY_DATA_PLACEHOLDER = "<binary data>"
9
+ BINARY_DATA_PLACEHOLDER = '<binary data>'
10
10
 
11
11
  MAXIMUM_COMMAND_LENGTH = 1000
12
12
  MAXIMUM_ARGUMENT_LENGTH = 64
@@ -25,7 +25,7 @@ module NewRelic
25
25
 
26
26
  def self.format_command(command_with_args)
27
27
  if Agent.config[:'transaction_tracer.record_redis_arguments']
28
- result = String.new('')
28
+ result = +''
29
29
 
30
30
  append_command_with_args(result, command_with_args)
31
31
 
@@ -36,7 +36,7 @@ module NewRelic
36
36
  end
37
37
 
38
38
  def self.format_pipeline_commands(commands_with_args)
39
- result = String.new('')
39
+ result = +''
40
40
 
41
41
  commands_with_args.each do |command|
42
42
  if result.length >= MAXIMUM_COMMAND_LENGTH
@@ -83,7 +83,7 @@ module NewRelic
83
83
  end
84
84
 
85
85
  def self.is_supported_version?
86
- Gem::Version.new(::Redis::VERSION) >= Gem::Version.new("3.0.0")
86
+ Gem::Version.new(::Redis::VERSION) >= Gem::Version.new('3.0.0')
87
87
  end
88
88
 
89
89
  def self.ellipsize(result, string)
@@ -106,8 +106,8 @@ module NewRelic
106
106
  end
107
107
 
108
108
  def self.safe_from_third_party_gem?
109
- if NewRelic::LanguageSupport.bundled_gem?("newrelic-redis")
110
- ::NewRelic::Agent.logger.info("Not installing New Relic supported Redis instrumentation because the third party newrelic-redis gem is present")
109
+ if NewRelic::LanguageSupport.bundled_gem?('newrelic-redis')
110
+ ::NewRelic::Agent.logger.info('Not installing New Relic supported Redis instrumentation because the third party newrelic-redis gem is present')
111
111
  false
112
112
  else
113
113
  true
@@ -1,4 +1,3 @@
1
- # -*- ruby -*-
2
1
  # This file is distributed under New Relic's license terms.
3
2
  # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
3
  # frozen_string_literal: true
@@ -28,7 +27,7 @@ module NewRelic
28
27
  end
29
28
 
30
29
  def is_cross_app_callee?
31
- cross_app_payload != nil
30
+ !cross_app_payload.nil?
32
31
  end
33
32
 
34
33
  def is_cross_app?
@@ -36,7 +35,7 @@ module NewRelic
36
35
  end
37
36
 
38
37
  def cat_trip_id
39
- cross_app_payload && cross_app_payload.referring_trip_id || transaction.guid
38
+ cross_app_payload&.referring_trip_id || transaction.guid
40
39
  end
41
40
 
42
41
  def cross_app_monitor
@@ -74,7 +73,7 @@ module NewRelic
74
73
  end
75
74
 
76
75
  def record_cross_app_metrics
77
- if (id = cross_app_payload && cross_app_payload.id)
76
+ if (id = cross_app_payload&.id)
78
77
  app_time_in_seconds = [
79
78
  Process.clock_gettime(Process::CLOCK_REALTIME) - transaction.start_time,
80
79
  0.0
@@ -104,11 +103,11 @@ module NewRelic
104
103
  end
105
104
 
106
105
  def cat_referring_path_hash
107
- cross_app_payload && cross_app_payload.referring_path_hash
106
+ cross_app_payload&.referring_path_hash
108
107
  end
109
108
 
110
109
  def append_cat_info(payload)
111
- if (referring_guid = cross_app_payload && cross_app_payload.referring_guid)
110
+ if (referring_guid = cross_app_payload&.referring_guid)
112
111
  payload[:referring_transaction_guid] = referring_guid
113
112
  end
114
113
 
@@ -150,7 +149,7 @@ module NewRelic
150
149
  if Agent.config[:cross_process_id] && Agent.config[:cross_process_id].length > 0
151
150
  true
152
151
  else
153
- NewRelic::Agent.logger.debug("No cross_process_id configured")
152
+ NewRelic::Agent.logger.debug('No cross_process_id configured')
154
153
  false
155
154
  end
156
155
  end
@@ -159,7 +158,7 @@ module NewRelic
159
158
  if Agent.config[:encoding_key] && Agent.config[:encoding_key].length > 0
160
159
  true
161
160
  else
162
- NewRelic::Agent.logger.debug("No encoding_key set")
161
+ NewRelic::Agent.logger.debug('No encoding_key set')
163
162
  false
164
163
  end
165
164
  end
@@ -9,16 +9,16 @@ module NewRelic
9
9
 
10
10
  # Intrinsic Keys
11
11
  INTRINSIC_KEYS = [
12
- PARENT_TYPE_KEY = "parent.type",
13
- PARENT_APP_KEY = "parent.app",
14
- PARENT_ACCOUNT_ID_KEY = "parent.account",
15
- PARENT_TRANSPORT_TYPE_KEY = "parent.transportType",
16
- PARENT_TRANSPORT_DURATION_KEY = "parent.transportDuration",
17
- GUID_KEY = "guid",
18
- TRACE_ID_KEY = "traceId",
19
- PARENT_TRANSACTION_ID_KEY = "parentId",
20
- PARENT_SPAN_ID_KEY = "parentSpanId",
21
- SAMPLED_KEY = "sampled"
12
+ PARENT_TYPE_KEY = 'parent.type',
13
+ PARENT_APP_KEY = 'parent.app',
14
+ PARENT_ACCOUNT_ID_KEY = 'parent.account',
15
+ PARENT_TRANSPORT_TYPE_KEY = 'parent.transportType',
16
+ PARENT_TRANSPORT_DURATION_KEY = 'parent.transportDuration',
17
+ GUID_KEY = 'guid',
18
+ TRACE_ID_KEY = 'traceId',
19
+ PARENT_TRANSACTION_ID_KEY = 'parentId',
20
+ PARENT_SPAN_ID_KEY = 'parentSpanId',
21
+ SAMPLED_KEY = 'sampled'
22
22
  ].freeze
23
23
 
24
24
  # This method extracts intrinsics from the transaction_payload and
@@ -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
 
@@ -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
@@ -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
@@ -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