newrelic 6.12.1 → 6.13.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/NEWS.md +4 -0
- package/lib/collector/serverless.js +40 -13
- package/package.json +1 -1
package/NEWS.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
### 6.13.0 (2020-08-25):
|
|
2
|
+
|
|
3
|
+
* Added ability for the agent to write to a named pipe, instead of stdout, when in serverless mode.
|
|
4
|
+
|
|
1
5
|
### 6.12.1 (2020-08-20):
|
|
2
6
|
|
|
3
7
|
* **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).
|
|
@@ -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,8 @@ class ServerlessCollector {
|
|
|
35
38
|
agent_version: agent.version
|
|
36
39
|
}
|
|
37
40
|
this.payload = {}
|
|
41
|
+
this.pipePath = pipePath || process.env.NEWRELIC_PIPE_PATH || defaultPipePath
|
|
42
|
+
this.shouldUsePipe = fs.existsSync(this.pipePath)
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/**
|
|
@@ -243,6 +248,37 @@ class ServerlessCollector {
|
|
|
243
248
|
}
|
|
244
249
|
}
|
|
245
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Writes payload to pipe
|
|
253
|
+
*/
|
|
254
|
+
flushToPipeSync(payload) {
|
|
255
|
+
try {
|
|
256
|
+
fs.writeFileSync(this.pipePath, payload)
|
|
257
|
+
return true
|
|
258
|
+
} catch (e) {
|
|
259
|
+
this.shouldUsePipe = false
|
|
260
|
+
logger.warn('Error attempting to write to pipe, falling back to stdout', e)
|
|
261
|
+
return false
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
flushToStdOut(serializedPayload, payloadLength, sync = false) {
|
|
266
|
+
if (sync) {
|
|
267
|
+
// Long log lines have been truncated at 65538
|
|
268
|
+
// Guarantees process.stdout will block, so long logs
|
|
269
|
+
// won't be truncated if process.exit() is called early.
|
|
270
|
+
const s = process.stdout
|
|
271
|
+
payloadLength > 65000 &&
|
|
272
|
+
s._handle &&
|
|
273
|
+
s._handle.setBlocking &&
|
|
274
|
+
s._handle.setBlocking(true)
|
|
275
|
+
|
|
276
|
+
fs.writeSync(process.stdout.fd, serializedPayload)
|
|
277
|
+
} else {
|
|
278
|
+
process.stdout.write(serializedPayload)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
246
282
|
/**
|
|
247
283
|
* Internal method to handle flushing to stdout.
|
|
248
284
|
*
|
|
@@ -258,19 +294,10 @@ class ServerlessCollector {
|
|
|
258
294
|
payload
|
|
259
295
|
]) + '\n'
|
|
260
296
|
|
|
261
|
-
|
|
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)
|
|
297
|
+
const didUsePipe = this.shouldUsePipe && this.flushToPipeSync(serializedPayload)
|
|
270
298
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
process.stdout.write(serializedPayload)
|
|
299
|
+
if (!didUsePipe) {
|
|
300
|
+
this.flushToStdOut(serializedPayload, payload.length, sync)
|
|
274
301
|
}
|
|
275
302
|
}
|
|
276
303
|
}
|