newrelic 8.12.0 → 8.13.2

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 CHANGED
@@ -1,25 +1,41 @@
1
- ### v8.12.0 (2022-05-24)
1
+ ### v8.13.2 (2022-05-31)
2
2
 
3
- * Added instrumentation to pino to support application logging use cases: forwarding, local decorating, and metrics.
4
-
5
- * Added supportability metrics about the data usage bytes of harvested data to the collector endpoints.
6
-
7
- * Added an optional way to avoid wrapping browser agent script with <script> tag when using `api.getBrowserTimingHeader`. This will ease usage with Component based libraries like React.
8
-
9
- Thanks to @github-dd-nicolas for the contribution. 🎉
10
-
11
- * Upgraded `@grpc/proto-loader` to fix a [CVE](https://security.snyk.io/vuln/SNYK-JS-PROTOBUFJS-2441248) with `protobufjs`.
12
-
13
- * Upgraded `@newrelic/test-utilities` to resolve a dev-only audit warning.
14
-
15
- ### v8.11.2 (2022-05-23)
16
-
17
- * Fixed winston instrumentation to no longer coerce every log line to be json.
18
-
19
- ### v8.11.1 (2022-05-13)
20
-
21
- * Fixed an issue with winston instrumentation that caused agent to crash when creating a winston logger from an existing instantiated logger.
3
+ * Upgraded `protobufjs` to resolve CVE-2022-25878
22
4
 
5
+ ### v8.13.1 (2022-05-27)
6
+
7
+ * Fixed passing undefined as a formatter options to `winston.format.combine`
8
+
9
+ Thanks to Rana Mohammad (@rjmohammad) for the contribution. 🎉
10
+
11
+ ### v8.13.0 (2022-05-26)
12
+
13
+ * Moved log forwarding logic to a transport so customer transports are not polluted with NR linking metadata and timestamp and error manipulations.
14
+
15
+ * Prevented transmitting logs when application level logging has been disabled.
16
+
17
+ ### v8.12.0 (2022-05-24)
18
+
19
+ * Added instrumentation to pino to support application logging use cases: forwarding, local decorating, and metrics.
20
+
21
+ * Added supportability metrics about the data usage bytes of harvested data to the collector endpoints.
22
+
23
+ * Added an optional way to avoid wrapping browser agent script with <script> tag when using `api.getBrowserTimingHeader`. This will ease usage with Component based libraries like React.
24
+
25
+ Thanks to @github-dd-nicolas for the contribution. 🎉
26
+
27
+ * Upgraded `@grpc/proto-loader` to fix a [CVE](https://security.snyk.io/vuln/SNYK-JS-PROTOBUFJS-2441248) with `protobufjs`.
28
+
29
+ * Upgraded `@newrelic/test-utilities` to resolve a dev-only audit warning.
30
+
31
+ ### v8.11.2 (2022-05-23)
32
+
33
+ * Fixed winston instrumentation to no longer coerce every log line to be json.
34
+
35
+ ### v8.11.1 (2022-05-13)
36
+
37
+ * Fixed an issue with winston instrumentation that caused agent to crash when creating a winston logger from an existing instantiated logger.
38
+
23
39
  ### v8.11.0 (2022-05-11)
24
40
 
25
41
  * Added application logging for Winston in the Node.js agent
@@ -26,6 +26,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
26
26
  * [json-stringify-safe](#json-stringify-safe)
27
27
  * [readable-stream](#readable-stream)
28
28
  * [semver](#semver)
29
+ * [winston-transport](#winston-transport)
29
30
 
30
31
  **[devDependencies](#devDependencies)**
31
32
 
@@ -1330,6 +1331,36 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1330
1331
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1331
1332
  IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1332
1333
 
1334
+ ```
1335
+
1336
+ ### winston-transport
1337
+
1338
+ This product includes source derived from [winston-transport](https://github.com/winstonjs/winston-transport) ([v4.5.0](https://github.com/winstonjs/winston-transport/tree/v4.5.0)), distributed under the [MIT License](https://github.com/winstonjs/winston-transport/blob/v4.5.0/LICENSE):
1339
+
1340
+ ```
1341
+ The MIT License (MIT)
1342
+
1343
+ Copyright (c) 2015 Charlie Robbins & the contributors.
1344
+
1345
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1346
+ of this software and associated documentation files (the "Software"), to deal
1347
+ in the Software without restriction, including without limitation the rights
1348
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1349
+ copies of the Software, and to permit persons to whom the Software is
1350
+ furnished to do so, subject to the following conditions:
1351
+
1352
+ The above copyright notice and this permission notice shall be included in all
1353
+ copies or substantial portions of the Software.
1354
+
1355
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1356
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1357
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1358
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1359
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1360
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1361
+ SOFTWARE.
1362
+
1363
+
1333
1364
  ```
1334
1365
 
1335
1366
 
@@ -1770,7 +1801,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1770
1801
 
1771
1802
  ### @newrelic/test-utilities
1772
1803
 
1773
- This product includes source derived from [@newrelic/test-utilities](https://github.com/newrelic/node-test-utilities) ([v6.5.3](https://github.com/newrelic/node-test-utilities/tree/v6.5.3)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-test-utilities/blob/v6.5.3/LICENSE):
1804
+ This product includes source derived from [@newrelic/test-utilities](https://github.com/newrelic/node-test-utilities) ([v6.5.4](https://github.com/newrelic/node-test-utilities/tree/v6.5.4)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-test-utilities/blob/v6.5.4/LICENSE):
1774
1805
 
1775
1806
  ```
1776
1807
  Apache License
@@ -65,6 +65,17 @@ class LogAggregator extends EventAggregator {
65
65
  super.add(logLine, priority)
66
66
  })
67
67
  }
68
+
69
+ reconfigure(config) {
70
+ const oldLimit = this.limit
71
+ super.reconfigure(config)
72
+ if (this.limit <= 0 && oldLimit > 0) {
73
+ logger.debug('This New Relic account has disabled APM logs.')
74
+ this.clear()
75
+ } else if (oldLimit <= 0 && this.limit > 0) {
76
+ logger.debug('This New Relic account has re-enabled APM logs.')
77
+ }
78
+ }
68
79
  }
69
80
 
70
81
  module.exports = LogAggregator
@@ -0,0 +1,108 @@
1
+ /*
2
+ * Copyright 2022 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ 'use strict'
7
+ const TransportStream = require('winston-transport')
8
+ const logger = require('../logger').child({ component: 'nr-winston-transport' })
9
+ const { truncate } = require('../util/application-logging')
10
+
11
+ /**
12
+ * Transport used to prepare a log line and add to the new relic agent
13
+ * log aggregator.
14
+ *
15
+ * Note*: This copies the log line so no other transports will get the
16
+ * mutated data.
17
+ */
18
+ class NrTransport extends TransportStream {
19
+ constructor(opts = {}) {
20
+ // set this option to have winston handle uncaught exceptions
21
+ // See: https://github.com/winstonjs/winston#handling-uncaught-exceptions-with-winston
22
+ opts.handleExceptions = true
23
+ super(opts)
24
+ this.name = 'newrelic'
25
+ this.agent = opts.agent
26
+ this.config = opts.agent.config
27
+ }
28
+
29
+ /**
30
+ * Executed on every log line. We will get the linking metadata
31
+ * and add this, along with reformatting of timestamp and error
32
+ * to a copy of the log line
33
+ *
34
+ * @param {object} logLine a winston log line
35
+ * @param {Function} callback callback to invoke once we are done
36
+ */
37
+ log(logLine, callback) {
38
+ const metadata = this.agent.getLinkingMetadata()
39
+ const formattedLine = reformatLogLine(logLine, metadata, this.agent)
40
+ this.agent.logs.add(formattedLine)
41
+ callback()
42
+ }
43
+ }
44
+
45
+ module.exports = NrTransport
46
+
47
+ /**
48
+ * Reformats a log line by reformatting errors, timestamp and adding
49
+ * new relic linking metadata(context). When uncaught exceptions exist
50
+ * an exception property will exist on the log line. This will tell us
51
+ * that we need to reformat the error
52
+ *
53
+ * @param {object} logLine log line
54
+ * @param {object} metadata linking metadata
55
+ * @param {object} agent NR agent
56
+ * @returns {object} copy of log line with NR linking metadata
57
+ */
58
+ function reformatLogLine(logLine, metadata, agent) {
59
+ // Add the metadata to a copy of the logLine
60
+ const formattedLine = Object.assign({}, logLine, metadata)
61
+
62
+ if (formattedLine.exception === true) {
63
+ reformatError(formattedLine)
64
+ }
65
+
66
+ reformatTimestamp(formattedLine, agent)
67
+
68
+ return formattedLine
69
+ }
70
+
71
+ /**
72
+ * Decorates the log line with truncated error.message, error.class, and error.stack and removes
73
+ * trace and stack
74
+ *
75
+ * @param {object} logLine a log line
76
+ */
77
+ function reformatError(logLine) {
78
+ // Due to Winston internals sometimes the error on the logLine object is a string or an
79
+ // empty object, and so the message property is all we have
80
+ const errorMessage = logLine.error.message || logLine.message || ''
81
+
82
+ logLine['error.message'] = truncate(errorMessage)
83
+ logLine['error.class'] =
84
+ logLine.error.name === 'Error' ? logLine.error.constructor.name : logLine.error.name
85
+ logLine['error.stack'] = truncate(logLine.error.stack)
86
+ logLine.message = truncate(logLine.message)
87
+
88
+ // Removes additional capture of stack to reduce overall payload/log-line size.
89
+ // The server has a maximum of ~4k characters per line allowed.
90
+ delete logLine.trace
91
+ delete logLine.stack
92
+ }
93
+
94
+ /**
95
+ * Turns timestamp into unix timestamp. If timestamp existed it will move original
96
+ * to `original_timestamp` key
97
+ *
98
+ * @param {object} logLine a log line
99
+ */
100
+ function reformatTimestamp(logLine) {
101
+ if (logLine.timestamp) {
102
+ logger.traceOnce(
103
+ 'Overwriting `timestamp` key; assigning original value to `original_timestamp`.'
104
+ )
105
+ logLine.original_timestamp = logLine.timestamp
106
+ }
107
+ logLine.timestamp = Date.now()
108
+ }
@@ -12,10 +12,11 @@ const {
12
12
  isLocalDecoratingEnabled,
13
13
  isMetricsEnabled,
14
14
  createModuleUsageMetric,
15
- incrementLoggingLinesMetrics,
16
- truncate
15
+ incrementLoggingLinesMetrics
17
16
  } = require('../util/application-logging')
17
+
18
18
  const logger = require('../logger').child({ component: 'winston' })
19
+ const NrTransport = require('./nr-winston-transport')
19
20
 
20
21
  module.exports = function instrument(agent, winston, _, shim) {
21
22
  const config = agent.config
@@ -33,40 +34,38 @@ module.exports = function instrument(agent, winston, _, shim) {
33
34
  return createLogger.apply(this, args)
34
35
  }
35
36
 
36
- registerFormatter({ opts, config, agent, winston })
37
+ createModuleUsageMetric('winston', agent.metrics)
38
+
39
+ if (isLocalDecoratingEnabled(config) || isMetricsEnabled(config)) {
40
+ registerFormatter({ opts, agent, winston })
41
+ }
42
+
43
+ const winstonLogger = createLogger.apply(this, args)
37
44
 
38
- return createLogger.apply(this, args)
45
+ if (isLogForwardingEnabled(config, agent)) {
46
+ winstonLogger.add(new NrTransport({ agent }))
47
+ }
48
+
49
+ return winstonLogger
39
50
  }
40
51
  })
41
52
  }
42
53
 
43
54
  /**
44
- * There is no right way to do this. But since we are automagical
45
- * it is hard to predict how a customer uses winston. We will iterate over the formatters specified on the logger and add last if forwarder or first if local decorating.
46
- * This is because we want all the customizations of previous formatters before adding log log to log aggregator. But in the case of local decorating we want to do this first so any formatter that is transforming data will have the changes.
47
- *
48
- * Note: The logic explained above does not apply if a customer specifies multiple formats for a given transport.
49
- * We cannot instrument the formats on the transport because if a customer has multiple transports we would be duplicating logs when forwaring.
55
+ * Apply a formatter to keep track of logging metrics, and in the case of local decorating appending
56
+ * the NR-LINKING metadata to message. We want to do this first so any formatter that is transforming
57
+ * data will have the changes.
50
58
  *
51
59
  * @param {object} params object passed to function
52
60
  * @param {object} params.opts options from winston.createLogger
53
- * @param {object} params.config agent config
54
61
  * @param {object} params.agent NR agent
55
62
  * @param {object} params.winston exported winston package
56
63
  */
57
- function registerFormatter({ opts, config, agent, winston }) {
64
+ function registerFormatter({ opts, agent, winston }) {
58
65
  const instrumentedFormatter = nrWinstonFormatter(agent, winston)
59
66
 
60
- if ('format' in opts) {
61
- const formatters = [opts.format]
62
-
63
- if (isLogForwardingEnabled(config, agent)) {
64
- formatters.push(instrumentedFormatter())
65
- } else {
66
- formatters.unshift(instrumentedFormatter())
67
- }
68
-
69
- opts.format = winston.format.combine(...formatters)
67
+ if (opts.format) {
68
+ opts.format = winston.format.combine(instrumentedFormatter(), opts.format)
70
69
  } else {
71
70
  opts.format = instrumentedFormatter()
72
71
  }
@@ -74,39 +73,26 @@ function registerFormatter({ opts, config, agent, winston }) {
74
73
 
75
74
  /**
76
75
  * This formatter is being used to facilitate
77
- * the application logging use cases.
78
- * It is worth noting that the features below are mutually
79
- * exclusive.
80
- *
81
- * The application logging use cases are local log decorating
82
- * and log forwarding.
76
+ * the two application logging use cases: metrics and local log decorating.
83
77
  *
84
78
  * Local log decorating appends `NR-LINKING` piped metadata to
85
79
  * the message key in log line. You must configure a log forwarder to get
86
80
  * this data to NR1.
87
81
  *
88
- * Log forwarding includes the linking metadata as keys on logging
89
- * object as well as adds the log line to the agent log aggregator.
90
- *
91
82
  * @param {object} agent NR agent
92
83
  * @param {object} winston exported winston package
93
- * @returns {object} log line with NR context or NR-LINKING metadata on message
84
+ * @returns {object} log line NR-LINKING metadata on message when local log decorating is enabled
94
85
  */
95
86
  function nrWinstonFormatter(agent, winston) {
96
87
  const config = agent.config
97
88
  const metrics = agent.metrics
98
- createModuleUsageMetric('winston', metrics)
99
89
 
100
90
  return winston.format((logLine) => {
101
91
  if (isMetricsEnabled(config)) {
102
92
  incrementLoggingLinesMetrics(logLine.level, metrics)
103
93
  }
104
94
 
105
- if (isLogForwardingEnabled(config, agent)) {
106
- const metadata = agent.getLinkingMetadata()
107
- reformatLogLine(logLine, metadata, agent)
108
- agent.logs.add(logLine)
109
- } else if (isLocalDecoratingEnabled(config)) {
95
+ if (isLocalDecoratingEnabled(config)) {
110
96
  logLine.message += agent.getNRLinkingMetadata()
111
97
  }
112
98
 
@@ -114,64 +100,6 @@ function nrWinstonFormatter(agent, winston) {
114
100
  })
115
101
  }
116
102
 
117
- /**
118
- * Reformats a log line by reformatting errors, timestamp and adding
119
- * new relic linking metadata(context)
120
- *
121
- * @param {object} logLine log line
122
- * @param {object} metadata linking metadata
123
- * @param {object} agent NR agent
124
- */
125
- function reformatLogLine(logLine, metadata, agent) {
126
- if (logLine.exception === true) {
127
- reformatError(logLine)
128
- }
129
-
130
- reformatTimestamp(logLine, agent)
131
-
132
- // Add the metadata to the logLine object being logged
133
- Object.assign(logLine, metadata)
134
- }
135
-
136
- /**
137
- * Decorates the log line with truncated error.message, error.class, and error.stack and removes
138
- * trace and stack
139
- *
140
- * @param {object} logLine a log line
141
- */
142
- function reformatError(logLine) {
143
- // Due to Winston internals sometimes the error on the logLine object is a string or an
144
- // empty object, and so the message property is all we have
145
- const errorMessage = logLine.error.message || logLine.message || ''
146
-
147
- logLine['error.message'] = truncate(errorMessage)
148
- logLine['error.class'] =
149
- logLine.error.name === 'Error' ? logLine.error.constructor.name : logLine.error.name
150
- logLine['error.stack'] = truncate(logLine.error.stack)
151
- logLine.message = truncate(logLine.message)
152
-
153
- // Removes additional capture of stack to reduce overall payload/log-line size.
154
- // The server has a maximum of ~4k characters per line allowed.
155
- delete logLine.trace
156
- delete logLine.stack
157
- }
158
-
159
- /**
160
- * Turns timestamp into unix timestamp. If timestamp existed it will move original
161
- * to `original_timestamp` key
162
- *
163
- * @param {object} logLine a log line
164
- */
165
- function reformatTimestamp(logLine) {
166
- if (logLine.timestamp) {
167
- logger.traceOnce(
168
- 'Overwriting `timestamp` key; assigning original value to `original_timestamp`.'
169
- )
170
- logLine.original_timestamp = logLine.timestamp
171
- }
172
- logLine.timestamp = Date.now()
173
- }
174
-
175
103
  /**
176
104
  * winston allows you to compose a logger
177
105
  * from an instantiated logger. Through a series
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "8.12.0",
3
+ "version": "8.13.2",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [
@@ -170,7 +170,8 @@
170
170
  "https-proxy-agent": "^5.0.0",
171
171
  "json-stringify-safe": "^5.0.0",
172
172
  "readable-stream": "^3.6.0",
173
- "semver": "^5.3.0"
173
+ "semver": "^5.3.0",
174
+ "winston-transport": "^4.5.0"
174
175
  },
175
176
  "optionalDependencies": {
176
177
  "@newrelic/native-metrics": "^8.0.0"
@@ -179,7 +180,7 @@
179
180
  "@newrelic/eslint-config": "^0.0.3",
180
181
  "@newrelic/newrelic-oss-cli": "^0.1.2",
181
182
  "@newrelic/proxy": "^2.0.0",
182
- "@newrelic/test-utilities": "^6.5.3",
183
+ "@newrelic/test-utilities": "^6.5.4",
183
184
  "@octokit/rest": "^18.0.15",
184
185
  "@slack/bolt": "^3.7.0",
185
186
  "ajv": "^6.12.6",