newrelic_rpm 6.9.0.363 → 6.10.0.364

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.md +59 -5
  4. data/lib/new_relic/agent.rb +3 -2
  5. data/lib/new_relic/agent/agent.rb +2 -2
  6. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  7. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +1 -1
  8. data/lib/new_relic/agent/error_collector.rb +30 -11
  9. data/lib/new_relic/agent/error_event_aggregator.rb +4 -4
  10. data/lib/new_relic/agent/hostname.rb +7 -1
  11. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  12. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +24 -19
  13. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +28 -13
  14. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +17 -21
  15. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +10 -11
  16. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +16 -4
  17. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -6
  18. data/lib/new_relic/agent/http_clients/uri_util.rb +3 -2
  19. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +4 -5
  20. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -0
  21. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -2
  22. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -2
  23. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +7 -2
  24. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -4
  25. data/lib/new_relic/agent/instrumentation/bunny.rb +44 -27
  26. data/lib/new_relic/agent/instrumentation/curb.rb +58 -17
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -1
  28. data/lib/new_relic/agent/instrumentation/excon/connection.rb +6 -3
  29. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
  30. data/lib/new_relic/agent/instrumentation/http.rb +5 -2
  31. data/lib/new_relic/agent/instrumentation/httpclient.rb +4 -2
  32. data/lib/new_relic/agent/instrumentation/memcache.rb +3 -1
  33. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +6 -2
  34. data/lib/new_relic/agent/instrumentation/mongo.rb +9 -3
  35. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +13 -0
  36. data/lib/new_relic/agent/instrumentation/net.rb +5 -2
  37. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +25 -1
  38. data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
  39. data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
  40. data/lib/new_relic/agent/instrumentation/typhoeus.rb +22 -5
  41. data/lib/new_relic/agent/logging.rb +1 -1
  42. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  43. data/lib/new_relic/agent/noticible_error.rb +22 -0
  44. data/lib/new_relic/agent/span_event_primitive.rb +43 -32
  45. data/lib/new_relic/agent/tracer.rb +30 -15
  46. data/lib/new_relic/agent/transaction.rb +47 -43
  47. data/lib/new_relic/agent/transaction/abstract_segment.rb +26 -0
  48. data/lib/new_relic/agent/transaction/external_request_segment.rb +25 -9
  49. data/lib/new_relic/agent/transaction_error_primitive.rb +5 -3
  50. data/lib/new_relic/cli/commands/install.rb +3 -2
  51. data/lib/new_relic/noticed_error.rb +28 -9
  52. data/lib/new_relic/rack/browser_monitoring.rb +2 -1
  53. data/lib/new_relic/version.rb +1 -1
  54. data/lib/tasks/multiverse.rb +25 -0
  55. data/lib/tasks/tests.rake +1 -1
  56. data/test/agent_helper.rb +217 -64
  57. metadata +4 -3
  58. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eb269d5c36e6139c7b617d3083418a8c8acf85e94c4f1005b1241aafc9471dd
4
- data.tar.gz: da6387b811e5402cd2a0da7b80acc5b88338768cf36e01b1c86d7576c2592f3d
3
+ metadata.gz: 7e5ab7fd3bb77356673eb2437785714e3935f9bbc9a763254425166753470f79
4
+ data.tar.gz: a0a8b207924ef308a1105783cfa373ca77ca91deeb046cdea632d48afe9e9906
5
5
  SHA512:
6
- metadata.gz: 077d136a9c8e3771f506ee67422983ae4782e23b9118e9cb070f35fdf3af7b8a9d9ed125725db34945d8195529c0c22bbde0a7ab313d1fae9488485e40f7398d
7
- data.tar.gz: c577d7a04fac1e22f043156635d4d2eeb3674707a2f50f7b11756855f4b4ae7e3479a6783d45decdc1a4950ce2b69e8d1d691bad6ebe67b504b098838fa6c86f
6
+ metadata.gz: cf2e4fc7fb9c35dd2d1392a9b47e3dea5c908230d59b616eb51d8f544560e736e9ac7256419c51751ee24627d1bf291f190f1bb8a3bf75436152ebba340b21ba
7
+ data.tar.gz: 1a29679d374d033b649cfa5966aad2127374de42f0527bbdc4091ff8c73f061a0df0b6049561eec2c4fe4af752329a139a9e2764e910943d315b5137d2cd93ea
@@ -4,6 +4,10 @@ services:
4
4
  - memcached
5
5
  - rabbitmq
6
6
 
7
+ notifications:
8
+ slack:
9
+ secure: Ziq6vzXmc1S+SZnJF7DyjprRgzZKvVK5TXtnNJAoH4EFchziCqko+75hMxDZ/6Y2kShcijgbzZSkIIVSiuYyx0Jgxdsmwed7yrs91uv2WsUw2/l+taOTBIAMa/m9PZppsRqmkywxWeeTPL6cf65Vg3PYRuqzj83nczUFJo4UNrA=
10
+
7
11
  language: ruby
8
12
 
9
13
  dist: precise
@@ -78,6 +82,7 @@ env:
78
82
  - TYPE=UNIT ENVIRONMENT=rails42
79
83
  - TYPE=UNIT ENVIRONMENT=rails50
80
84
  - TYPE=UNIT ENVIRONMENT=rails51
85
+ - TYPE=UNIT ENVIRONMENT=rails52
81
86
  - TYPE=UNIT ENVIRONMENT=rails60
82
87
  - TYPE=UNIT ENVIRONMENT=norails
83
88
  - TYPE=FUNCTIONAL GROUP=agent
@@ -117,6 +122,8 @@ matrix:
117
122
  env: TYPE=UNIT ENVIRONMENT=rails50 # rails (= 5.0.0) depends on bundler (< 2.0, >= 1.3.0)
118
123
  - rvm: 2.7.0
119
124
  env: TYPE=UNIT ENVIRONMENT=rails51 # rails (= 5.1.0) depends on bundler (< 2.0, >= 1.3.0)
125
+ - rvm: 2.7.0
126
+ env: TYPE=UNIT ENVIRONMENT=rails52 # rails (= 5.2.0) depends on bundler (< 2.0, >= 1.3.0)
120
127
  - rvm: 2.7.0
121
128
  env: TYPE=FUNCTIONAL GROUP=api # blocked: https://github.com/solnic/coercible/issues/27
122
129
  - rvm: 2.7.0
@@ -128,6 +135,8 @@ matrix:
128
135
  env: TYPE=UNIT ENVIRONMENT=rails50 # rails (= 5.0.0) depends on bundler (< 2.0, >= 1.3.0)
129
136
  - rvm: 2.7.0
130
137
  env: TYPE=UNIT ENVIRONMENT=rails51 # rails (= 5.1.0) depends on bundler (< 2.0, >= 1.3.0)
138
+ - rvm: 2.7.0
139
+ env: TYPE=UNIT ENVIRONMENT=rails52 # rails (= 5.2.0) depends on bundler (< 2.0, >= 1.3.0)
131
140
  - rvm: 2.7.0
132
141
  env: TYPE=FUNCTIONAL GROUP=api # blocked: https://github.com/solnic/coercible/issues/27
133
142
  - rvm: 2.7.0
@@ -184,6 +193,8 @@ matrix:
184
193
  env: TYPE=UNIT ENVIRONMENT=rails50
185
194
  - rvm: 2.1.10
186
195
  env: TYPE=UNIT ENVIRONMENT=rails51
196
+ - rvm: 2.1.10
197
+ env: TYPE=UNIT ENVIRONMENT=rails52
187
198
  - rvm: 2.1.10
188
199
  env: TYPE=UNIT ENVIRONMENT=rails60
189
200
 
@@ -192,6 +203,8 @@ matrix:
192
203
  env: TYPE=UNIT ENVIRONMENT=rails50
193
204
  - rvm: 2.0.0-p648
194
205
  env: TYPE=UNIT ENVIRONMENT=rails51
206
+ - rvm: 2.0.0-p648
207
+ env: TYPE=UNIT ENVIRONMENT=rails52
195
208
  - rvm: 2.0.0-p648
196
209
  env: TYPE=UNIT ENVIRONMENT=rails60
197
210
 
@@ -208,3 +221,5 @@ matrix:
208
221
  env: TYPE=UNIT ENVIRONMENT=rails41
209
222
  - rvm: jruby-9.2.6.0
210
223
  env: TYPE=UNIT ENVIRONMENT=rails60
224
+ - rvm: jruby-9.2.6.0
225
+ env: TYPE=UNIT ENVIRONMENT=rails52
@@ -1,5 +1,59 @@
1
1
  # New Relic Ruby Agent Release Notes #
2
2
 
3
+ ## v6.10.0
4
+
5
+ * **Error attributes now added to each span that exits with an error or exception**
6
+
7
+ Error attributes `error.class` and `error.message` are now included on the span event in which an error
8
+ or exception was noticed, and, in the case of unhandled exceptions, on any ancestor spans that also exit with an error.
9
+ The public API method `notice_error` now attaches these error attributes to the currently executing span.
10
+
11
+ <a href="https://docs.newrelic.com/docs/apm/distributed-tracing/ui-data/understand-use-distributed-tracing-data#rules-limits">Spans with error details are now highlighted red in the Distributed Tracing UI</a>, and error details will expose the associated
12
+ `error.class` and `error.message`. It is also now possible to see when an exception leaves the boundary of the span,
13
+ and if it is caught in an ancestor span without reaching the entry span. NOTE: This “bubbling up” of exceptions will impact
14
+ the error count when compared to prior behavior for the same trace. It is possible to have a trace that now has span errors
15
+ without the trace level showing an error.
16
+
17
+ If multiple errors occur on the same span, only the most recent error information is added to the attributes. Prior errors on the same span are overwritten.
18
+
19
+ These span event attributes conform to <a href="https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/manage-errors-apm-collect-ignore-or-mark-expected#ignore">ignored errors</a> and <a href="https://docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/manage-errors-apm-collect-ignore-or-mark-expected#expected">expected errors</a>.
20
+
21
+ * **Added tests for latest Grape / Rack combination**
22
+
23
+ For a short period of time, the latest versions of Grape and Rack had compatibility issues.
24
+ Generally, Rack 2.1.0 should be avoided in all cases due to breaking changes in many gems
25
+ reliant on Rack. We recommend using either Rack <= 2.0.9, or using latest Rack when using Grape
26
+ (2.2.2 at the time of this writing).
27
+
28
+ * **Bugfix: Calculate Content-Length in bytes**
29
+
30
+ Previously, the Content-Length HTTP header would be incorrect after injecting the Browser Monitoring
31
+ JS when the response contained Unicode characters because the value was not calculated in bytes.
32
+ The Content-Length is now correctly updated.
33
+
34
+ Thanks to thaim for the contribution!
35
+
36
+ * **Bugfix: Fix Content-Length calculation when response is nil**
37
+
38
+ Previously, calculating the Content-Length HTTP header would result in a `NoMethodError` in the case of
39
+ a nil response. These errors will no longer occur in such a case.
40
+
41
+ Thanks to Johan Van Ryseghem for the contribution!
42
+
43
+ * **Bugfix: DecoratingFormatter now logs timestamps as millisecond Integers**
44
+
45
+ Previously the agent sent timestamps as a Float with milliseconds as part of the
46
+ fractional value. Logs in Context was changed to only accept Integer values and this
47
+ release changes DecoratingFormatter to match.
48
+
49
+ * **Added --force option to `newrelic install` cli command to allow overwriting newrelic.yml**
50
+
51
+ * **Bugfix: The fully qualified hostname now works correctly for BSD and Solaris**
52
+
53
+ Previously, when running on systems such as BSD and Solaris, the agent was unable to determine the fully
54
+ qualified domain name, which is used to help link Ruby agent data with data from New Relic Infrastructure.
55
+ This information is now successfully collected on various BSD distros and Solaris.
56
+
3
57
  ## v6.9.0
4
58
 
5
59
  * **Added support for W3C Trace Context, with easy upgrade from New Relic trace context**
@@ -34,7 +88,7 @@
34
88
 
35
89
  Known Issues and Workarounds
36
90
 
37
- * If a .NET agent is initiating traces as the root service, do not upgrade your
91
+ * If a .NET agent is initiating traces as the root service, do not upgrade your
38
92
  downstream Ruby New Relic agents to this agent release.
39
93
 
40
94
  * **Official Ruby 2.7 support**
@@ -43,10 +97,10 @@
43
97
 
44
98
  * **Reduced allocations when tracing transactions using API calls**
45
99
 
46
- Default empty hashes for `options` parameter were not frozen, leading to
100
+ Default empty hashes for `options` parameter were not frozen, leading to
47
101
  excessive and unnecessary allocations when calling APIs for tracing transactions.
48
102
 
49
- Thanks to Joel Turkel (jturkel) for the contribution!
103
+ Thanks to Joel Turkel (jturkel) for the contribution!
50
104
 
51
105
  * **Bugfix for Resque worker thread race conditions**
52
106
 
@@ -56,10 +110,10 @@
56
110
  Thanks to Bertrand Paquet (bpaquet) for the contribution!
57
111
 
58
112
  * **Bugfix for Content-Length when injecting Browser Monitoring JS**
59
-
113
+
60
114
  The Content-Length HTTP header would be incorrect after injecting the Browser Monitoring
61
115
  JS into the HEAD tag of the HTML source with Content-Length and lead to the HTML BODY content
62
- being truncated in some cases. The Content-Length is now correctly updated after injecting the
116
+ being truncated in some cases. The Content-Length is now correctly updated after injecting the
63
117
  Browser Monitoring JS script.
64
118
 
65
119
  Thanks to Slava Kardakov (ojab) for the contribution!
@@ -30,6 +30,7 @@ module NewRelic
30
30
  require 'new_relic/metric_spec'
31
31
  require 'new_relic/metric_data'
32
32
  require 'new_relic/noticed_error'
33
+ require 'new_relic/agent/noticible_error'
33
34
  require 'new_relic/supportability_helper'
34
35
 
35
36
  require 'new_relic/agent/encoding_normalizer'
@@ -671,8 +672,8 @@ module NewRelic
671
672
  # @param [String] method the name of the finder method or other method to
672
673
  # identify the operation with.
673
674
  #
674
- def with_database_metric_name(model, method = nil, product = nil, &block) #THREAD_LOCAL_ACCESS
675
- if txn = Transaction.tl_current
675
+ def with_database_metric_name(model, method = nil, product = nil, &block)
676
+ if txn = Tracer.current_transaction
676
677
  txn.with_database_metric_name(model, method, product, &block)
677
678
  else
678
679
  yield
@@ -134,7 +134,7 @@ module NewRelic
134
134
  # and request before/after from Rack.
135
135
  attr_reader :events
136
136
 
137
- # listens and responds to events that need to process headers
137
+ # listens and responds to events that need to process headers
138
138
  # for synthetics and distributed tracing
139
139
  attr_reader :monitors
140
140
  # Transaction and metric renaming rules as provided by the
@@ -249,7 +249,7 @@ module NewRelic
249
249
  # Wait the end of the event loop thread.
250
250
  if @worker_thread
251
251
  unless @worker_thread.join(3)
252
- ::NewRelic::Agent.logger.error "Event loop thread did not stop within 3 seconds"
252
+ ::NewRelic::Agent.logger.debug "Event loop thread did not stop within 3 seconds"
253
253
  end
254
254
  end
255
255
  end
@@ -12,7 +12,7 @@ module NewRelic
12
12
  end
13
13
 
14
14
  def self.is_monitoring_enabled?
15
- defined?(::Mongo::Monitoring)
15
+ defined?(::Mongo::Monitoring) # @since 2.1.0
16
16
  end
17
17
 
18
18
  def self.is_unsupported_2x?
@@ -117,7 +117,7 @@ module NewRelic
117
117
  result << DELIMITER << (id || NewRelic::EMPTY_STR)
118
118
  result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
119
119
  result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
120
- result << DELIMITER << priority.to_s
120
+ result << DELIMITER << sprintf("%.6f", priority)
121
121
  result << DELIMITER << timestamp.to_s
122
122
  result
123
123
  end
@@ -32,7 +32,6 @@ module NewRelic
32
32
  end
33
33
  end
34
34
 
35
-
36
35
  def initialize_ignored_errors(ignore_errors)
37
36
  @ignore.clear
38
37
  ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
@@ -117,14 +116,22 @@ module NewRelic
117
116
  NewRelic::LanguageSupport.jruby? && exception.respond_to?(:java_class)
118
117
  end
119
118
 
120
- def exception_tagged?(exception)
119
+ def exception_tagged_with?(ivar, exception)
121
120
  return false if exception_is_java_object?(exception)
122
- exception.instance_variable_defined?(EXCEPTION_TAG_IVAR)
121
+ exception.instance_variable_defined?(ivar)
122
+ end
123
+
124
+ def tag_exception_using(ivar, exception)
125
+ return if exception_is_java_object?(exception) || exception.frozen?
126
+ begin
127
+ exception.instance_variable_set(ivar, true)
128
+ rescue => e
129
+ NewRelic::Agent.logger.warn("Failed to tag exception: #{exception}: ", e)
130
+ end
123
131
  end
124
132
 
125
133
  def tag_exception(exception)
126
- return if exception_is_java_object?(exception)
127
- return if exception.frozen?
134
+ return if exception_is_java_object?(exception) || exception.frozen?
128
135
  begin
129
136
  exception.instance_variable_set(EXCEPTION_TAG_IVAR, true)
130
137
  rescue => e
@@ -169,9 +176,9 @@ module NewRelic
169
176
 
170
177
  def skip_notice_error?(exception)
171
178
  disabled? ||
172
- error_is_ignored?(exception) ||
173
- exception.nil? ||
174
- exception_tagged?(exception)
179
+ error_is_ignored?(exception) ||
180
+ exception.nil? ||
181
+ exception_tagged_with?(EXCEPTION_TAG_IVAR, exception)
175
182
  end
176
183
 
177
184
  # calls a method on an object, if it responds to it - used for
@@ -191,8 +198,18 @@ module NewRelic
191
198
  sense_method(actual_exception, :backtrace) || '<no stack trace>'
192
199
  end
193
200
 
201
+ def notice_segment_error(segment, exception, options={})
202
+ return if skip_notice_error?(exception)
203
+
204
+ segment.set_noticed_error create_noticed_error(exception, options)
205
+ exception
206
+ rescue => e
207
+ ::NewRelic::Agent.logger.warn("Failure when capturing segment error '#{exception}':", e)
208
+ nil
209
+ end
210
+
194
211
  # See NewRelic::Agent.notice_error for options and commentary
195
- def notice_error(exception, options={}) #THREAD_LOCAL_ACCESS
212
+ def notice_error(exception, options={}, span_id=nil)
196
213
  return if skip_notice_error?(exception)
197
214
 
198
215
  tag_exception(exception)
@@ -205,8 +222,10 @@ module NewRelic
205
222
 
206
223
  noticed_error = create_noticed_error(exception, options)
207
224
  error_trace_aggregator.add_to_error_queue(noticed_error)
208
- payload = state.current_transaction ? state.current_transaction.payload : nil
209
- error_event_aggregator.record(noticed_error, payload)
225
+ transaction = state.current_transaction
226
+ payload = transaction ? transaction.payload : nil
227
+ span_id ||= (transaction && transaction.current_segment) ? transaction.current_segment.guid : nil
228
+ error_event_aggregator.record(noticed_error, payload, span_id)
210
229
  exception
211
230
  rescue => e
212
231
  ::NewRelic::Agent.logger.warn("Failure when capturing error '#{exception}':", e)
@@ -19,14 +19,14 @@ module NewRelic
19
19
  :'error_collector.capture_events'
20
20
  buffer_class PrioritySampledBuffer
21
21
 
22
- def record noticed_error, transaction_payload = nil
22
+ def record noticed_error, transaction_payload = nil, span_id = nil
23
23
  return unless enabled?
24
24
 
25
25
  priority = float!((transaction_payload && transaction_payload[:priority]) || rand)
26
26
 
27
27
  @lock.synchronize do
28
28
  @buffer.append(priority: priority) do
29
- create_event(noticed_error, transaction_payload)
29
+ create_event(noticed_error, transaction_payload, span_id)
30
30
  end
31
31
  notify_if_full
32
32
  end
@@ -34,8 +34,8 @@ module NewRelic
34
34
 
35
35
  private
36
36
 
37
- def create_event noticed_error, transaction_payload
38
- TransactionErrorPrimitive.create noticed_error, transaction_payload
37
+ def create_event noticed_error, transaction_payload, span_id
38
+ TransactionErrorPrimitive.create noticed_error, transaction_payload, span_id
39
39
  end
40
40
  end
41
41
  end
@@ -17,8 +17,14 @@ module NewRelic
17
17
  end
18
18
  end
19
19
 
20
+ # calling hostname with -f on some OS's (NetBSD, FreeBSD, Solaris)
21
+ # produces invalid option error, but doesn't raise exception. Instead,
22
+ # we get back empty string. So, solution here is to check for non-zero
23
+ # exit status and retry the command without the -f flag.
20
24
  def self.get_fqdn
21
- %x[hostname -f].chomp!
25
+ fqdn = %x[hostname -f].chomp!
26
+ fqdn = %x[hostname].chomp! unless $?.exitstatus.zero?
27
+ fqdn
22
28
  rescue => e
23
29
  NewRelic::Agent.logger.debug "Unable to determine fqdn #{e}"
24
30
  nil
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ # frozen_string_literal: true
5
+
6
+ module NewRelic
7
+ module Agent
8
+ module HTTPClients
9
+ MUST_IMPLEMENT_ERROR = "Subclasses of %s must implement a :%s method"
10
+ WHINY_NIL_ERROR = "%s cannot initialize with a nil wrapped_response object."
11
+
12
+ # This class provides a public interface for wrapping HTTP requests. This
13
+ # may be used to create wrappers that are compatible with New Relic's
14
+ # external request API.
15
+ #
16
+ # @api public
17
+ class AbstractRequest
18
+
19
+ def []
20
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
21
+ end
22
+
23
+ def []=
24
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
25
+ end
26
+
27
+ def type
28
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
29
+ end
30
+
31
+ def host_from_header
32
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
33
+ end
34
+
35
+ def host
36
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
37
+ end
38
+
39
+ def method
40
+ raise NotImplementedError, MUST_IMPLEMENT_ERROR % [self.class, __method__]
41
+ end
42
+ end
43
+
44
+ # This class implements the adaptor pattern and is used internally provide
45
+ # uniform access to the underlying HTTP Client's response object
46
+ # NOTE: response_object should be non-nil!
47
+ class AbstractResponse # :nodoc:
48
+
49
+ def initialize wrapped_response
50
+ if wrapped_response.nil?
51
+ raise ArgumentError, WHINY_NIL_ERROR % self.class
52
+ end
53
+ @wrapped_response = wrapped_response
54
+ end
55
+
56
+ def has_status_code?
57
+ !!status_code
58
+ end
59
+
60
+ # most HTTP client libraries report the HTTP status code as an integer, so
61
+ # we expect status_code to be set only if a non-zero value is present
62
+ def status_code
63
+ @status_code ||= get_status_code
64
+ end
65
+
66
+ private
67
+
68
+ def get_status_code_using method_name
69
+ return unless @wrapped_response.respond_to?(method_name)
70
+ code = @wrapped_response.send(method_name).to_i
71
+ code == 0 ? nil : code
72
+ end
73
+
74
+ # Override this method to memoize a non-zero Integer representation
75
+ # of HTTP status code from the response object
76
+ def get_status_code
77
+ get_status_code_using :code
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,19 +1,20 @@
1
1
  # encoding: utf-8
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ # frozen_string_literal: true
4
5
 
5
- require 'new_relic/agent/http_clients/abstract_request'
6
+ require_relative 'abstract'
6
7
 
7
8
  module NewRelic
8
9
  module Agent
9
10
  module HTTPClients
10
11
 
11
12
  class CurbRequest
12
- CURB = 'Curb'.freeze
13
- LHOST = 'host'.freeze
14
- UHOST = 'Host'.freeze
13
+ CURB = 'Curb'
14
+ LHOST = 'host'
15
+ UHOST = 'Host'
15
16
 
16
- def initialize( curlobj )
17
+ def initialize curlobj
17
18
  @curlobj = curlobj
18
19
  end
19
20
 
@@ -34,41 +35,45 @@ module NewRelic
34
35
  end
35
36
 
36
37
  def []( key )
37
- @curlobj.headers[ key ]
38
+ @curlobj.headers[key]
38
39
  end
39
40
 
40
- def []=( key, value )
41
- @curlobj.headers[ key ] = value
41
+ def []=(key, value)
42
+ @curlobj.headers[key] = value
42
43
  end
43
44
 
44
45
  def uri
45
- @uri ||= NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@curlobj.url)
46
+ @uri ||= URIUtil.parse_and_normalize_url(@curlobj.url)
46
47
  end
47
48
  end
48
49
 
50
+ class CurbResponse < AbstractResponse
49
51
 
50
- class CurbResponse < AbstractRequest
51
-
52
- def initialize(curlobj)
52
+ def initialize wrapped_response
53
+ super wrapped_response
53
54
  @headers = {}
54
- @curlobj = curlobj
55
55
  end
56
56
 
57
57
  def [](key)
58
- @headers[ key.downcase ]
58
+ @headers[key.downcase]
59
59
  end
60
60
 
61
61
  def to_hash
62
62
  @headers.dup
63
63
  end
64
64
 
65
- def append_header_data( data )
66
- key, value = data.split( /:\s*/, 2 )
67
- @headers[ key.downcase ] = value
68
- @curlobj._nr_header_str ||= ''
69
- @curlobj._nr_header_str << data
65
+ def append_header_data data
66
+ key, value = data.split(/:\s*/, 2)
67
+ @headers[key.downcase] = value
68
+ @wrapped_response._nr_header_str ||= String.new
69
+ @wrapped_response._nr_header_str << data
70
70
  end
71
71
 
72
+ private
73
+
74
+ def get_status_code
75
+ get_status_code_using :response_code
76
+ end
72
77
  end
73
78
 
74
79
  end