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
@@ -1,20 +1,21 @@
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
- class ExconHTTPResponse
11
- def initialize(response)
12
- @response = response
11
+ class ExconHTTPResponse < AbstractResponse
12
+ def initialize wrapped_response
13
+ super wrapped_response
14
+
13
15
  # Since HTTP headers are case-insensitive, we normalize all of them to
14
16
  # upper case here, and then also in our [](key) implementation.
15
17
  @normalized_headers = {}
16
- headers = response.respond_to?(:headers) ? response.headers : response[:headers]
17
- (headers || {}).each do |key, val|
18
+ (get_attribute(:headers) || {}).each do |key, val|
18
19
  @normalized_headers[key.upcase] = val
19
20
  end
20
21
  end
@@ -26,15 +27,30 @@ module NewRelic
26
27
  def to_hash
27
28
  @normalized_headers.dup
28
29
  end
30
+
31
+ private
32
+
33
+ def get_attribute name
34
+ if @wrapped_response.respond_to?(name)
35
+ @wrapped_response.send(name)
36
+ else
37
+ @wrapped_response[name]
38
+ end
39
+ end
40
+
41
+ def get_status_code
42
+ code = get_attribute(:status).to_i
43
+ code == 0 ? nil : code
44
+ end
29
45
  end
30
46
 
31
47
  class ExconHTTPRequest < AbstractRequest
32
48
  attr_reader :method
33
49
 
34
- EXCON = "Excon".freeze
35
- LHOST = 'host'.freeze
36
- UHOST = 'Host'.freeze
37
- COLON = ':'.freeze
50
+ EXCON = "Excon"
51
+ LHOST = 'host'
52
+ UHOST = 'Host'
53
+ COLON = ':'
38
54
 
39
55
  def initialize(datum)
40
56
  @datum = datum
@@ -70,9 +86,8 @@ module NewRelic
70
86
  end
71
87
 
72
88
  def uri
73
- ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(
74
- "#{@scheme}://#{host}:#{@port}#{@path}"
75
- )
89
+ url = "#{@scheme}://#{host}:#{@port}#{@path}"
90
+ URIUtil.parse_and_normalize_url url
76
91
  end
77
92
  end
78
93
  end
@@ -1,39 +1,35 @@
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
- class HTTPResponse
11
- attr_reader :response
12
-
13
- def initialize(response)
14
- @response = response
15
- end
16
-
11
+ class HTTPResponse < AbstractResponse
17
12
  def [](key)
18
- _, value = response.headers.find { |k,_| key.downcase == k.downcase }
13
+ _, value = @wrapped_response.headers.find{ |k, _| key.downcase == k.downcase }
19
14
  value unless value.nil?
20
15
  end
21
16
 
22
17
  def to_hash
23
- response.headers
18
+ @wrapped_response.headers
24
19
  end
25
20
  end
26
21
 
27
22
  class HTTPRequest < AbstractRequest
28
- HTTP_RB = 'http.rb'.freeze
29
- HOST = 'host'.freeze
30
- COLON = ':'.freeze
23
+ HTTP_RB = 'http.rb'
24
+ HOST = 'host'
25
+ COLON = ':'
31
26
 
32
- attr_reader :request, :uri
27
+ def initialize wrapped_request
28
+ @wrapped_request = wrapped_request
29
+ end
33
30
 
34
- def initialize(request)
35
- @request = request
36
- @uri = request.uri
31
+ def uri
32
+ @uri ||= URIUtil.parse_and_normalize_url(@wrapped_request.uri)
37
33
  end
38
34
 
39
35
  def type
@@ -47,19 +43,19 @@ module NewRelic
47
43
  end
48
44
 
49
45
  def host
50
- host_from_header || request.host
46
+ host_from_header || @wrapped_request.host
51
47
  end
52
48
 
53
49
  def method
54
- request.verb.upcase
50
+ @wrapped_request.verb.upcase
55
51
  end
56
52
 
57
53
  def [](key)
58
- request.headers[key]
54
+ @wrapped_request.headers[key]
59
55
  end
60
56
 
61
57
  def []=(key, value)
62
- request.headers[key] = value
58
+ @wrapped_request.headers[key] = value
63
59
  end
64
60
  end
65
61
  end
@@ -1,21 +1,17 @@
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
- class HTTPClientResponse
11
- attr_reader :response
12
-
13
- def initialize(response)
14
- @response = response
15
- end
11
+ class HTTPClientResponse < AbstractResponse
16
12
 
17
13
  def [](key)
18
- response.headers.each do |k,v|
14
+ @wrapped_response.headers.each do |k,v|
19
15
  if key.downcase == k.downcase
20
16
  return v
21
17
  end
@@ -24,12 +20,12 @@ module NewRelic
24
20
  end
25
21
 
26
22
  def to_hash
27
- response.headers
23
+ @wrapped_response.headers
28
24
  end
29
25
  end
30
26
 
31
27
  class HTTPClientRequest < AbstractRequest
32
- attr_reader :request, :uri
28
+ attr_reader :request
33
29
 
34
30
  HTTP_CLIENT = "HTTPClient".freeze
35
31
  LHOST = 'host'.freeze
@@ -38,7 +34,6 @@ module NewRelic
38
34
 
39
35
  def initialize(request)
40
36
  @request = request
41
- @uri = request.header.request_uri
42
37
  end
43
38
 
44
39
  def type
@@ -59,6 +54,10 @@ module NewRelic
59
54
  host_from_header || uri.host.to_s
60
55
  end
61
56
 
57
+ def uri
58
+ @uri ||= URIUtil.parse_and_normalize_url(request.header.request_uri)
59
+ end
60
+
62
61
  def [](key)
63
62
  request.headers[key]
64
63
  end
@@ -1,26 +1,38 @@
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
11
+ class NetHTTPResponse < AbstractResponse
12
+
13
+ def [](key)
14
+ @wrapped_response[key]
15
+ end
16
+
17
+ def to_hash
18
+ @wrapped_response.to_hash
19
+ end
20
+ end
21
+
10
22
  class NetHTTPRequest < AbstractRequest
11
23
  def initialize(connection, request)
12
24
  @connection = connection
13
25
  @request = request
14
26
  end
15
27
 
16
- NET_HTTP = 'Net::HTTP'.freeze
28
+ NET_HTTP = 'Net::HTTP'
17
29
 
18
30
  def type
19
31
  NET_HTTP
20
32
  end
21
33
 
22
- HOST = 'host'.freeze
23
- COLON = ':'.freeze
34
+ HOST = 'host'
35
+ COLON = ':'
24
36
 
25
37
  def host_from_header
26
38
  if hostname = self[HOST]
@@ -1,16 +1,14 @@
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
- class TyphoeusHTTPResponse
11
- def initialize(response)
12
- @response = response
13
- end
11
+ class TyphoeusHTTPResponse < AbstractResponse
14
12
 
15
13
  def [](key)
16
14
  unless headers.nil?
@@ -33,7 +31,7 @@ module NewRelic
33
31
  private
34
32
 
35
33
  def headers
36
- @response.headers
34
+ @wrapped_response.headers
37
35
  end
38
36
  end
39
37
 
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
4
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+ # frozen_string_literal: true
5
6
 
6
7
  # This module includes utilities for manipulating URIs, particularly from the
7
8
  # context of Net::HTTP requests. We don't always have direct access to the full
@@ -41,10 +42,10 @@ module NewRelic
41
42
  uri
42
43
  end
43
44
 
44
- QUESTION_MARK = "?".freeze
45
+ QUESTION_MARK = "?"
45
46
 
46
47
  def self.strip_query_string(fragment)
47
- if(fragment.include?(QUESTION_MARK))
48
+ if fragment.include? QUESTION_MARK
48
49
  fragment.split(QUESTION_MARK).first
49
50
  else
50
51
  fragment
@@ -29,7 +29,10 @@ module NewRelic
29
29
  def finish(name, id, payload) #THREAD_LOCAL_ACCESS
30
30
  return unless state.is_execution_traced?
31
31
 
32
- notice_error payload if payload.key? :exception
32
+ if exception = exception_object(payload)
33
+ NewRelic::Agent.notice_error exception
34
+ end
35
+
33
36
  finishable = pop_segment(id)
34
37
  finishable.finish if finishable
35
38
  rescue => e
@@ -51,10 +54,6 @@ module NewRelic
51
54
  def action_name(name)
52
55
  name.gsub DOT_ACTION_CABLE, NewRelic::EMPTY_STR
53
56
  end
54
-
55
- def notice_error(payload)
56
- NewRelic::Agent.notice_error payload[:exception_object]
57
- end
58
57
  end
59
58
  end
60
59
  end
@@ -35,6 +35,10 @@ module NewRelic
35
35
  if state.is_execution_traced? \
36
36
  && !should_ignore(payload, controller_class(payload))
37
37
 
38
+ if exception = exception_object(payload)
39
+ finishable.notice_error(exception)
40
+ end
41
+
38
42
  finishable.finish
39
43
  else
40
44
  Agent.instance.pop_trace_execution_flag
@@ -24,8 +24,13 @@ module NewRelic
24
24
  end
25
25
 
26
26
  def finish(name, id, payload) #THREAD_LOCAL_ACCESS
27
- event = pop_segment(id)
28
- event.finish if event
27
+ if segment = pop_segment(id)
28
+
29
+ if exception = exception_object(payload)
30
+ segment.notice_error exception
31
+ end
32
+ segment.finish
33
+ end
29
34
  rescue => e
30
35
  log_notification_error(e, name, 'finish')
31
36
  end
@@ -97,6 +102,10 @@ module NewRelic
97
102
  def finish
98
103
  @finishable.finish if @finishable
99
104
  end
105
+
106
+ def notice_error error
107
+ @finishable.notice_error error if @finishable
108
+ end
100
109
  end
101
110
  end
102
111
 
@@ -43,7 +43,7 @@ module NewRelic
43
43
  end
44
44
  end
45
45
 
46
- def log_with_newrelic_instrumentation(*args, &block) #THREAD_LOCAL_ACCESS
46
+ def log_with_newrelic_instrumentation(*args, &block)
47
47
  state = NewRelic::Agent::Tracer.state
48
48
 
49
49
  if !state.is_execution_traced?
@@ -78,7 +78,9 @@ module NewRelic
78
78
  segment._notice_sql(sql, @config, EXPLAINER)
79
79
 
80
80
  begin
81
- log_without_newrelic_instrumentation(*args, &block)
81
+ NewRelic::Agent::Tracer.capture_segment_error segment do
82
+ log_without_newrelic_instrumentation(*args, &block)
83
+ end
82
84
  ensure
83
85
  segment.finish if segment
84
86
  end
@@ -58,8 +58,13 @@ module NewRelic
58
58
  return if cached?(payload)
59
59
  return unless state.is_execution_traced?
60
60
 
61
- segment = pop_segment(id)
62
- segment.finish if segment
61
+ if segment = pop_segment(id)
62
+ if exception = exception_object(payload)
63
+ segment.notice_error(exception)
64
+ end
65
+ segment.finish
66
+ end
67
+
63
68
  rescue => e
64
69
  log_notification_error(e, name, 'finish')
65
70
  end
@@ -16,7 +16,7 @@ module NewRelic
16
16
 
17
17
  def finish name, id, payload
18
18
  return unless state.is_execution_traced?
19
- finish_segment id
19
+ finish_segment id, payload
20
20
  rescue => e
21
21
  log_notification_error e, name, 'finish'
22
22
  end
@@ -28,9 +28,13 @@ module NewRelic
28
28
  push_segment id, segment
29
29
  end
30
30
 
31
- def finish_segment id
32
- segment = pop_segment id
33
- segment.finish if segment
31
+ def finish_segment id, payload
32
+ if segment = pop_segment(id)
33
+ if exception = exception_object(payload)
34
+ segment.notice_error(exception)
35
+ end
36
+ segment.finish
37
+ end
34
38
  end
35
39
 
36
40
  def metric_name name, payload
@@ -1,6 +1,7 @@
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
6
  DependencyDetection.defer do
6
7
  named :bunny
@@ -41,10 +42,11 @@ DependencyDetection.defer do
41
42
  )
42
43
  rescue => e
43
44
  NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Exchange#publish", e
44
- end
45
-
46
- begin
47
45
  publish_without_new_relic payload, opts
46
+ else
47
+ NewRelic::Agent::Tracer.capture_segment_error segment do
48
+ publish_without_new_relic payload, opts
49
+ end
48
50
  ensure
49
51
  segment.finish if segment
50
52
  end
@@ -55,28 +57,40 @@ DependencyDetection.defer do
55
57
  alias_method :pop_without_new_relic, :pop
56
58
 
57
59
  def pop(opts = {:manual_ack => false}, &block)
58
- t0 = Time.now
59
- msg = pop_without_new_relic opts, &block
60
- delivery_info, message_properties, _payload = msg
60
+ bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
61
+ begin
62
+ t0 = Time.now
63
+ msg = pop_without_new_relic opts, &block
64
+ delivery_info, message_properties, _payload = msg
65
+ rescue StandardError => error
66
+ bunny_error = error
67
+ end
61
68
 
62
69
  begin
63
- if delivery_info
64
- exchange_name = NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange)
65
- exchange_type = NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel)
66
-
67
- segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
68
- library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
69
- destination_name: exchange_name,
70
- delivery_info: delivery_info,
71
- message_properties: message_properties,
72
- exchange_type: exchange_type,
73
- queue_name: name,
74
- start_time: t0
75
- )
70
+ exchange_name, exchange_type = if delivery_info
71
+ [ NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange),
72
+ NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel) ]
73
+ else
74
+ [ NewRelic::Agent::Instrumentation::Bunny.exchange_name(NewRelic::EMPTY_STR),
75
+ NewRelic::Agent::Instrumentation::Bunny.exchange_type({}, channel) ]
76
76
  end
77
77
 
78
+ segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
79
+ library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
80
+ destination_name: exchange_name,
81
+ delivery_info: (delivery_info || {}),
82
+ message_properties: (message_properties || {headers: {}}),
83
+ exchange_type: exchange_type,
84
+ queue_name: name,
85
+ start_time: t0
86
+ )
78
87
  rescue => e
79
88
  NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#pop", e
89
+ else
90
+ if bunny_error
91
+ segment.notice_error bunny_error
92
+ raise bunny_error
93
+ end
80
94
  ensure
81
95
  segment.finish if segment
82
96
  end
@@ -97,10 +111,11 @@ DependencyDetection.defer do
97
111
  )
98
112
  rescue => e
99
113
  NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#purge", e
100
- end
101
-
102
- begin
103
114
  purge_without_new_relic(*args)
115
+ else
116
+ NewRelic::Agent::Tracer.capture_segment_error segment do
117
+ purge_without_new_relic(*args)
118
+ end
104
119
  ensure
105
120
  segment.finish if segment
106
121
  end
@@ -134,18 +149,20 @@ module NewRelic
134
149
  module Agent
135
150
  module Instrumentation
136
151
  module Bunny
137
- LIBRARY = 'RabbitMQ'.freeze
138
- DEFAULT = 'Default'.freeze
139
- SLASH = '/'.freeze
152
+ LIBRARY = 'RabbitMQ'
153
+ DEFAULT_NAME = 'Default'
154
+ DEFAULT_TYPE = :direct
155
+
156
+ SLASH = '/'
140
157
 
141
158
  class << self
142
159
  def exchange_name name
143
- name.empty? ? DEFAULT : name
160
+ name.empty? ? DEFAULT_NAME : name
144
161
  end
145
162
 
146
163
  def exchange_type delivery_info, channel
147
164
  if di_exchange = delivery_info[:exchange]
148
- return :direct if di_exchange.empty?
165
+ return DEFAULT_TYPE if di_exchange.empty?
149
166
  return channel.exchanges[delivery_info[:exchange]].type if channel.exchanges[di_exchange]
150
167
  end
151
168
  end