newrelic_rpm 6.5.0.357 → 6.10.0.364

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +65 -5
  4. data/CHANGELOG.md +243 -0
  5. data/Guardfile +18 -1
  6. data/lib/new_relic/agent.rb +89 -7
  7. data/lib/new_relic/agent/agent.rb +116 -57
  8. data/lib/new_relic/agent/agent_logger.rb +4 -0
  9. data/lib/new_relic/agent/attribute_filter.rb +7 -7
  10. data/lib/new_relic/agent/attributes.rb +150 -0
  11. data/lib/new_relic/agent/autostart.rb +19 -14
  12. data/lib/new_relic/agent/configuration/default_source.rb +132 -13
  13. data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
  14. data/lib/new_relic/agent/configuration/manager.rb +13 -9
  15. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  16. data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
  17. data/lib/new_relic/agent/connect/request_builder.rb +5 -13
  18. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  19. data/lib/new_relic/agent/database.rb +1 -2
  20. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  21. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
  22. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
  23. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  24. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  25. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  26. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  27. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  28. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
  29. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  30. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  31. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  32. data/lib/new_relic/agent/error_collector.rb +35 -18
  33. data/lib/new_relic/agent/error_event_aggregator.rb +9 -6
  34. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  35. data/lib/new_relic/agent/event_aggregator.rb +26 -32
  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/rails_notifications/action_cable.rb +2 -3
  69. data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
  70. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  71. data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
  72. data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
  73. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  74. data/lib/new_relic/agent/logging.rb +139 -0
  75. data/lib/new_relic/agent/messaging.rb +5 -73
  76. data/lib/new_relic/agent/method_tracer.rb +3 -2
  77. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  78. data/lib/new_relic/agent/monitors.rb +27 -0
  79. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  80. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  81. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +3 -3
  82. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  83. data/lib/new_relic/agent/new_relic_service.rb +7 -5
  84. data/lib/new_relic/agent/noticible_error.rb +22 -0
  85. data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
  86. data/lib/new_relic/agent/span_event_primitive.rb +82 -53
  87. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  88. data/lib/new_relic/agent/supported_versions.rb +2 -2
  89. data/lib/new_relic/agent/tracer.rb +65 -18
  90. data/lib/new_relic/agent/transaction.rb +84 -79
  91. data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
  92. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  93. data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
  94. data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
  95. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  96. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  97. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  98. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  99. data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
  100. data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
  101. data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
  102. data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
  103. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  104. data/lib/new_relic/cli/commands/install.rb +3 -2
  105. data/lib/new_relic/coerce.rb +31 -6
  106. data/lib/new_relic/constants.rb +34 -0
  107. data/lib/new_relic/control/instance_methods.rb +10 -1
  108. data/lib/new_relic/dependency_detection.rb +4 -4
  109. data/lib/new_relic/noticed_error.rb +38 -17
  110. data/lib/new_relic/rack/browser_monitoring.rb +5 -0
  111. data/lib/new_relic/supportability_helper.rb +14 -0
  112. data/lib/new_relic/version.rb +1 -1
  113. data/lib/tasks/multiverse.rb +25 -0
  114. data/lib/tasks/tests.rake +6 -1
  115. data/newrelic_rpm.gemspec +16 -5
  116. data/test/agent_helper.rb +329 -70
  117. data/true +0 -0
  118. metadata +98 -30
  119. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  120. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  121. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  122. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  123. data/lib/tasks/versions.html.erb +0 -28
  124. data/lib/tasks/versions.postface.html +0 -8
  125. data/lib/tasks/versions.preface.html +0 -9
  126. data/lib/tasks/versions.rake +0 -65
  127. data/lib/tasks/versions.txt.erb +0 -14
@@ -20,15 +20,15 @@ module NewRelic
20
20
  attr_reader :obfuscator
21
21
 
22
22
  def initialize(events)
23
- events.subscribe(:finished_configuring) do
24
- # This requires :encoding_key, so must wait until :finished_configuring
23
+ events.subscribe(:initial_configuration_complete) do
24
+ # This requires :encoding_key, so must wait until :initial_configuration_complete
25
25
  setup_obfuscator
26
26
  on_finished_configuring(events)
27
27
  end
28
28
  end
29
29
 
30
30
  def setup_obfuscator
31
- @obfuscator = NewRelic::Agent::Obfuscator.new(NewRelic::Agent.config[:encoding_key])
31
+ @obfuscator = Obfuscator.new(Agent.config[:encoding_key])
32
32
  end
33
33
 
34
34
  def deserialize_header(encoded_header, key)
@@ -2,8 +2,6 @@
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
4
 
5
- require 'new_relic/agent/inbound_request_monitor'
6
-
7
5
  module NewRelic
8
6
  module Agent
9
7
  class SyntheticsMonitor < InboundRequestMonitor
@@ -40,7 +38,7 @@ module NewRelic
40
38
 
41
39
  def is_trusted?(incoming_payload)
42
40
  account_id = incoming_payload[1]
43
- NewRelic::Agent.config[:trusted_account_ids].include?(account_id)
41
+ Agent.config[:trusted_account_ids].include?(account_id)
44
42
  end
45
43
 
46
44
  def is_valid_payload?(incoming_payload)
@@ -48,7 +46,7 @@ module NewRelic
48
46
  end
49
47
 
50
48
  def reject_messaging_synthetics_header headers
51
- headers.reject {|k,_| k == NewRelic::Agent::CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
49
+ headers.reject {|k,_| k == CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
52
50
  end
53
51
 
54
52
  end
@@ -92,14 +92,16 @@ module NewRelic
92
92
  token = Agent.config[:security_policies_token]
93
93
 
94
94
  if token && !token.empty?
95
- response = invoke_remote(:preconnect, [{'security_policies_token' => token}])
95
+ response = invoke_remote(:preconnect, [{'security_policies_token' => token, 'high_security' => false}])
96
96
 
97
97
  validator = SecurityPolicySettings::Validator.new(response)
98
98
  validator.validate_matching_agent_config!
99
99
 
100
100
  response
101
+ elsif Agent.config[:high_security]
102
+ invoke_remote(:preconnect, [{'high_security' => true}])
101
103
  else
102
- invoke_remote(:preconnect, [])
104
+ invoke_remote(:preconnect, [{'high_security' => false}])
103
105
  end
104
106
  end
105
107
 
@@ -196,10 +198,10 @@ module NewRelic
196
198
  encoding = 'identity'
197
199
  if data.size > 64 * 1024
198
200
  encoding = Agent.config[:compressed_content_encoding]
199
- data = if encoding == 'gzip'
200
- Encoders::Compressed::Gzip.encode(data)
201
- else
201
+ data = if encoding == 'deflate'
202
202
  Encoders::Compressed::Deflate.encode(data)
203
+ else
204
+ Encoders::Compressed::Gzip.encode(data)
203
205
  end
204
206
  end
205
207
  check_post_size(data, endpoint)
@@ -0,0 +1,22 @@
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
+
9
+ # This class is used for instrumentations that have exceptions or error classes
10
+ # not derived from Ruby's usual Exception or StandardError or in situations
11
+ # where we do not have such Exception object to work with.
12
+ class NoticibleError
13
+ attr_reader :class_name, :message
14
+
15
+ def initialize class_name, message
16
+ @class_name = class_name
17
+ @message = message
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -13,10 +13,8 @@ module NewRelic
13
13
  named :SpanEventAggregator
14
14
  capacity_key :'span_events.max_samples_stored'
15
15
 
16
- enabled_fn -> {
17
- NewRelic::Agent.config[:'span_events.enabled'] &&
18
- NewRelic::Agent.config[:'distributed_tracing.enabled']
19
- }
16
+ enabled_keys :'span_events.enabled',
17
+ :'distributed_tracing.enabled'
20
18
 
21
19
  def record priority: nil, event:nil, &blk
22
20
  unless(event || priority && blk)
@@ -1,12 +1,13 @@
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
  # This module builds the data structures necessary to create a Span
6
7
  # event for a segment.
7
8
 
8
9
  require 'new_relic/agent/payload_metric_mapping'
9
- require 'new_relic/agent/distributed_trace_payload'
10
+ require 'new_relic/agent/distributed_tracing/distributed_trace_payload'
10
11
 
11
12
  module NewRelic
12
13
  module Agent
@@ -15,70 +16,80 @@ module NewRelic
15
16
  extend self
16
17
 
17
18
  # Strings for static keys of the event structure
18
- TYPE_KEY = 'type'.freeze
19
- TRACE_ID_KEY = 'traceId'.freeze
20
- GUID_KEY = 'guid'.freeze
21
- PARENT_ID_KEY = 'parentId'.freeze
22
- GRANDPARENT_ID_KEY = 'grandparentId'.freeze
23
- TRANSACTION_ID_KEY = 'transactionId'.freeze
24
- SAMPLED_KEY = 'sampled'.freeze
25
- PRIORITY_KEY = 'priority'.freeze
26
- TIMESTAMP_KEY = 'timestamp'.freeze
27
- DURATION_KEY = 'duration'.freeze
28
- NAME_KEY = 'name'.freeze
29
- CATEGORY_KEY = 'category'.freeze
30
- HTTP_URL_KEY = 'http.url'.freeze
31
- HTTP_METHOD_KEY = 'http.method'.freeze
32
- COMPONENT_KEY = 'component'.freeze
33
- DB_INSTANCE_KEY = 'db.instance'.freeze
34
- DB_STATEMENT_KEY = 'db.statement'.freeze
35
- PEER_ADDRESS_KEY = 'peer.address'.freeze
36
- PEER_HOSTNAME_KEY = 'peer.hostname'.freeze
37
- SPAN_KIND_KEY = 'span.kind'.freeze
38
- ENTRY_POINT_KEY = 'nr.entryPoint'.freeze
19
+ ELLIPSIS = '...'
20
+ TYPE_KEY = 'type'
21
+ TRACE_ID_KEY = 'traceId'
22
+ GUID_KEY = 'guid'
23
+ PARENT_ID_KEY = 'parentId'
24
+ GRANDPARENT_ID_KEY = 'grandparentId'
25
+ TRANSACTION_ID_KEY = 'transactionId'
26
+ SAMPLED_KEY = 'sampled'
27
+ PRIORITY_KEY = 'priority'
28
+ TIMESTAMP_KEY = 'timestamp'
29
+ DURATION_KEY = 'duration'
30
+ NAME_KEY = 'name'
31
+ CATEGORY_KEY = 'category'
32
+ HTTP_URL_KEY = 'http.url'
33
+ HTTP_METHOD_KEY = 'http.method'
34
+ HTTP_STATUS_CODE_KEY = 'http.statusCode'
35
+ COMPONENT_KEY = 'component'
36
+ DB_INSTANCE_KEY = 'db.instance'
37
+ DB_STATEMENT_KEY = 'db.statement'
38
+ PEER_ADDRESS_KEY = 'peer.address'
39
+ PEER_HOSTNAME_KEY = 'peer.hostname'
40
+ SPAN_KIND_KEY = 'span.kind'
41
+ ENTRY_POINT_KEY = 'nr.entryPoint'
42
+ TRUSTED_PARENT_KEY = "trustedParentId"
43
+ TRACING_VENDORS_KEY = "tracingVendors"
39
44
 
40
45
  # Strings for static values of the event structure
41
- EVENT_TYPE = 'Span'.freeze
42
- GENERIC_CATEGORY = 'generic'.freeze
43
- HTTP_CATEGORY = 'http'.freeze
44
- DATASTORE_CATEGORY = 'datastore'.freeze
45
- CLIENT = 'client'.freeze
46
-
47
- # To avoid allocations when we have empty custom or agent attributes
48
- EMPTY_HASH = {}.freeze
46
+ EVENT_TYPE = 'Span'
47
+ GENERIC_CATEGORY = 'generic'
48
+ HTTP_CATEGORY = 'http'
49
+ DATASTORE_CATEGORY = 'datastore'
50
+ CLIENT = 'client'
51
+
52
+ # Builds a Hash of error attributes as well as the Span ID when
53
+ # an error is present. Otherwise, returns nil when no error present.
54
+ def error_attributes segment
55
+ return if Agent.config[:high_security] || !segment.noticed_error
56
+ segment.noticed_error.build_error_attributes
57
+ segment.noticed_error_attributes
58
+ end
49
59
 
50
- def for_segment(segment)
60
+ def for_segment segment
51
61
  intrinsics = intrinsics_for(segment)
52
62
  intrinsics[CATEGORY_KEY] = GENERIC_CATEGORY
53
63
 
54
- [intrinsics, EMPTY_HASH, EMPTY_HASH]
64
+ [intrinsics, custom_attributes(segment.attributes), error_attributes(segment) || NewRelic::EMPTY_HASH]
55
65
  end
56
66
 
57
- def for_external_request_segment(segment)
67
+ def for_external_request_segment segment
58
68
  intrinsics = intrinsics_for(segment)
59
69
 
60
70
  intrinsics[COMPONENT_KEY] = segment.library
61
71
  intrinsics[HTTP_METHOD_KEY] = segment.procedure
72
+ intrinsics[HTTP_STATUS_CODE_KEY] = segment.http_status_code if segment.http_status_code
62
73
  intrinsics[CATEGORY_KEY] = HTTP_CATEGORY
63
74
  intrinsics[SPAN_KIND_KEY] = CLIENT
64
75
 
65
- agent_attributes = {}
76
+ agent_attributes = error_attributes(segment) || {}
66
77
 
67
78
  if allowed?(HTTP_URL_KEY)
68
79
  agent_attributes[HTTP_URL_KEY] = truncate(segment.uri)
69
80
  end
70
81
 
71
- [intrinsics, EMPTY_HASH, agent_attributes]
82
+ [intrinsics, custom_attributes(segment.attributes), agent_attributes]
72
83
  end
73
84
 
74
- def for_datastore_segment(segment)
85
+ def for_datastore_segment segment
75
86
  intrinsics = intrinsics_for(segment)
76
87
 
77
88
  intrinsics[COMPONENT_KEY] = segment.product
78
89
  intrinsics[SPAN_KIND_KEY] = CLIENT
79
90
  intrinsics[CATEGORY_KEY] = DATASTORE_CATEGORY
80
91
 
81
- agent_attributes = {}
92
+ agent_attributes = error_attributes(segment) || {}
82
93
 
83
94
  if segment.database_name && allowed?(DB_INSTANCE_KEY)
84
95
  agent_attributes[DB_INSTANCE_KEY] = truncate(segment.database_name)
@@ -96,14 +107,13 @@ module NewRelic
96
107
  agent_attributes[DB_STATEMENT_KEY] = truncate(segment.nosql_statement, 2000)
97
108
  end
98
109
 
99
- [intrinsics, EMPTY_HASH, agent_attributes]
110
+ [intrinsics, custom_attributes(segment.attributes), agent_attributes]
100
111
  end
101
112
 
102
113
  private
103
114
 
104
- def intrinsics_for(segment)
105
- intrinsics =
106
- {
115
+ def intrinsics_for segment
116
+ intrinsics = {
107
117
  TYPE_KEY => EVENT_TYPE,
108
118
  TRACE_ID_KEY => segment.transaction.trace_id,
109
119
  GUID_KEY => segment.guid,
@@ -115,29 +125,48 @@ module NewRelic
115
125
  NAME_KEY => segment.name
116
126
  }
117
127
 
118
- parent_id = parent_guid(segment)
119
- intrinsics[PARENT_ID_KEY] = parent_id if parent_id
120
-
121
- intrinsics[ENTRY_POINT_KEY] = true unless segment.parent
128
+ if segment.parent.nil?
129
+ intrinsics[ENTRY_POINT_KEY] = true
130
+ if txn = segment.transaction
131
+ if header_data = txn.distributed_tracer.trace_context_header_data
132
+ if trace_state_vendors = header_data.trace_state_vendors
133
+ intrinsics[TRACING_VENDORS_KEY] = trace_state_vendors unless trace_state_vendors == NewRelic::EMPTY_STR
134
+ end
135
+ end
136
+ if trace_state_payload = txn.distributed_tracer.trace_state_payload
137
+ intrinsics[TRUSTED_PARENT_KEY] = trace_state_payload.id if trace_state_payload.id
138
+ end
139
+ end
140
+ end
122
141
 
142
+ if parent_id = parent_guid(segment)
143
+ intrinsics[PARENT_ID_KEY] = parent_id
144
+ end
123
145
  intrinsics
124
146
  end
125
147
 
126
- def parent_guid(segment)
148
+ def custom_attributes attributes
149
+ if attributes
150
+ result = attributes.custom_attributes_for(NewRelic::Agent::AttributeFilter::DST_SPAN_EVENTS)
151
+ result.freeze
152
+ else
153
+ NewRelic::EMPTY_HASH
154
+ end
155
+ end
156
+
157
+ def parent_guid segment
127
158
  if segment.parent
128
159
  segment.parent.guid
129
- elsif segment.transaction && segment.transaction.distributed_trace?
130
- segment.transaction.distributed_trace_payload.id
160
+ elsif txn = segment.transaction
161
+ txn.distributed_tracer.parent_guid
131
162
  end
132
163
  end
133
164
 
134
- def milliseconds_since_epoch(segment)
165
+ def milliseconds_since_epoch segment
135
166
  Integer(segment.start_time.to_f * 1000.0)
136
167
  end
137
168
 
138
- ELLIPSIS = '...'.freeze
139
-
140
- def truncate(value, max_size=255)
169
+ def truncate value, max_size=255
141
170
  value = value.to_s
142
171
  if value.bytesize > max_size
143
172
  value.byteslice(0, max_size - 2).chop! << ELLIPSIS
@@ -146,7 +175,7 @@ module NewRelic
146
175
  end
147
176
  end
148
177
 
149
- def allowed?(key)
178
+ def allowed? key
150
179
  NewRelic::Agent.instance.attribute_filter.allows_key?(key, AttributeFilter::DST_SPAN_EVENTS)
151
180
  end
152
181
  end
@@ -159,10 +159,10 @@ module NewRelic
159
159
  def distributed_trace_intrinsics(state)
160
160
  transaction = state.current_transaction
161
161
  params = nil
162
- if transaction && transaction.distributed_trace_payload
162
+ if transaction && transaction.distributed_tracer.distributed_trace_payload
163
163
  params = {}
164
- payload = transaction.distributed_trace_payload
165
- payload.assign_intrinsics transaction, params
164
+ payload = transaction.distributed_tracer.distributed_trace_payload
165
+ DistributedTraceIntrinsics.copy_from_transaction transaction, payload, params
166
166
  params[PRIORITY] = transaction.priority
167
167
  end
168
168
  params
@@ -11,7 +11,7 @@ module NewRelic
11
11
  {
12
12
  :type => :ruby,
13
13
  :name => "MRI",
14
- :supported => ["2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0", "~>2.4.0", "~>2.5.0"],
14
+ :supported => ["2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0", "~>2.4.0", "~>2.5.0", "~>2.6.0", "~>2.7.0"],
15
15
  :deprecated => ["1.8.6", "1.8.7", "1.9.2", "1.9.3"],
16
16
  :url => "https://www.ruby-lang.org",
17
17
  :feed => "https://www.ruby-lang.org/en/feeds/news.rss",
@@ -119,7 +119,7 @@ module NewRelic
119
119
  :activerecord =>
120
120
  {
121
121
  :type => :database,
122
- :supported => ["~>3.0.0", "~>3.1.0", "~>3.2.0", "~>4.0.0", "~>4.1.0", "~>4.2.0", "~>5.0.0", "~>5.1.0"],
122
+ :supported => ["~>3.0.0", "~>3.1.0", "~>3.2.0", "~>4.0.0", "~>4.1.0", "~>4.2.0", "~>5.0.0", "~>5.1.0", "~>6.0.0"],
123
123
  :deprecated => ["~>2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0",],
124
124
  :url => "https://rubygems.org/gems/activerecord",
125
125
  :feed => "https://rubygems.org/gems/activerecord/versions.atom",
@@ -39,6 +39,38 @@ module NewRelic
39
39
  state.current_transaction
40
40
  end
41
41
 
42
+ # Returns the trace_id of the current_transaction, or +nil+ if
43
+ # none exists.
44
+ #
45
+ # @api public
46
+ def current_trace_id
47
+ if txn = current_transaction
48
+ txn.trace_id
49
+ end
50
+ end
51
+ alias_method :trace_id, :current_trace_id
52
+
53
+ # Returns the id of the current span, or +nil+ if none exists.
54
+ #
55
+ # @api public
56
+ def current_span_id
57
+ if span = current_segment
58
+ span.guid
59
+ end
60
+ end
61
+ alias_method :span_id, :current_span_id
62
+
63
+ # Returns a boolean indicating whether the current_transaction
64
+ # is sampled, or +nil+ if there is no current transaction.
65
+ #
66
+ # @api public
67
+ def transaction_sampled?
68
+ if txn = current_transaction
69
+ txn.sampled?
70
+ end
71
+ end
72
+ alias_method :sampled?, :transaction_sampled?
73
+
42
74
  # Runs the given block of code in a transaction.
43
75
  #
44
76
  # @param [String] name reserved for New Relic internal use
@@ -70,9 +102,9 @@ module NewRelic
70
102
  # only wrap the yield to be absolutely sure we don't report agent
71
103
  # problems as app errors
72
104
  yield
73
- rescue => e
74
- current_transaction.notice_error(e)
75
- raise e
105
+ rescue => exception
106
+ current_transaction.notice_error(exception)
107
+ raise
76
108
  ensure
77
109
  finishable.finish if finishable
78
110
  end
@@ -88,7 +120,7 @@ module NewRelic
88
120
  # New-Relic-specific prefix
89
121
  #
90
122
  # @param [Symbol] category +:web+ for web transactions or
91
- # +:background+ for background transactions
123
+ # +:task+ for background transactions
92
124
  #
93
125
  # @param [Hash] options reserved for New Relic internal use
94
126
  #
@@ -125,8 +157,8 @@ module NewRelic
125
157
 
126
158
  rescue ArgumentError
127
159
  raise
128
- rescue => e
129
- log_error('start_transaction_or_segment', e)
160
+ rescue => exception
161
+ log_error('start_transaction_or_segment', exception)
130
162
  end
131
163
 
132
164
  # Takes name or partial_name and a category.
@@ -158,18 +190,18 @@ module NewRelic
158
190
  options)
159
191
  rescue ArgumentError
160
192
  raise
161
- rescue => e
162
- log_error('start_transaction', e)
193
+ rescue => exception
194
+ log_error('start_transaction', exception)
163
195
  end
164
196
 
165
197
  def create_distributed_trace_payload
166
198
  return unless txn = current_transaction
167
- txn.create_distributed_trace_payload
199
+ txn.distributed_tracer.create_distributed_trace_payload
168
200
  end
169
201
 
170
202
  def accept_distributed_trace_payload(payload)
171
203
  return unless txn = current_transaction
172
- txn.accept_distributed_trace_payload(payload)
204
+ txn.distributed_tracer.accept_distributed_trace_payload(payload)
173
205
  end
174
206
 
175
207
  # Returns the currently active segment in the transaction in
@@ -219,8 +251,8 @@ module NewRelic
219
251
 
220
252
  rescue ArgumentError
221
253
  raise
222
- rescue => e
223
- log_error('start_segment', e)
254
+ rescue => exception
255
+ log_error('start_segment', exception)
224
256
  end
225
257
 
226
258
  UNKNOWN = "Unknown".freeze
@@ -278,8 +310,8 @@ module NewRelic
278
310
 
279
311
  rescue ArgumentError
280
312
  raise
281
- rescue => e
282
- log_error('start_datastore_segment', e)
313
+ rescue => exception
314
+ log_error('start_datastore_segment', exception)
283
315
  end
284
316
 
285
317
  # Creates and starts an external request segment using the
@@ -325,8 +357,23 @@ module NewRelic
325
357
 
326
358
  rescue ArgumentError
327
359
  raise
328
- rescue => e
329
- log_error('start_external_request_segment', e)
360
+ rescue => exception
361
+ log_error('start_external_request_segment', exception)
362
+ end
363
+
364
+ # Will potentially capture and notice an error at the
365
+ # segment that was executing when error occurred.
366
+ # if passed +segment+ is something that doesn't
367
+ # respond to +notice_segment_error+ then this method
368
+ # is effectively just a yield to the given &block
369
+ def capture_segment_error segment
370
+ return unless block_given?
371
+ yield
372
+ rescue => exception
373
+ if segment && segment.is_a?(Transaction::AbstractSegment)
374
+ segment.notice_error exception
375
+ end
376
+ raise
330
377
  end
331
378
 
332
379
  # For New Relic internal use only.
@@ -358,8 +405,8 @@ module NewRelic
358
405
 
359
406
  rescue ArgumentError
360
407
  raise
361
- rescue => e
362
- log_error('start_datastore_segment', e)
408
+ rescue => exception
409
+ log_error('start_datastore_segment', exception)
363
410
  end
364
411
 
365
412
  # This method should only be used by Tracer for access to the