newrelic 8.11.1 → 8.11.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,3 +1,7 @@
1
+ ### v8.11.2 (2022-05-23)
2
+
3
+ * Fixed winston instrumentation to no longer coerce every log line to be json.
4
+
1
5
  ### v8.11.1 (2022-05-13)
2
6
 
3
7
  * Fixed an issue with winston instrumentation that caused agent to crash when creating a winston logger from an existing instantiated logger.
@@ -19,7 +19,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
19
19
  * [@newrelic/aws-sdk](#newrelicaws-sdk)
20
20
  * [@newrelic/koa](#newrelickoa)
21
21
  * [@newrelic/superagent](#newrelicsuperagent)
22
- * [@newrelic/winston-enricher](#newrelicwinston-enricher)
23
22
  * [@tyriar/fibonacci-heap](#tyriarfibonacci-heap)
24
23
  * [async](#async)
25
24
  * [concat-stream](#concat-stream)
@@ -1129,215 +1128,6 @@ This product includes source derived from [@newrelic/superagent](https://github.
1129
1128
 
1130
1129
  ```
1131
1130
 
1132
- ### @newrelic/winston-enricher
1133
-
1134
- This product includes source derived from [@newrelic/winston-enricher](https://github.com/newrelic/newrelic-node-log-extensions) ([v3.1.1](https://github.com/newrelic/newrelic-node-log-extensions/tree/v3.1.1)), distributed under the [Apache-2.0 License](https://github.com/newrelic/newrelic-node-log-extensions/blob/v3.1.1/LICENSE):
1135
-
1136
- ```
1137
- Apache License
1138
- Version 2.0, January 2004
1139
- http://www.apache.org/licenses/
1140
-
1141
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1142
-
1143
- 1. Definitions.
1144
-
1145
- "License" shall mean the terms and conditions for use, reproduction,
1146
- and distribution as defined by Sections 1 through 9 of this document.
1147
-
1148
- "Licensor" shall mean the copyright owner or entity authorized by
1149
- the copyright owner that is granting the License.
1150
-
1151
- "Legal Entity" shall mean the union of the acting entity and all
1152
- other entities that control, are controlled by, or are under common
1153
- control with that entity. For the purposes of this definition,
1154
- "control" means (i) the power, direct or indirect, to cause the
1155
- direction or management of such entity, whether by contract or
1156
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
1157
- outstanding shares, or (iii) beneficial ownership of such entity.
1158
-
1159
- "You" (or "Your") shall mean an individual or Legal Entity
1160
- exercising permissions granted by this License.
1161
-
1162
- "Source" form shall mean the preferred form for making modifications,
1163
- including but not limited to software source code, documentation
1164
- source, and configuration files.
1165
-
1166
- "Object" form shall mean any form resulting from mechanical
1167
- transformation or translation of a Source form, including but
1168
- not limited to compiled object code, generated documentation,
1169
- and conversions to other media types.
1170
-
1171
- "Work" shall mean the work of authorship, whether in Source or
1172
- Object form, made available under the License, as indicated by a
1173
- copyright notice that is included in or attached to the work
1174
- (an example is provided in the Appendix below).
1175
-
1176
- "Derivative Works" shall mean any work, whether in Source or Object
1177
- form, that is based on (or derived from) the Work and for which the
1178
- editorial revisions, annotations, elaborations, or other modifications
1179
- represent, as a whole, an original work of authorship. For the purposes
1180
- of this License, Derivative Works shall not include works that remain
1181
- separable from, or merely link (or bind by name) to the interfaces of,
1182
- the Work and Derivative Works thereof.
1183
-
1184
- "Contribution" shall mean any work of authorship, including
1185
- the original version of the Work and any modifications or additions
1186
- to that Work or Derivative Works thereof, that is intentionally
1187
- submitted to Licensor for inclusion in the Work by the copyright owner
1188
- or by an individual or Legal Entity authorized to submit on behalf of
1189
- the copyright owner. For the purposes of this definition, "submitted"
1190
- means any form of electronic, verbal, or written communication sent
1191
- to the Licensor or its representatives, including but not limited to
1192
- communication on electronic mailing lists, source code control systems,
1193
- and issue tracking systems that are managed by, or on behalf of, the
1194
- Licensor for the purpose of discussing and improving the Work, but
1195
- excluding communication that is conspicuously marked or otherwise
1196
- designated in writing by the copyright owner as "Not a Contribution."
1197
-
1198
- "Contributor" shall mean Licensor and any individual or Legal Entity
1199
- on behalf of whom a Contribution has been received by Licensor and
1200
- subsequently incorporated within the Work.
1201
-
1202
- 2. Grant of Copyright License. Subject to the terms and conditions of
1203
- this License, each Contributor hereby grants to You a perpetual,
1204
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1205
- copyright license to reproduce, prepare Derivative Works of,
1206
- publicly display, publicly perform, sublicense, and distribute the
1207
- Work and such Derivative Works in Source or Object form.
1208
-
1209
- 3. Grant of Patent License. Subject to the terms and conditions of
1210
- this License, each Contributor hereby grants to You a perpetual,
1211
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1212
- (except as stated in this section) patent license to make, have made,
1213
- use, offer to sell, sell, import, and otherwise transfer the Work,
1214
- where such license applies only to those patent claims licensable
1215
- by such Contributor that are necessarily infringed by their
1216
- Contribution(s) alone or by combination of their Contribution(s)
1217
- with the Work to which such Contribution(s) was submitted. If You
1218
- institute patent litigation against any entity (including a
1219
- cross-claim or counterclaim in a lawsuit) alleging that the Work
1220
- or a Contribution incorporated within the Work constitutes direct
1221
- or contributory patent infringement, then any patent licenses
1222
- granted to You under this License for that Work shall terminate
1223
- as of the date such litigation is filed.
1224
-
1225
- 4. Redistribution. You may reproduce and distribute copies of the
1226
- Work or Derivative Works thereof in any medium, with or without
1227
- modifications, and in Source or Object form, provided that You
1228
- meet the following conditions:
1229
-
1230
- (a) You must give any other recipients of the Work or
1231
- Derivative Works a copy of this License; and
1232
-
1233
- (b) You must cause any modified files to carry prominent notices
1234
- stating that You changed the files; and
1235
-
1236
- (c) You must retain, in the Source form of any Derivative Works
1237
- that You distribute, all copyright, patent, trademark, and
1238
- attribution notices from the Source form of the Work,
1239
- excluding those notices that do not pertain to any part of
1240
- the Derivative Works; and
1241
-
1242
- (d) If the Work includes a "NOTICE" text file as part of its
1243
- distribution, then any Derivative Works that You distribute must
1244
- include a readable copy of the attribution notices contained
1245
- within such NOTICE file, excluding those notices that do not
1246
- pertain to any part of the Derivative Works, in at least one
1247
- of the following places: within a NOTICE text file distributed
1248
- as part of the Derivative Works; within the Source form or
1249
- documentation, if provided along with the Derivative Works; or,
1250
- within a display generated by the Derivative Works, if and
1251
- wherever such third-party notices normally appear. The contents
1252
- of the NOTICE file are for informational purposes only and
1253
- do not modify the License. You may add Your own attribution
1254
- notices within Derivative Works that You distribute, alongside
1255
- or as an addendum to the NOTICE text from the Work, provided
1256
- that such additional attribution notices cannot be construed
1257
- as modifying the License.
1258
-
1259
- You may add Your own copyright statement to Your modifications and
1260
- may provide additional or different license terms and conditions
1261
- for use, reproduction, or distribution of Your modifications, or
1262
- for any such Derivative Works as a whole, provided Your use,
1263
- reproduction, and distribution of the Work otherwise complies with
1264
- the conditions stated in this License.
1265
-
1266
- 5. Submission of Contributions. Unless You explicitly state otherwise,
1267
- any Contribution intentionally submitted for inclusion in the Work
1268
- by You to the Licensor shall be under the terms and conditions of
1269
- this License, without any additional terms or conditions.
1270
- Notwithstanding the above, nothing herein shall supersede or modify
1271
- the terms of any separate license agreement you may have executed
1272
- with Licensor regarding such Contributions.
1273
-
1274
- 6. Trademarks. This License does not grant permission to use the trade
1275
- names, trademarks, service marks, or product names of the Licensor,
1276
- except as required for reasonable and customary use in describing the
1277
- origin of the Work and reproducing the content of the NOTICE file.
1278
-
1279
- 7. Disclaimer of Warranty. Unless required by applicable law or
1280
- agreed to in writing, Licensor provides the Work (and each
1281
- Contributor provides its Contributions) on an "AS IS" BASIS,
1282
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1283
- implied, including, without limitation, any warranties or conditions
1284
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
1285
- PARTICULAR PURPOSE. You are solely responsible for determining the
1286
- appropriateness of using or redistributing the Work and assume any
1287
- risks associated with Your exercise of permissions under this License.
1288
-
1289
- 8. Limitation of Liability. In no event and under no legal theory,
1290
- whether in tort (including negligence), contract, or otherwise,
1291
- unless required by applicable law (such as deliberate and grossly
1292
- negligent acts) or agreed to in writing, shall any Contributor be
1293
- liable to You for damages, including any direct, indirect, special,
1294
- incidental, or consequential damages of any character arising as a
1295
- result of this License or out of the use or inability to use the
1296
- Work (including but not limited to damages for loss of goodwill,
1297
- work stoppage, computer failure or malfunction, or any and all
1298
- other commercial damages or losses), even if such Contributor
1299
- has been advised of the possibility of such damages.
1300
-
1301
- 9. Accepting Warranty or Additional Liability. While redistributing
1302
- the Work or Derivative Works thereof, You may choose to offer,
1303
- and charge a fee for, acceptance of support, warranty, indemnity,
1304
- or other liability obligations and/or rights consistent with this
1305
- License. However, in accepting such obligations, You may act only
1306
- on Your own behalf and on Your sole responsibility, not on behalf
1307
- of any other Contributor, and only if You agree to indemnify,
1308
- defend, and hold each Contributor harmless for any liability
1309
- incurred by, or claims asserted against, such Contributor by reason
1310
- of your accepting any such warranty or additional liability.
1311
-
1312
- END OF TERMS AND CONDITIONS
1313
-
1314
- APPENDIX: How to apply the Apache License to your work.
1315
-
1316
- To apply the Apache License to your work, attach the following
1317
- boilerplate notice, with the fields enclosed by brackets "[]"
1318
- replaced with your own identifying information. (Don't include
1319
- the brackets!) The text should be enclosed in the appropriate
1320
- comment syntax for the file format. We also recommend that a
1321
- file or class name and description of purpose be included on the
1322
- same "printed page" as the copyright notice for easier
1323
- identification within third-party archives.
1324
-
1325
- Copyright 2019 New Relic, Inc.
1326
-
1327
- Licensed under the Apache License, Version 2.0 (the "License");
1328
- you may not use this file except in compliance with the License.
1329
- You may obtain a copy of the License at
1330
-
1331
- http://www.apache.org/licenses/LICENSE-2.0
1332
-
1333
- Unless required by applicable law or agreed to in writing, software
1334
- distributed under the License is distributed on an "AS IS" BASIS,
1335
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1336
- See the License for the specific language governing permissions and
1337
- limitations under the License.
1338
-
1339
- ```
1340
-
1341
1131
  ### @tyriar/fibonacci-heap
1342
1132
 
1343
1133
  This product includes source derived from [@tyriar/fibonacci-heap](https://github.com/gwtw/ts-fibonacci-heap) ([v2.0.9](https://github.com/gwtw/ts-fibonacci-heap/tree/v2.0.9)), distributed under the [MIT License](https://github.com/gwtw/ts-fibonacci-heap/blob/v2.0.9/LICENSE):
package/api.js CHANGED
@@ -150,32 +150,7 @@ API.prototype.getLinkingMetadata = function getLinkingMetadata(omitSupportabilit
150
150
  metric.incrementCallCount()
151
151
  }
152
152
 
153
- const agent = this.agent
154
-
155
- const segment = agent.tracer.getSegment()
156
- const config = agent.config
157
-
158
- const linkingMetadata = {
159
- 'entity.name': config.applications()[0],
160
- 'entity.type': 'SERVICE',
161
- 'hostname': config.getHostnameSafe()
162
- }
163
-
164
- if (config.distributed_tracing.enabled && segment) {
165
- linkingMetadata['trace.id'] = segment.transaction.traceId
166
- const spanId = segment.getSpanId()
167
- if (spanId) {
168
- linkingMetadata['span.id'] = spanId
169
- }
170
- } else {
171
- logger.debug('getLinkingMetadata with no active transaction')
172
- }
173
-
174
- if (config.entity_guid) {
175
- linkingMetadata['entity.guid'] = config.entity_guid
176
- }
177
-
178
- return linkingMetadata
153
+ return this.agent.getLinkingMetadata()
179
154
  }
180
155
 
181
156
  /**
package/lib/agent.js CHANGED
@@ -923,6 +923,76 @@ Agent.prototype._listenForConfigChanges = function _listenForConfigChanges() {
923
923
  })
924
924
  }
925
925
 
926
+ /**
927
+ * This method returns an object with the following keys/data:
928
+ * - `trace.id`: The current trace ID
929
+ * - `span.id`: The current span ID
930
+ * - `entity.name`: The application name specified in the connect request as
931
+ * app_name. If multiple application names are specified this will only be
932
+ * the first name
933
+ * - `entity.type`: The string "SERVICE"
934
+ * - `entity.guid`: The entity ID returned in the connect reply as entity_guid
935
+ * - `hostname`: The hostname as specified in the connect request as
936
+ * utilization.full_hostname. If utilization.full_hostname is null or empty,
937
+ * this will be the hostname specified in the connect request as host.
938
+ *
939
+ * @returns {LinkingMetadata} The linking object with the data above
940
+ */
941
+ Agent.prototype.getLinkingMetadata = function getLinkingMetadata() {
942
+ const segment = this.tracer.getSegment()
943
+ const config = this.config
944
+
945
+ const linkingMetadata = {
946
+ 'entity.name': config.applications()[0],
947
+ 'entity.type': 'SERVICE',
948
+ 'hostname': config.getHostnameSafe()
949
+ }
950
+
951
+ if (config.distributed_tracing.enabled && segment) {
952
+ linkingMetadata['trace.id'] = segment.transaction.traceId
953
+ const spanId = segment.getSpanId()
954
+ if (spanId) {
955
+ linkingMetadata['span.id'] = spanId
956
+ }
957
+ } else {
958
+ logger.debug('getLinkingMetadata with no active transaction')
959
+ }
960
+
961
+ if (config.entity_guid) {
962
+ linkingMetadata['entity.guid'] = config.entity_guid
963
+ }
964
+
965
+ return linkingMetadata
966
+ }
967
+
968
+ /**
969
+ * Formats the NR-LINKING blob that matches the spec
970
+ *
971
+ * @returns {string} formatted NR-LINKING string
972
+ */
973
+ Agent.prototype.getNRLinkingMetadata = function getNRLinkingMetadata() {
974
+ const metadata = this.getLinkingMetadata()
975
+ const nrLinkingMeta = [
976
+ getValue('entity.guid'),
977
+ getValue('hostname'),
978
+ getValue('trace.id'),
979
+ getValue('span.id'),
980
+ encodeURIComponent(getValue('entity.name'))
981
+ ]
982
+
983
+ return ` NR-LINKING|${nrLinkingMeta.join('|')}|`
984
+
985
+ /**
986
+ * Retries value for a given key but defaults to `` if falsey
987
+ *
988
+ * @param {string} key in linking metadata
989
+ * @returns {string}
990
+ */
991
+ function getValue(key) {
992
+ return metadata[key] || ''
993
+ }
994
+ }
995
+
926
996
  function generateEventHarvestSupportMetrics(agent, harvestConfig) {
927
997
  const harvestLimits = harvestConfig.harvest_limits
928
998
 
@@ -5,44 +5,26 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const createFormatter = require('@newrelic/winston-enricher/lib/createFormatter')
9
- const API = require('../../api')
10
8
  const Stream = require('stream')
11
-
12
- /**
13
- * winston allows you to compose a logger
14
- * from an instantiated logger. Through a series
15
- * of inherited classes, this logger instance is a Stream.
16
- * Check what gets passed into `winston.createLogger` to avoid
17
- * instrumenting an already instrumented instance of a logger.
18
- *
19
- * @param {*} obj obj to check if a stream
20
- * @returns {boolean}
21
- */
22
- function isStream(obj) {
23
- return obj instanceof Stream
24
- }
9
+ const {
10
+ isApplicationLoggingEnabled,
11
+ isLogForwardingEnabled,
12
+ isLocalDecoratingEnabled,
13
+ isMetricsEnabled,
14
+ createModuleUsageMetric,
15
+ incrementLoggingLinesMetrics,
16
+ truncate
17
+ } = require('../util/application-logging')
18
+ const logger = require('../logger').child({ component: 'winston' })
25
19
 
26
20
  module.exports = function instrument(agent, winston, _, shim) {
27
21
  const config = agent.config
28
- if (
29
- !(
30
- config.application_logging.enabled &&
31
- (config.application_logging.forwarding.enabled ||
32
- config.application_logging.metrics.enabled ||
33
- config.application_logging.local_decorating.enabled)
34
- )
35
- ) {
36
- shim.logger.debug('Application logging not enabled. Not instrumenting winston...')
22
+
23
+ if (!isApplicationLoggingEnabled(config)) {
24
+ logger.debug('Application logging not enabled. Not instrumenting winston.')
37
25
  return
38
26
  }
39
27
 
40
- // create an instrumented formatter to enrich and report logs
41
- const api = new API(agent)
42
- api.shim = shim
43
- const instrumentedFormatter = createFormatter(api, winston)
44
-
45
- // wrap logger creation to combine or insert our formatter
46
28
  shim.wrap(winston, 'createLogger', function wrapCreate(shim, createLogger) {
47
29
  return function createWrappedLogger() {
48
30
  const args = shim.argsToArray.apply(shim, arguments)
@@ -51,24 +33,155 @@ module.exports = function instrument(agent, winston, _, shim) {
51
33
  return createLogger.apply(this, args)
52
34
  }
53
35
 
54
- if ('transports' in opts) {
55
- // combine transport-level formatters with our own
56
- opts.transports = opts.transports.map((transport) => {
57
- if (transport.format) {
58
- transport.format = winston.format.combine(transport.format, instrumentedFormatter())
59
- } else {
60
- transport.format = instrumentedFormatter()
61
- }
62
- return transport
63
- })
64
- } else if ('format' in opts) {
65
- // combine top-level formatter with our own
66
- opts.format = winston.format.combine(opts.format, instrumentedFormatter())
67
- } else {
68
- opts.format = instrumentedFormatter()
69
- }
36
+ registerFormatter({ opts, config, agent, winston })
70
37
 
71
38
  return createLogger.apply(this, args)
72
39
  }
73
40
  })
74
41
  }
42
+
43
+ /**
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.
50
+ *
51
+ * @param {object} params object passed to function
52
+ * @param {object} params.opts options from winston.createLogger
53
+ * @param {object} params.config agent config
54
+ * @param {object} params.agent NR agent
55
+ * @param {object} params.winston exported winston package
56
+ */
57
+ function registerFormatter({ opts, config, agent, winston }) {
58
+ const instrumentedFormatter = nrWinstonFormatter(agent, winston)
59
+
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)
70
+ } else {
71
+ opts.format = instrumentedFormatter()
72
+ }
73
+ }
74
+
75
+ /**
76
+ * 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.
83
+ *
84
+ * Local log decorating appends `NR-LINKING` piped metadata to
85
+ * the message key in log line. You must configure a log forwarder to get
86
+ * this data to NR1.
87
+ *
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
+ * @param {object} agent NR agent
92
+ * @param {object} winston exported winston package
93
+ * @returns {object} log line with NR context or NR-LINKING metadata on message
94
+ */
95
+ function nrWinstonFormatter(agent, winston) {
96
+ const config = agent.config
97
+ const metrics = agent.metrics
98
+ createModuleUsageMetric('winston', metrics)
99
+
100
+ return winston.format((logLine) => {
101
+ if (isMetricsEnabled(config)) {
102
+ incrementLoggingLinesMetrics(logLine.level, metrics)
103
+ }
104
+
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)) {
110
+ logLine.message += agent.getNRLinkingMetadata()
111
+ }
112
+
113
+ return logLine
114
+ })
115
+ }
116
+
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
+ /**
176
+ * winston allows you to compose a logger
177
+ * from an instantiated logger. Through a series
178
+ * of inherited classes, this logger instance is a Stream.
179
+ * Check what gets passed into `winston.createLogger` to avoid
180
+ * instrumenting an already instrumented instance of a logger.
181
+ *
182
+ * @param {*} obj obj to check if a stream
183
+ * @returns {boolean} is object is a stream or not
184
+ */
185
+ function isStream(obj) {
186
+ return obj instanceof Stream
187
+ }
@@ -273,6 +273,10 @@ const LOGGING = {
273
273
  DEBUG: `${LOGGING_LINES_PREFIX}/DEBUG`,
274
274
  TRACE: `${LOGGING_LINES_PREFIX}/TRACE`
275
275
  },
276
+ LIBS: {
277
+ PINO: `${SUPPORTABILITY.LOGGING}/${NODEJS.PREFIX}pino/enabled`,
278
+ WINSTON: `${SUPPORTABILITY.LOGGING}/${NODEJS.PREFIX}winston/enabled`
279
+ },
276
280
  DROPPED: `Logging/Forwarding/Dropped`,
277
281
  SEEN: `${LOGGING_FORWARDING_PREFIX}/Seen`,
278
282
  SENT: `${LOGGING_FORWARDING_PREFIX}/Sent`,
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Copyright 2022 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ 'use strict'
7
+ const utils = module.exports
8
+ const MAX_LENGTH = 1021
9
+ const OUTPUT_LENGTH = 1024
10
+ const { LOGGING } = require('../metrics/names')
11
+
12
+ /**
13
+ * Truncates a string to MAX_LENGTH constant above.
14
+ *
15
+ * @param {string} str string to truncate
16
+ * @returns {string}
17
+ */
18
+ utils.truncate = function truncate(str) {
19
+ if (str.length > OUTPUT_LENGTH) {
20
+ return str.substring(0, MAX_LENGTH) + '...'
21
+ }
22
+
23
+ return str
24
+ }
25
+
26
+ /**
27
+ * Checks if application_logging and one of the features are enabled
28
+ *
29
+ * @param {object} config agent config
30
+ * @returns {boolean} is application logging enabled
31
+ */
32
+ utils.isApplicationLoggingEnabled = function isApplicationLoggingEnabled(config) {
33
+ return !!(
34
+ config.application_logging.enabled &&
35
+ (config.application_logging.metrics.enabled ||
36
+ config.application_logging.forwarding.enabled ||
37
+ config.application_logging.local_decorating.enabled)
38
+ )
39
+ }
40
+
41
+ /**
42
+ * Checks if application_logging and application_logging.metrics are both enabled
43
+ *
44
+ * @param {object} config agent config
45
+ * @returns {boolean} is metrics enabled
46
+ */
47
+ utils.isMetricsEnabled = function isMetricsEnabled(config) {
48
+ return !!(config.application_logging.enabled && config.application_logging.metrics.enabled)
49
+ }
50
+
51
+ /**
52
+ * Checks if application_logging and application_logging.local_decorating are both enabled
53
+ *
54
+ * @param {object} config agent config
55
+ * @returns {boolean} is forwarding enabled
56
+ */
57
+ utils.isLocalDecoratingEnabled = function isLocalDecoratingEnabled(config) {
58
+ return !!(
59
+ config.application_logging.enabled && config.application_logging.local_decorating.enabled
60
+ )
61
+ }
62
+
63
+ /**
64
+ * Checks if log aggregator exists on agent & application_logging and application_logging.forwarding are both enabled
65
+ *
66
+ * @param {object} config agent config
67
+ * @param {Agent} agent Node.js agent
68
+ * @returns {boolean} is forwarding enabled
69
+ */
70
+ utils.isLogForwardingEnabled = function isLogForwardingEnabled(config, agent) {
71
+ return !!(
72
+ agent.logs &&
73
+ config.application_logging.enabled &&
74
+ config.application_logging.forwarding.enabled
75
+ )
76
+ }
77
+
78
+ /**
79
+ * Increments both `Logging/lines` and `Logging/lines/<level>` call count
80
+ *
81
+ * @param {string} level log level
82
+ * @param {object} metrics metrics module
83
+ */
84
+ utils.incrementLoggingLinesMetrics = function incrementLoggingLinesMetrics(level, metrics) {
85
+ metrics.getOrCreateMetric(LOGGING.LINES).incrementCallCount()
86
+ metrics.getOrCreateMetric(LOGGING.LEVELS[level.toUpperCase()]).incrementCallCount()
87
+ }
88
+
89
+ /**
90
+ * Increments call count when instrumentation for a logging library is loaded
91
+ *
92
+ * @param {string} lib name of library
93
+ * @param {object} metrics agent metrics instance
94
+ */
95
+ utils.createModuleUsageMetric = function createModuleUsageMetric(lib, metrics) {
96
+ metrics.getOrCreateMetric(LOGGING.LIBS[lib.toUpperCase()]).incrementCallCount()
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newrelic",
3
- "version": "8.11.1",
3
+ "version": "8.11.2",
4
4
  "author": "New Relic Node.js agent team <nodejs@newrelic.com>",
5
5
  "license": "Apache-2.0",
6
6
  "contributors": [
@@ -164,7 +164,6 @@
164
164
  "@newrelic/aws-sdk": "^4.1.1",
165
165
  "@newrelic/koa": "^6.1.1",
166
166
  "@newrelic/superagent": "^5.1.0",
167
- "@newrelic/winston-enricher": "^3.1.1",
168
167
  "@tyriar/fibonacci-heap": "^2.0.7",
169
168
  "async": "^3.2.3",
170
169
  "concat-stream": "^2.0.0",