newrelic_rpm 6.6.0.358 → 6.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +65 -5
  4. data/CHANGELOG.md +222 -0
  5. data/Gemfile +5 -2
  6. data/Guardfile +18 -1
  7. data/LICENSE +1 -1
  8. data/Rakefile +2 -0
  9. data/lib/new_relic/agent.rb +89 -7
  10. data/lib/new_relic/agent/agent.rb +114 -55
  11. data/lib/new_relic/agent/agent_logger.rb +4 -0
  12. data/lib/new_relic/agent/attribute_filter.rb +7 -7
  13. data/lib/new_relic/agent/attributes.rb +150 -0
  14. data/lib/new_relic/agent/autostart.rb +19 -14
  15. data/lib/new_relic/agent/configuration/default_source.rb +127 -9
  16. data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
  17. data/lib/new_relic/agent/configuration/manager.rb +0 -8
  18. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  19. data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
  20. data/lib/new_relic/agent/connect/request_builder.rb +5 -13
  21. data/lib/new_relic/agent/database.rb +1 -2
  22. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  23. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
  24. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
  25. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  26. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  27. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  28. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  29. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  30. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
  31. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  32. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  33. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  34. data/lib/new_relic/agent/error_collector.rb +33 -16
  35. data/lib/new_relic/agent/error_event_aggregator.rb +7 -5
  36. data/lib/new_relic/agent/external.rb +7 -7
  37. data/lib/new_relic/agent/guid_generator.rb +28 -0
  38. data/lib/new_relic/agent/hostname.rb +7 -1
  39. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  40. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +24 -19
  41. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +28 -13
  42. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +17 -21
  43. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +10 -11
  44. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +16 -4
  45. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -6
  46. data/lib/new_relic/agent/http_clients/uri_util.rb +3 -2
  47. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +5 -7
  48. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -0
  49. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -2
  50. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -2
  51. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +7 -2
  52. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -4
  53. data/lib/new_relic/agent/instrumentation/bunny.rb +45 -28
  54. data/lib/new_relic/agent/instrumentation/curb.rb +59 -18
  55. data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -1
  56. data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
  57. data/lib/new_relic/agent/instrumentation/excon/connection.rb +6 -3
  58. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
  59. data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
  60. data/lib/new_relic/agent/instrumentation/http.rb +6 -3
  61. data/lib/new_relic/agent/instrumentation/httpclient.rb +5 -3
  62. data/lib/new_relic/agent/instrumentation/memcache.rb +3 -1
  63. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +6 -2
  64. data/lib/new_relic/agent/instrumentation/mongo.rb +9 -3
  65. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +13 -0
  66. data/lib/new_relic/agent/instrumentation/net.rb +6 -3
  67. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +25 -1
  68. data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
  69. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  70. data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
  71. data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
  72. data/lib/new_relic/agent/logging.rb +139 -0
  73. data/lib/new_relic/agent/messaging.rb +5 -73
  74. data/lib/new_relic/agent/method_tracer.rb +3 -2
  75. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  76. data/lib/new_relic/agent/monitors.rb +27 -0
  77. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  78. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  79. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +1 -1
  80. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  81. data/lib/new_relic/agent/new_relic_service.rb +7 -5
  82. data/lib/new_relic/agent/noticible_error.rb +22 -0
  83. data/lib/new_relic/agent/span_event_aggregator.rb +1 -0
  84. data/lib/new_relic/agent/span_event_primitive.rb +82 -53
  85. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  86. data/lib/new_relic/agent/supported_versions.rb +2 -2
  87. data/lib/new_relic/agent/tracer.rb +65 -18
  88. data/lib/new_relic/agent/transaction.rb +84 -79
  89. data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
  90. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  91. data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
  92. data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
  93. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  94. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  95. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  96. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  97. data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
  98. data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
  99. data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
  100. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  101. data/lib/new_relic/cli/commands/install.rb +3 -2
  102. data/lib/new_relic/coerce.rb +31 -6
  103. data/lib/new_relic/constants.rb +34 -0
  104. data/lib/new_relic/control/instance_methods.rb +10 -1
  105. data/lib/new_relic/dependency_detection.rb +4 -4
  106. data/lib/new_relic/noticed_error.rb +38 -17
  107. data/lib/new_relic/rack/browser_monitoring.rb +5 -0
  108. data/lib/new_relic/supportability_helper.rb +14 -0
  109. data/lib/new_relic/version.rb +1 -1
  110. data/lib/tasks/multiverse.rb +25 -0
  111. data/lib/tasks/tests.rake +6 -1
  112. data/newrelic_rpm.gemspec +18 -7
  113. data/test/agent_helper.rb +322 -70
  114. metadata +98 -32
  115. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  116. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  117. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  118. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  119. data/lib/tasks/versions.html.erb +0 -28
  120. data/lib/tasks/versions.postface.html +0 -8
  121. data/lib/tasks/versions.preface.html +0 -9
  122. data/lib/tasks/versions.rake +0 -65
  123. data/lib/tasks/versions.txt.erb +0 -14
@@ -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
@@ -47,14 +50,9 @@ module NewRelic
47
50
  end
48
51
 
49
52
  DOT_ACTION_CABLE = '.action_cable'.freeze
50
- EMPTY_STRING = ''.freeze
51
53
 
52
54
  def action_name(name)
53
- name.gsub DOT_ACTION_CABLE, EMPTY_STRING
54
- end
55
-
56
- def notice_error(payload)
57
- NewRelic::Agent.notice_error payload[:exception_object]
55
+ name.gsub DOT_ACTION_CABLE, NewRelic::EMPTY_STR
58
56
  end
59
57
  end
60
58
  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
@@ -11,7 +12,7 @@ DependencyDetection.defer do
11
12
 
12
13
  executes do
13
14
  ::NewRelic::Agent.logger.info 'Installing Bunny instrumentation'
14
- require 'new_relic/agent/cross_app_tracing'
15
+ require 'new_relic/agent/distributed_tracing/cross_app_tracing'
15
16
  require 'new_relic/agent/messaging'
16
17
  require 'new_relic/agent/transaction/message_broker_segment'
17
18
  end
@@ -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