newrelic 6.12.1 → 6.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONTRIBUTING.md CHANGED
@@ -20,9 +20,9 @@ licensing restrictions.
20
20
 
21
21
  ### Code of Conduct
22
22
 
23
- Before contributing please read the [code of conduct](./CODE_OF_CONDUCT.md)
23
+ Before contributing please read the [code of conduct](https://github.com/newrelic/.github/blob/main/CODE_OF_CONDUCT.md)
24
24
 
25
- Note that our [code of conduct](./CODE_OF_CONDUCT.md) applies to all platforms
25
+ Note that our [code of conduct](https://github.com/newrelic/.github/blob/main/CODE_OF_CONDUCT.md) applies to all platforms
26
26
  and venues related to this project; please follow it in all your interactions
27
27
  with the project and its participants.
28
28
 
@@ -53,7 +53,7 @@ When contributing, keep in mind that New Relic customers (that's you!) are runni
53
53
 
54
54
  Be aware that the instrumentation needs to work with a wide range of versions of the instrumented modules, and that code that looks nonsensical or overcomplicated may be that way for compatibility-related reasons. Read all the comments and check the related tests before deciding whether existing code is incorrect.
55
55
 
56
- If you’re planning on contributing a new feature or an otherwise complex contribution, we kindly ask you to start a conversation with the maintainer team by opening up an Github issue first.
56
+ If you’re planning on contributing a new feature or an otherwise complex contribution, we kindly ask you to start a conversation with the maintainer team by opening up an Github issue first.
57
57
 
58
58
  ### General Guidelines
59
59
 
package/NEWS.md CHANGED
@@ -1,3 +1,59 @@
1
+ ### 6.14.0 (2020-10-28):
2
+
3
+ * Updated README for consistency.
4
+
5
+ * Fixed issue where gRPC connection used for infinite tracing could throw if the server
6
+ shutdown during disconnect of an existing connection.
7
+
8
+ * Bumped @grpc/grpc-js to 1.1.7.
9
+
10
+ * Bumped @grpc/proto-loader to ^0.5.5.
11
+
12
+ * Infinite tracing logging and support metric improvements.
13
+
14
+ * Increased logging level of certain infinite tracing / gRPC errors.
15
+ * Decreased logging interval of dropped span warning for infinite tracing.
16
+ * Added additional support metrics and logging for infinite tracing.
17
+
18
+ * Fixed bug where errors would still be collected for transactions with ignored error
19
+ status codes in certain situations.
20
+
21
+ * Converted errors ignore unit tests to tap API.
22
+
23
+ * Added Node 14 to CI test coverage.
24
+
25
+ Many thanks to @jgeurts for the contribution.
26
+
27
+ ### 6.13.2 (2020-10-13):
28
+
29
+ * Removed lodash as a development dependency
30
+
31
+ * Check for named pipe existence before each flush
32
+
33
+ This removes the cached value used in 6.13.1
34
+
35
+ * Update shim documentation
36
+
37
+ Thank you to @ronen-e for the contribution!
38
+
39
+ ### 6.13.1 (2020-09-24):
40
+
41
+ * Fixed named-pipe check for lambda invocations to avoid race-condition.
42
+
43
+ Named-pipe existence will now be checked just prior to first write and then cached.
44
+
45
+ * Updated README with community-plus header.
46
+
47
+ * Updated README config copy example.
48
+
49
+ * Added Open Source Policy workflow.
50
+
51
+ * Removed repository CoC in favor of centralized CoC at org root.
52
+
53
+ ### 6.13.0 (2020-08-25):
54
+
55
+ * Added ability for the agent to write to a named pipe, instead of stdout, when in serverless mode.
56
+
1
57
  ### 6.12.1 (2020-08-20):
2
58
 
3
59
  * **Security fix:** Resolves an issue where transaction traces will still capture the request URI when the Node.js agent is configured to exclude the 'request.uri' attribute. This can be problematic for certain customers in environments where sensitive information is included in the URI. See security bulletin [NR20-02](https://docs.newrelic.com/docs/security/new-relic-security/security-bulletins/security-bulletin-nr20-02).
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)
1
+ [![Community Plus header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus)
2
2
 
3
3
  # New Relic's Node.js agent [![Server Smoke Tests][3]][4] [![Node Agent CI][5]][6]
4
4
 
@@ -10,7 +10,7 @@ In order to take full advantage of this package, make sure you have a [New Relic
10
10
 
11
11
  As with any instrumentation tool, please test before using in production.
12
12
 
13
- ## Installation and getting started
13
+ ## Installation
14
14
 
15
15
  To use New Relic's Node.js agent entails these three steps, which are described in detail below:
16
16
 
@@ -20,11 +20,11 @@ To use New Relic's Node.js agent entails these three steps, which are described
20
20
 
21
21
  1. To install the agent for performance monitoring, use your favorite npm-based package manager and install the `newrelic` package into your application:
22
22
 
23
- $ npm install newrelic
23
+ `$ npm install newrelic`
24
24
 
25
25
  2. Then, copy the stock configuration file to your program's base folder:
26
26
 
27
- $ cp node_modules/newrelic/newrelic.js
27
+ `$ cp ./node_modules/newrelic/newrelic.js ./<your destination>`
28
28
 
29
29
  3. Now, add your New Relic license key and application/service name to that file:
30
30
 
@@ -57,9 +57,13 @@ If you're compiling your JavaScript and can't control the final `require` order,
57
57
  $ node -r newrelic your-program.js
58
58
  $ node --require newrelic your-program.js
59
59
 
60
+ ## Getting Started
61
+
60
62
  For more information on getting started, [check the Node.js docs](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/introduction-new-relic-nodejs).
61
63
 
62
- ## Using the API
64
+ ## Usage
65
+
66
+ ### Using the API
63
67
 
64
68
  The `newrelic` module returns an object with the Node agent's API methods attached.
65
69
 
@@ -72,7 +76,7 @@ The `newrelic` module returns an object with the Node agent's API methods attach
72
76
 
73
77
  You can read more about using the API over on the [New Relic documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/guide-using-nodejs-agent-api) site.
74
78
 
75
- ## Core agent development and tests
79
+ ## Testing
76
80
 
77
81
  These are the steps to work on core agent features, with more detail below:
78
82
 
@@ -149,17 +153,22 @@ Please review [New Relic’s General Data Privacy Notice](https://newrelic.com/t
149
153
 
150
154
  See our [roadmap](./ROADMAP_Node.md), to learn more about our product vision, understand our plans, and provide us valuable feedback.
151
155
 
152
- ## Contributing
156
+ ## Contribute
153
157
 
154
158
  We encourage your contributions to improve the Node.js agent! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
159
+
155
160
  If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.
156
161
 
157
162
  **A note about vulnerabilities**
158
163
 
159
- As noted in our [security policy](https://github.com/newrelic/node-newrelic/security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
164
+ As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
160
165
 
161
166
  If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
162
167
 
168
+ If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).
169
+
170
+ To [all contributors](https://github.com/newrelic/node-newrelic/graphs/contributors), we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to [New Relic Node Agent](https://opensource.newrelic.com/projects/newrelic/node-newrelic).
171
+
163
172
  ## License
164
173
 
165
174
  The Node.js agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
@@ -172,4 +181,4 @@ The Node.js agent also uses source code from third-party libraries. You can find
172
181
  [3]: https://github.com/newrelic/node-newrelic/workflows/Server%20Smoke%20Tests/badge.svg
173
182
  [4]: https://github.com/newrelic/node-newrelic/actions?query=workflow%3A%22Server+Smoke+Tests%22
174
183
  [5]: https://github.com/newrelic/node-newrelic/workflows/Node%20Agent%20CI/badge.svg
175
- [6]: https://github.com/newrelic/node-newrelic/actions?query=workflow%3A%22Node+Agent+CI%22
184
+ [6]: https://github.com/newrelic/node-newrelic/actions?query=workflow%3A%22Node+Agent+CI%22
@@ -48,7 +48,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
48
48
  * [got](#got)
49
49
  * [http-errors](#http-errors)
50
50
  * [jsdoc](#jsdoc)
51
- * [lodash](#lodash)
52
51
  * [memcached](#memcached)
53
52
  * [minami](#minami)
54
53
  * [mongodb](#mongodb)
@@ -77,7 +76,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
77
76
 
78
77
  ### @grpc/grpc-js
79
78
 
80
- This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.0.5](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.0.5)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.0.5/LICENSE):
79
+ This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.1.7](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.1.7)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.1.7/LICENSE):
81
80
 
82
81
  ```
83
82
  Apache License
@@ -286,7 +285,7 @@ This product includes source derived from [@grpc/grpc-js](https://github.com/grp
286
285
 
287
286
  ### @grpc/proto-loader
288
287
 
289
- This product includes source derived from [@grpc/proto-loader](https://github.com/grpc/grpc-node) ([v0.5.4](https://github.com/grpc/grpc-node/tree/v0.5.4)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/blob/v0.5.4/LICENSE):
288
+ This product includes source derived from [@grpc/proto-loader](https://github.com/grpc/grpc-node) ([v0.5.5](https://github.com/grpc/grpc-node/tree/v0.5.5)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/blob/v0.5.5/LICENSE):
290
289
 
291
290
  ```
292
291
  Apache License
@@ -2197,61 +2196,6 @@ https://github.com/jmblog/color-themes-for-google-code-prettify
2197
2196
 
2198
2197
  ```
2199
2198
 
2200
- ### lodash
2201
-
2202
- This product includes source derived from [lodash](https://github.com/lodash/lodash) ([v4.17.15](https://github.com/lodash/lodash/tree/v4.17.15)), distributed under the [MIT License](https://github.com/lodash/lodash/blob/v4.17.15/LICENSE):
2203
-
2204
- ```
2205
- Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
2206
-
2207
- Based on Underscore.js, copyright Jeremy Ashkenas,
2208
- DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
2209
-
2210
- This software consists of voluntary contributions made by many
2211
- individuals. For exact contribution history, see the revision history
2212
- available at https://github.com/lodash/lodash
2213
-
2214
- The following license applies to all parts of this software except as
2215
- documented below:
2216
-
2217
- ====
2218
-
2219
- Permission is hereby granted, free of charge, to any person obtaining
2220
- a copy of this software and associated documentation files (the
2221
- "Software"), to deal in the Software without restriction, including
2222
- without limitation the rights to use, copy, modify, merge, publish,
2223
- distribute, sublicense, and/or sell copies of the Software, and to
2224
- permit persons to whom the Software is furnished to do so, subject to
2225
- the following conditions:
2226
-
2227
- The above copyright notice and this permission notice shall be
2228
- included in all copies or substantial portions of the Software.
2229
-
2230
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2231
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2232
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2233
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2234
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2235
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2236
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2237
-
2238
- ====
2239
-
2240
- Copyright and related rights for sample code are waived via CC0. Sample
2241
- code is defined as all source code displayed within the prose of the
2242
- documentation.
2243
-
2244
- CC0: http://creativecommons.org/publicdomain/zero/1.0/
2245
-
2246
- ====
2247
-
2248
- Files located in the node_modules and vendor directories are externally
2249
- maintained libraries used by this software which have their own
2250
- licenses; we recommend you read them, as their terms may differ from the
2251
- terms above.
2252
-
2253
- ```
2254
-
2255
2199
  ### memcached
2256
2200
 
2257
2201
  This product includes source derived from [memcached](https://github.com/3rd-Eden/node-memcached) ([v2.2.2](https://github.com/3rd-Eden/node-memcached/tree/v2.2.2)), distributed under the [MIT License](https://github.com/3rd-Eden/node-memcached/blob/v2.2.2/LICENSE):
package/lib/agent.js CHANGED
@@ -581,6 +581,10 @@ Agent.prototype._beforeMetricDataSend = function _beforeMetricDataSend() {
581
581
 
582
582
  // Send uninstrumented supportability metrics every metric harvest cycle
583
583
  uninstrumented.createMetrics(this.metrics)
584
+
585
+ if (this.spanEventAggregator.isStream) {
586
+ this.spanEventAggregator.createMetrics()
587
+ }
584
588
  }
585
589
 
586
590
  Agent.prototype._generateEntityStatsAndClear = function _generateHarvestMetrics() {
@@ -107,17 +107,23 @@ RemoteMethod.prototype._post = function _post(data, nrHeaders, callback) {
107
107
  }
108
108
 
109
109
  if (options.compressed) {
110
- var useGzip = this._config.compressed_content_encoding === 'gzip'
111
- var compressor = useGzip ? zlib.gzip : zlib.deflate
112
- compressor(data, function onCompress(err, compressed) {
113
- if (err) {
114
- logger.warn(err, 'Error compressing JSON for delivery. Not sending.')
115
- return callback(err)
116
- }
117
-
118
- options.body = compressed
119
- makeRequest()
120
- })
110
+ // NOTE: gzip and deflate throw immediately in Node 14+ with an invalid argument
111
+ try {
112
+ var useGzip = this._config.compressed_content_encoding === 'gzip'
113
+ var compressor = useGzip ? zlib.gzip : zlib.deflate
114
+ compressor(data, function onCompress(err, compressed) {
115
+ if (err) {
116
+ logger.warn(err, 'Error compressing JSON for delivery. Not sending.')
117
+ return callback(err)
118
+ }
119
+
120
+ options.body = compressed
121
+ makeRequest()
122
+ })
123
+ } catch (err) {
124
+ logger.warn(err, 'Error compressing JSON for delivery. Not sending.')
125
+ return callback(err)
126
+ }
121
127
  } else {
122
128
  options.body = data
123
129
  makeRequest()
@@ -14,6 +14,9 @@ const stringify = require('json-stringify-safe')
14
14
  const PAYLOAD_VERSION = 1
15
15
  const PAYLOAD_MARKER = 'NR_LAMBDA_MONITORING'
16
16
 
17
+ const path = require('path')
18
+ const defaultPipePath = path.resolve('/tmp', 'newrelic-telemetry')
19
+
17
20
  class ServerlessCollector {
18
21
  /**
19
22
  * Constructs a new serverless collector instance with the give agent.
@@ -24,7 +27,7 @@ class ServerlessCollector {
24
27
  *
25
28
  * @param {Agent} agent - The agent this collector will use
26
29
  */
27
- constructor(agent) {
30
+ constructor(agent, pipePath) {
28
31
  this._agent = agent
29
32
  this.enabled = true
30
33
  this.metadata = {
@@ -35,6 +38,7 @@ class ServerlessCollector {
35
38
  agent_version: agent.version
36
39
  }
37
40
  this.payload = {}
41
+ this.pipePath = pipePath || process.env.NEWRELIC_PIPE_PATH || defaultPipePath
38
42
  }
39
43
 
40
44
  /**
@@ -243,6 +247,36 @@ class ServerlessCollector {
243
247
  }
244
248
  }
245
249
 
250
+ /**
251
+ * Writes payload to pipe
252
+ */
253
+ flushToPipeSync(payload) {
254
+ try {
255
+ fs.writeFileSync(this.pipePath, payload)
256
+ return true
257
+ } catch (e) {
258
+ logger.warn('Error attempting to write to pipe, falling back to stdout', e)
259
+ return false
260
+ }
261
+ }
262
+
263
+ flushToStdOut(serializedPayload, payloadLength, sync = false) {
264
+ if (sync) {
265
+ // Long log lines have been truncated at 65538
266
+ // Guarantees process.stdout will block, so long logs
267
+ // won't be truncated if process.exit() is called early.
268
+ const s = process.stdout
269
+ payloadLength > 65000 &&
270
+ s._handle &&
271
+ s._handle.setBlocking &&
272
+ s._handle.setBlocking(true)
273
+
274
+ fs.writeSync(process.stdout.fd, serializedPayload)
275
+ } else {
276
+ process.stdout.write(serializedPayload)
277
+ }
278
+ }
279
+
246
280
  /**
247
281
  * Internal method to handle flushing to stdout.
248
282
  *
@@ -258,19 +292,10 @@ class ServerlessCollector {
258
292
  payload
259
293
  ]) + '\n'
260
294
 
261
- if (sync) {
262
- // Long log lines have been truncated at 65538
263
- // Guarantees process.stdout will block, so long logs
264
- // won't be truncated if process.exit() is called early.
265
- const s = process.stdout
266
- payload.length > 65000 &&
267
- s._handle &&
268
- s._handle.setBlocking &&
269
- s._handle.setBlocking(true)
295
+ const didUsePipe = fs.existsSync(this.pipePath) && this.flushToPipeSync(serializedPayload)
270
296
 
271
- fs.writeSync(process.stdout.fd, serializedPayload)
272
- } else {
273
- process.stdout.write(serializedPayload)
297
+ if (!didUsePipe) {
298
+ this.flushToStdOut(serializedPayload, payload.length, sync)
274
299
  }
275
300
  }
276
301
  }
@@ -142,13 +142,18 @@ class ErrorCollector {
142
142
  }
143
143
 
144
144
  const isErroredTransaction = urltils.isError(this.config, transaction.statusCode)
145
+ const isIgnoredErrorStatusCode = urltils.isIgnoredError(
146
+ this.config,
147
+ transaction.statusCode
148
+ )
149
+
145
150
  const isExpectedErrorStatusCode = urltils.isExpectedError(
146
151
  this.config,
147
152
  transaction.statusCode
148
153
  )
149
154
 
150
155
  // collect other exceptions only if status code is not ignored
151
- if (transaction.exceptions.length) {
156
+ if (transaction.exceptions.length && !isIgnoredErrorStatusCode) {
152
157
  for (let i = 0; i < transaction.exceptions.length; i++) {
153
158
  const exception = transaction.exceptions[i]
154
159
  if (this.collect(transaction, exception)) {
@@ -20,7 +20,20 @@ class Exception {
20
20
  }
21
21
 
22
22
  getErrorDetails(config) {
23
- return errorHelper.extractErrorInformation(null, this.error, config)
23
+ const errorDetails = errorHelper.extractErrorInformation(null, this.error, config)
24
+ errorDetails.expected = this.isExpected(config, errorDetails)
25
+
26
+ return errorDetails
27
+ }
28
+
29
+ isExpected(config, {type, message}) {
30
+ if (!this._expected) {
31
+ this._expected =
32
+ errorHelper.isExpectedErrorClass(config, type) ||
33
+ errorHelper.isExpectedErrorMessage(config, type, message)
34
+ }
35
+
36
+ return this._expected
24
37
  }
25
38
  }
26
39
 
@@ -121,7 +121,7 @@ class GrpcConnection extends EventEmitter {
121
121
  // immediately.
122
122
  this._setState(connectionStates.connected, this.stream)
123
123
  } catch (err) {
124
- logger.trace(
124
+ logger.warn(
125
125
  err,
126
126
  'Unexpected error establishing gRPC stream, will not attempt reconnect.'
127
127
  )
@@ -198,9 +198,26 @@ class GrpcConnection extends EventEmitter {
198
198
  if (this.stream) {
199
199
  this.stream.removeAllListeners()
200
200
 
201
+ const oldStream = this.stream
202
+ this.stream.on('status', function endStreamStatusHandler(grpcStatus) {
203
+ logger.trace('End stream status received [%s]: %s', grpcStatus.code, grpcStatus.details)
204
+
205
+ // Cleanup the final end stream listeners.
206
+ oldStream.removeAllListeners()
207
+ })
208
+
209
+ // Listen to any final errors to prevent throwing.
210
+ // This is unlikely but if the server closes post
211
+ // removing listeners and prior to response it could
212
+ // happen. We noticed this via tests on Node 14.
213
+ this.stream.on('error', function endStreamErrorHandler(err) {
214
+ logger.trace('End stream error received. Code: [%s]: %s', err.code, err.details)
215
+ })
216
+
201
217
  // Indicates to server we are done.
202
218
  // Server officially closes the stream.
203
219
  this.stream.end()
220
+
204
221
  this.stream = null
205
222
  }
206
223
 
@@ -238,6 +255,9 @@ class GrpcConnection extends EventEmitter {
238
255
  // per the spec, An UNIMPLEMENTED status code from gRPC indicates
239
256
  // that the versioned Trace Observer is no longer available. Agents
240
257
  // MUST NOT attempt to reconnect in this case
258
+ logger.info(
259
+ '[UNIMPLEMENTED]: Trace Obserserver is no longer available. Shutting down connection.'
260
+ )
241
261
  this._disconnect()
242
262
  } else if (grpc.status[grpc.status.OK] === grpcStatusName) {
243
263
  this._reconnect()
@@ -256,7 +276,11 @@ class GrpcConnection extends EventEmitter {
256
276
  this._metrics.getOrCreateMetric(NAMES.INFINITE_TRACING.SPAN_RESPONSE_ERROR)
257
277
  .incrementCallCount()
258
278
 
259
- logger.trace('span stream error. Code: [%s]: %s',err.code, err.details)
279
+ // For errors, the status will either result in a disconnect or a reconnect
280
+ // delay that should prevent too frequent spamming. Unless the app is idle
281
+ // and regularly getting Status 13 reconnects from the server, in which case
282
+ // this will be almost the only logging.
283
+ logger.warn('Span stream error. Code: [%s]: %s', err.code, err.details)
260
284
  })
261
285
  }
262
286
 
@@ -240,10 +240,13 @@ const SPAN_EVENTS = {
240
240
  const INFINITE_TRACING = {
241
241
  SEEN: SUPPORTABILITY.INFINITE_TRACING + '/Span/Seen',
242
242
  SENT: SUPPORTABILITY.INFINITE_TRACING + '/Span/Sent',
243
+ DROPPED: SUPPORTABILITY.INFINITE_TRACING + '/Span/Dropped',
243
244
  SPAN_RESPONSE_ERROR: SUPPORTABILITY.INFINITE_TRACING + '/Span/Response/Error',
244
245
  SPAN_RESPONSE_GRPC_UNIMPLEMENTED: SUPPORTABILITY.INFINITE_TRACING + '/Span/gRPC/UNIMPLEMENTED',
245
246
  SPAN_RESPONSE_GRPC_STATUS: SUPPORTABILITY.INFINITE_TRACING + '/Span/gRPC/%s',
246
- DRAIN_DURATION: SUPPORTABILITY.INFINITE_TRACING + '/Drain/Duration'
247
+ QUEUE_CAPACITY: SUPPORTABILITY.INFINITE_TRACING + '/Span/QueueCapacity',
248
+ QUEUE_SIZE: SUPPORTABILITY.INFINITE_TRACING + '/Span/QueueSize',
249
+ DRAIN_DURATION: SUPPORTABILITY.INFINITE_TRACING + '/Drain/Duration',
247
250
  }
248
251
 
249
252
  module.exports = {
@@ -21,6 +21,9 @@ class SpanContext {
21
21
  customAttributes || new PrioritizedAttributes(ATTRIBUTE_SCOPE, MAXIMUM_CUSTOM_ATTRIBUTES)
22
22
 
23
23
  this.ATTRIBUTE_PRIORITY = ATTRIBUTE_PRIORITY
24
+
25
+ this.hasError = false
26
+ this.errorDetails = null
24
27
  }
25
28
 
26
29
  addIntrinsicAttribute(key, value) {
@@ -36,6 +39,21 @@ class SpanContext {
36
39
  priority
37
40
  )
38
41
  }
42
+
43
+ /**
44
+ * Set error details to be potentially be used to create span
45
+ * attributes. Attributes will be created unless the transaction
46
+ * ends with an ignored error status code.
47
+ *
48
+ * Last error wins.
49
+ */
50
+ setError(details) {
51
+ this.hasError = true
52
+
53
+ // Error details will be used to create attributes unless the transaction ends
54
+ // with an ignored status code.
55
+ this.errorDetails = details
56
+ }
39
57
  }
40
58
 
41
59
  module.exports = SpanContext
@@ -84,9 +84,21 @@ class SpanEvent {
84
84
  * @return {SpanEvent} The constructed event.
85
85
  */
86
86
  static fromSegment(segment, parentId = null, isRoot = false) {
87
+ const spanContext = segment.getSpanContext()
88
+
89
+ // Since segments already hold span agent attributes and we want to leverage
90
+ // filtering, we add to the segment attributes prior to processing.
91
+ if (spanContext.hasError && !segment.transaction.hasIgnoredErrorStatusCode()) {
92
+ const details = spanContext.errorDetails
93
+ segment.addSpanAttribute('error.message', details.message)
94
+ segment.addSpanAttribute('error.class', details.type)
95
+ if (details.expected) {
96
+ segment.addSpanAttribute('error.expected', details.expected)
97
+ }
98
+ }
99
+
87
100
  const attributes = segment.attributes.get(DESTINATIONS.SPAN_EVENT)
88
101
 
89
- const spanContext = segment.getSpanContext()
90
102
  const customAttributes = spanContext.customAttributes.get(DESTINATIONS.SPAN_EVENT)
91
103
 
92
104
  let span = null
@@ -98,7 +110,6 @@ class SpanEvent {
98
110
  span = new SpanEvent(attributes, customAttributes)
99
111
  }
100
112
 
101
-
102
113
  for (const [key, value] of Object.entries(spanContext.intrinsicAttributes)) {
103
114
  span.intrinsics[key] = value
104
115
  }
@@ -8,10 +8,10 @@
8
8
  const logger = require('../logger').child({component: 'span-streamer'})
9
9
  const NAMES = require('../metrics/names').INFINITE_TRACING
10
10
 
11
+ const SPAN_DROP_MSG_INTERVAL_MS = 30000
11
12
  const SPAN_DROP_MSG =
12
- 'Queue full, dropping spans.'
13
- const SPAN_DROP_INTERVAL = 5
14
-
13
+ 'Queue full, dropping spans. ' +
14
+ `Will not warn again for ${SPAN_DROP_MSG_INTERVAL_MS / 1000} seconds.`
15
15
 
16
16
  class SpanStreamer {
17
17
  constructor(license_key, connection, metrics, queue_size) {
@@ -47,21 +47,20 @@ class SpanStreamer {
47
47
 
48
48
  // If not writeable (because of backpressure) queue the span
49
49
  if (!this._writable) {
50
- if (this.spans.length <= this.queue_size) {
50
+ if (this.spans.length < this.queue_size) {
51
51
  this.spans.push(span)
52
52
  return
53
53
  }
54
54
 
55
+ // While this can be directionally calculated between seen/sent the
56
+ // queue makes that a bit more disconnected. This will be a bit more specific.
57
+ this._metrics.getOrCreateMetric(NAMES.DROPPED).incrementCallCount()
58
+
55
59
  // If the queue is full drop the span
56
60
  logger.infoOncePer(
57
- // key for the OncePer
58
- 'SPAN_DROP_MSG',
59
- // interval in ms
60
- SPAN_DROP_INTERVAL * 1000,
61
- // message
62
- SPAN_DROP_MSG + ' Will not warn again for %s seconds.',
63
- // variables to put in log message
64
- SPAN_DROP_INTERVAL
61
+ 'SPAN_DROP_MSG', // key for the OncePer
62
+ SPAN_DROP_MSG_INTERVAL_MS,
63
+ SPAN_DROP_MSG
65
64
  )
66
65
 
67
66
  return
@@ -121,6 +120,8 @@ class SpanStreamer {
121
120
  }
122
121
 
123
122
  sendQueue() {
123
+ logger.trace('Sending spans from queue.')
124
+
124
125
  // Continue sending the spans that were in the queue. _writable is checked
125
126
  // so that if a send fails while clearing the queue, this drain handler can
126
127
  // finish, and the drain handler setup on the failed send will then attempt
@@ -129,6 +130,11 @@ class SpanStreamer {
129
130
  const nextObject = this.spans.shift()
130
131
  this.send(nextObject)
131
132
  }
133
+
134
+ logger.trace(
135
+ 'Finished sending spans from queue. Items left in queue: %s',
136
+ this.spans.length
137
+ )
132
138
  }
133
139
 
134
140
  connect(agent_run_id, requestHeadersMap) {
@@ -144,6 +150,11 @@ class SpanStreamer {
144
150
  disconnect() {
145
151
  this.connection.disconnect()
146
152
  }
153
+
154
+ createMetrics() {
155
+ this._metrics.getOrCreateMetric(NAMES.QUEUE_CAPACITY).recordValue(this.queue_size)
156
+ this._metrics.getOrCreateMetric(NAMES.QUEUE_SIZE).recordValue(this.spans.length)
157
+ }
147
158
  }
148
159
 
149
160
  module.exports = SpanStreamer
@@ -98,6 +98,10 @@ class StreamingSpanEventAggregator extends Aggregator {
98
98
 
99
99
  this.requestHeadersMap = config.request_headers_map
100
100
  }
101
+
102
+ createMetrics() {
103
+ this.stream.createMetrics()
104
+ }
101
105
  }
102
106
 
103
107
  module.exports = StreamingSpanEventAggregator
@@ -102,9 +102,21 @@ class StreamingSpanEvent {
102
102
  }
103
103
 
104
104
  static fromSegment(segment, parentId = null, isRoot = false) {
105
+ const spanContext = segment.getSpanContext()
106
+
107
+ // Since segments already hold span agent attributes and we want to leverage
108
+ // filtering, we add to the segment attributes prior to processing.
109
+ if (spanContext.hasError && !segment.transaction.hasIgnoredErrorStatusCode()) {
110
+ const details = spanContext.errorDetails
111
+ segment.addSpanAttribute('error.message', details.message)
112
+ segment.addSpanAttribute('error.class', details.type)
113
+ if (details.expected) {
114
+ segment.addSpanAttribute('error.expected', details.expected)
115
+ }
116
+ }
117
+
105
118
  const agentAttributes = segment.attributes.get(DESTINATIONS.SPAN_EVENT)
106
119
 
107
- const spanContext = segment.getSpanContext()
108
120
  const customAttributes = spanContext.customAttributes.get(DESTINATIONS.SPAN_EVENT)
109
121
 
110
122
  const transaction = segment.transaction
@@ -679,7 +679,6 @@ Transaction.prototype.measure = function measure(name, scope, duration, exclusiv
679
679
  Transaction.prototype._setApdex = function _setApdex(name, duration, keyApdexInMillis) {
680
680
  var apdexStats = this.metrics.getOrCreateApdexMetric(name, null, keyApdexInMillis)
681
681
 
682
-
683
682
  // if we have an error-like status code, and all the errors are
684
683
  // expected, we know the status code was caused by an expected
685
684
  // error, so we will not report "frustrating". Otherwise, we
@@ -747,19 +746,13 @@ function _linkExceptionToSegment(exception) {
747
746
  return
748
747
  }
749
748
 
750
- const config = this.agent.config
751
-
752
- // Add error attributes to the span
753
- const details = exception.getErrorDetails(config)
754
- segment.addSpanAttribute('error.message', details.message)
755
- segment.addSpanAttribute('error.class', details.type)
756
-
757
- const isExpected =
758
- errorHelper.isExpectedErrorClass(config, details.type) ||
759
- errorHelper.isExpectedErrorMessage(config, details.type, details.message)
760
-
761
- if (isExpected) {
762
- segment.addSpanAttribute('error.expected', isExpected)
749
+ const spanContext = segment.getSpanContext()
750
+ if (spanContext) {
751
+ // Exception attributes will be added to span unless transaction
752
+ // status code has been ignored. Last error wins.
753
+ const config = this.agent.config
754
+ const details = exception.getErrorDetails(config)
755
+ spanContext.setError(details)
763
756
  }
764
757
 
765
758
  // Add the span/segment ID to the exception as agent attributes
@@ -793,6 +786,14 @@ function _addUserError(exception) {
793
786
  this.userErrors.push(exception)
794
787
  }
795
788
 
789
+ /**
790
+ * Returns if the transaction's current status code is errored
791
+ * but considered ignored via the config.
792
+ */
793
+ Transaction.prototype.hasIgnoredErrorStatusCode = function _hasIgnoredErrorStatusCode() {
794
+ return urltils.isIgnoredError(this.agent.config, this.statusCode)
795
+ }
796
+
796
797
  /**
797
798
  * Returns true if an error happened during the transaction or if the transaction itself is
798
799
  * considered to be an error.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "6.12.1",
3
+ "version": "6.14.0",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [
@@ -142,8 +142,8 @@
142
142
  "newrelic-naming-rules": "./bin/test-naming-rules.js"
143
143
  },
144
144
  "dependencies": {
145
- "@grpc/grpc-js": "1.0.5",
146
- "@grpc/proto-loader": "^0.5.4",
145
+ "@grpc/grpc-js": "1.1.7",
146
+ "@grpc/proto-loader": "^0.5.5",
147
147
  "@newrelic/aws-sdk": "^2.0.0",
148
148
  "@newrelic/koa": "^4.0.0",
149
149
  "@newrelic/superagent": "^3.0.0",
@@ -174,7 +174,6 @@
174
174
  "got": "^8.0.1",
175
175
  "http-errors": "^1.7.3",
176
176
  "jsdoc": "^3.6.3",
177
- "lodash": "^4.17.14",
178
177
  "memcached": ">=0.2.8",
179
178
  "minami": "^1.1.1",
180
179
  "mongodb": "^3.3.3",
@@ -1,30 +1,30 @@
1
1
  {
2
- "lastUpdated": "Mon Aug 03 2020 12:31:39 GMT-0700 (Pacific Daylight Time)",
2
+ "lastUpdated": "Wed Oct 28 2020 11:06:05 GMT-0700 (Pacific Daylight Time)",
3
3
  "projectName": "New Relic Node Agent",
4
4
  "projectUrl": "https://github.com/newrelic/node-newrelic",
5
5
  "includeDev": true,
6
6
  "dependencies": {
7
- "@grpc/grpc-js@1.0.5": {
7
+ "@grpc/grpc-js@1.1.7": {
8
8
  "name": "@grpc/grpc-js",
9
- "version": "1.0.5",
10
- "range": "1.0.5",
9
+ "version": "1.1.7",
10
+ "range": "1.1.7",
11
11
  "licenses": "Apache-2.0",
12
12
  "repoUrl": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
13
- "versionedRepoUrl": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.0.5",
13
+ "versionedRepoUrl": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.1.7",
14
14
  "licenseFile": "node_modules/@grpc/grpc-js/LICENSE",
15
- "licenseUrl": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.0.5/LICENSE",
15
+ "licenseUrl": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.1.7/LICENSE",
16
16
  "licenseTextSource": "file",
17
17
  "publisher": "Google Inc."
18
18
  },
19
- "@grpc/proto-loader@0.5.4": {
19
+ "@grpc/proto-loader@0.5.5": {
20
20
  "name": "@grpc/proto-loader",
21
- "version": "0.5.4",
22
- "range": "^0.5.4",
21
+ "version": "0.5.5",
22
+ "range": "^0.5.5",
23
23
  "licenses": "Apache-2.0",
24
24
  "repoUrl": "https://github.com/grpc/grpc-node",
25
- "versionedRepoUrl": "https://github.com/grpc/grpc-node/tree/v0.5.4",
25
+ "versionedRepoUrl": "https://github.com/grpc/grpc-node/tree/v0.5.5",
26
26
  "licenseFile": "node_modules/@grpc/proto-loader/LICENSE",
27
- "licenseUrl": "https://github.com/grpc/grpc-node/blob/v0.5.4/LICENSE",
27
+ "licenseUrl": "https://github.com/grpc/grpc-node/blob/v0.5.5/LICENSE",
28
28
  "licenseTextSource": "file",
29
29
  "publisher": "Google Inc."
30
30
  },
@@ -358,19 +358,6 @@
358
358
  "publisher": "Michael Mathews",
359
359
  "email": "micmath@gmail.com"
360
360
  },
361
- "lodash@4.17.15": {
362
- "name": "lodash",
363
- "version": "4.17.15",
364
- "range": "^4.17.14",
365
- "licenses": "MIT",
366
- "repoUrl": "https://github.com/lodash/lodash",
367
- "versionedRepoUrl": "https://github.com/lodash/lodash/tree/v4.17.15",
368
- "licenseFile": "node_modules/lodash/LICENSE",
369
- "licenseUrl": "https://github.com/lodash/lodash/blob/v4.17.15/LICENSE",
370
- "licenseTextSource": "file",
371
- "publisher": "John-David Dalton",
372
- "email": "john.david.dalton@gmail.com"
373
- },
374
361
  "memcached@2.2.2": {
375
362
  "name": "memcached",
376
363
  "version": "2.2.2",
@@ -1,5 +0,0 @@
1
- ### Hello! We're glad you've joined us.
2
-
3
- We believe participation in our community should be a harassment free experience for everyone.
4
-
5
- Learn more about our guidelines and principles by reading our [Code of Conduct](https://opensource.newrelic.com/code-of-conduct/) on our Open Source Website.