newrelic 11.9.0 → 11.10.1
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 +30 -0
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/api.js +5 -5
- package/lib/collector/remote-method.js +16 -11
- package/lib/errors/index.js +3 -2
- package/lib/feature_flags.js +3 -3
- package/lib/instrumentation/openai.js +5 -0
- package/lib/shim/message-shim/common.js +34 -0
- package/lib/shim/message-shim/consume.js +167 -0
- package/lib/shim/{message-shim.js → message-shim/index.js} +22 -378
- package/lib/shim/message-shim/subscribe-consume.js +213 -0
- package/lib/shim/shim.js +354 -240
- package/lib/shim/specs/index.js +20 -0
- package/lib/shimmer.js +8 -2
- package/package.json +13 -3
package/NEWS.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
### v11.10.1 (2024-01-25)
|
|
2
|
+
|
|
3
|
+
#### Bug fixes
|
|
4
|
+
|
|
5
|
+
* Updated instrumentation registration to allow for instrumenting of a local file that does not exist within node_modules.
|
|
6
|
+
* To properly instrument a local file, you must pass in `absolutePath` with the absolute path to the file that is being instrumented along with the `moduleName` which in this case is just the file name without the extension. ([#1974](https://github.com/newrelic/node-newrelic/pull/1974)) ([f545b4e](https://github.com/newrelic/node-newrelic/commit/f545b4ebc3394f0a7179a51e156c6df28896edf0))
|
|
7
|
+
|
|
8
|
+
### v11.10.0 (2024-01-22)
|
|
9
|
+
|
|
10
|
+
#### Features
|
|
11
|
+
|
|
12
|
+
* Added llm attribute to all transactions that contain llm spans for openai ([#1946](https://github.com/newrelic/node-newrelic/pull/1946)) ([6312629](https://github.com/newrelic/node-newrelic/commit/6312629326c02fe3de4db91ee293eb71b7ddd042))
|
|
13
|
+
* Added transaction ID to ErrorTrace event ([#1954](https://github.com/newrelic/node-newrelic/pull/1954)) ([5d0ebcd](https://github.com/newrelic/node-newrelic/commit/5d0ebcd216cb60b3a488b2b5f7c20f71f8d5bbeb))
|
|
14
|
+
|
|
15
|
+
#### Security improvements
|
|
16
|
+
|
|
17
|
+
* **remote_method:** Redacted ingest key in trace level logs ([#1948](https://github.com/newrelic/node-newrelic/pull/1948)) ([04fee88](https://github.com/newrelic/node-newrelic/commit/04fee886bd2f479e568830ea03217d7c9aba87d9))
|
|
18
|
+
|
|
19
|
+
#### Code refactoring
|
|
20
|
+
|
|
21
|
+
* Updated `lib/shim/shim.js` to remove cognitive complexity violations ([#1950](https://github.com/newrelic/node-newrelic/pull/1950)) ([60e57a1](https://github.com/newrelic/node-newrelic/commit/60e57a10f038c1e70dfef2937592983b2bfd5613))
|
|
22
|
+
* Updated message-shim to remove cognitive complexity violations. ([#1958](https://github.com/newrelic/node-newrelic/pull/1958)) ([3d1caaf](https://github.com/newrelic/node-newrelic/commit/3d1caaf7d7f7de1c2e139eb7943f557b896fc1e2))
|
|
23
|
+
|
|
24
|
+
#### Miscellaneous chores
|
|
25
|
+
|
|
26
|
+
* **deps:** Updated @newrelic/aws-sdk to latest and removed aws_bedrock_instrumentation feature flag ([#1956](https://github.com/newrelic/node-newrelic/pull/1956)) ([9eae28c](https://github.com/newrelic/node-newrelic/commit/9eae28c7ca06f9287fe09a2d51ad61534d9e8b1d))
|
|
27
|
+
* **deps:** Updated @newrelic/security-agent to v0.7.0 ([#1955](https://github.com/newrelic/node-newrelic/pull/1955)) ([e156539](https://github.com/newrelic/node-newrelic/commit/e15653916f4614e17501202f6831459a8104e7a7))
|
|
28
|
+
* Migrated non-sensitive CI values to vars ([#1957](https://github.com/newrelic/node-newrelic/pull/1957)) ([1739378](https://github.com/newrelic/node-newrelic/commit/17393782a278fd3c3289332c78a88a5d6819be7c))
|
|
29
|
+
* updated contributors list to include james and svetlana 🎉 ([#1947](https://github.com/newrelic/node-newrelic/pull/1947)) ([33a59fd](https://github.com/newrelic/node-newrelic/commit/33a59fdcdeb3e4074b4611d88e2fe79a65168fe3))
|
|
30
|
+
|
|
1
31
|
### v11.9.0 (2024-01-10)
|
|
2
32
|
|
|
3
33
|
#### Features
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -509,7 +509,7 @@ This product includes source derived from [@grpc/proto-loader](https://github.co
|
|
|
509
509
|
|
|
510
510
|
### @newrelic/aws-sdk
|
|
511
511
|
|
|
512
|
-
This product includes source derived from [@newrelic/aws-sdk](https://github.com/newrelic/node-newrelic-aws-sdk) ([v7.0
|
|
512
|
+
This product includes source derived from [@newrelic/aws-sdk](https://github.com/newrelic/node-newrelic-aws-sdk) ([v7.1.0](https://github.com/newrelic/node-newrelic-aws-sdk/tree/v7.1.0)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-newrelic-aws-sdk/blob/v7.1.0/LICENSE):
|
|
513
513
|
|
|
514
514
|
```
|
|
515
515
|
Apache License
|
|
@@ -926,7 +926,7 @@ Apache License
|
|
|
926
926
|
|
|
927
927
|
### @newrelic/security-agent
|
|
928
928
|
|
|
929
|
-
This product includes source derived from [@newrelic/security-agent](https://github.com/newrelic/csec-node-agent) ([v0.
|
|
929
|
+
This product includes source derived from [@newrelic/security-agent](https://github.com/newrelic/csec-node-agent) ([v0.7.0](https://github.com/newrelic/csec-node-agent/tree/v0.7.0)), distributed under the [UNKNOWN License](https://github.com/newrelic/csec-node-agent/blob/v0.7.0/LICENSE):
|
|
930
930
|
|
|
931
931
|
```
|
|
932
932
|
## New Relic Pre-Release Software Notice
|
package/api.js
CHANGED
|
@@ -1312,7 +1312,7 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
|
|
|
1312
1312
|
*
|
|
1313
1313
|
* @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
|
|
1314
1314
|
* @param {string} moduleName.moduleName The module name given to require to load the module
|
|
1315
|
-
* @param {
|
|
1315
|
+
* @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
|
|
1316
1316
|
* @param {Function} moduleName.onRequire The function to call when the module has been loaded
|
|
1317
1317
|
* @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
|
|
1318
1318
|
* @param {Function} onRequire The function to call when the module has been loaded
|
|
@@ -1343,7 +1343,7 @@ API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
|
|
|
1343
1343
|
*
|
|
1344
1344
|
* @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
|
|
1345
1345
|
* @param {string} moduleName.moduleName The module name given to require to load the module
|
|
1346
|
-
* @param {
|
|
1346
|
+
* @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
|
|
1347
1347
|
* @param {Function} moduleName.onRequire The function to call when the module has been loaded
|
|
1348
1348
|
* @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
|
|
1349
1349
|
* @param {Function} onRequire The function to call when the module has been loaded
|
|
@@ -1375,7 +1375,7 @@ API.prototype.instrumentConglomerate = function instrumentConglomerate(
|
|
|
1375
1375
|
*
|
|
1376
1376
|
* @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
|
|
1377
1377
|
* @param {string} moduleName.moduleName The module name given to require to load the module
|
|
1378
|
-
* @param {
|
|
1378
|
+
* @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
|
|
1379
1379
|
* @param {Function} moduleName.onRequire The function to call when the module has been loaded
|
|
1380
1380
|
* @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
|
|
1381
1381
|
* @param {Function} onRequire The function to call when the module has been loaded
|
|
@@ -1408,7 +1408,7 @@ API.prototype.instrumentDatastore = function instrumentDatastore(moduleName, onR
|
|
|
1408
1408
|
*
|
|
1409
1409
|
* @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
|
|
1410
1410
|
* @param {string} moduleName.moduleName The module name given to require to load the module
|
|
1411
|
-
* @param {
|
|
1411
|
+
* @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
|
|
1412
1412
|
* @param {Function} moduleName.onRequire The function to call when the module has been loaded
|
|
1413
1413
|
* @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
|
|
1414
1414
|
* @param {Function} onRequire The function to call when the module has been loaded
|
|
@@ -1445,7 +1445,7 @@ API.prototype.instrumentWebframework = function instrumentWebframework(
|
|
|
1445
1445
|
*
|
|
1446
1446
|
* @param {string|object} moduleName The module name given to require to load the module, or the instrumentation specification
|
|
1447
1447
|
* @param {string} moduleName.moduleName The module name given to require to load the module
|
|
1448
|
-
* @param {
|
|
1448
|
+
* @param {string} [moduleName.absolutePath] Must provide absolute path to module if it does not exist within node_modules. This is used to instrument a file within the same application.
|
|
1449
1449
|
* @param {Function} moduleName.onRequire The function to call when the module has been loaded
|
|
1450
1450
|
* @param {Function} [moduleName.onError] If provided, should `onRequire` throw an error, the error will be passed to
|
|
1451
1451
|
* @param {Function} onRequire The function to call when the module has been loaded
|
|
@@ -259,15 +259,19 @@ RemoteMethod.prototype._safeRequest = function _safeRequest(options) {
|
|
|
259
259
|
level = 'info'
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
'
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
262
|
+
// check if trace is enabled or audit log(aka info in this case) before attemping
|
|
263
|
+
// to get the body length or parse the path with redacted key
|
|
264
|
+
if (logger.traceEnabled() || level === 'info') {
|
|
265
|
+
const logBody = Buffer.isBuffer(options.body) ? 'Buffer ' + options.body.length : options.body
|
|
266
|
+
logger[level](
|
|
267
|
+
{ body: logBody },
|
|
268
|
+
'Posting to %s://%s:%s%s',
|
|
269
|
+
protocol,
|
|
270
|
+
options.host,
|
|
271
|
+
options.port,
|
|
272
|
+
this._path({ redactLicenseKey: true })
|
|
273
|
+
)
|
|
274
|
+
}
|
|
271
275
|
|
|
272
276
|
this._request(options)
|
|
273
277
|
}
|
|
@@ -336,13 +340,14 @@ RemoteMethod.prototype._userAgent = function _userAgent() {
|
|
|
336
340
|
/**
|
|
337
341
|
* Generate a URL the collector understands.
|
|
338
342
|
*
|
|
343
|
+
* @param {boolean} redactLicenseKey flag to redact license key in path
|
|
339
344
|
* @returns {string} The URL path to be POSTed to.
|
|
340
345
|
*/
|
|
341
|
-
RemoteMethod.prototype._path = function _path() {
|
|
346
|
+
RemoteMethod.prototype._path = function _path({ redactLicenseKey } = {}) {
|
|
342
347
|
const query = {
|
|
343
348
|
marshal_format: 'json',
|
|
344
349
|
protocol_version: this._protocolVersion,
|
|
345
|
-
license_key: this._config.license_key,
|
|
350
|
+
license_key: redactLicenseKey ? 'REDACTED' : this._config.license_key,
|
|
346
351
|
method: this.name
|
|
347
352
|
}
|
|
348
353
|
|
package/lib/errors/index.js
CHANGED
|
@@ -67,7 +67,8 @@ class Exception {
|
|
|
67
67
|
* [1] -> name extracted from error info,
|
|
68
68
|
* [2] -> extracted error message,
|
|
69
69
|
* [3] -> extracted error type,
|
|
70
|
-
* [4] -> attributes
|
|
70
|
+
* [4] -> attributes,
|
|
71
|
+
* [5] -> transaction id
|
|
71
72
|
*/
|
|
72
73
|
function createError(transaction, exception, config) {
|
|
73
74
|
const error = exception.error
|
|
@@ -111,7 +112,7 @@ function createError(transaction, exception, config) {
|
|
|
111
112
|
|
|
112
113
|
maybeAddAgentAttributes(params, exception)
|
|
113
114
|
|
|
114
|
-
return [0, name, message, type, params]
|
|
115
|
+
return [0, name, message, type, params, transaction?.id]
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
function isValidErrorGroupOutput(output) {
|
package/lib/feature_flags.js
CHANGED
|
@@ -12,8 +12,7 @@ exports.prerelease = {
|
|
|
12
12
|
reverse_naming_rules: false,
|
|
13
13
|
undici_async_tracking: true,
|
|
14
14
|
unresolved_promise_cleanup: true,
|
|
15
|
-
legacy_context_manager: false
|
|
16
|
-
aws_bedrock_instrumentation: false
|
|
15
|
+
legacy_context_manager: false
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
// flags that are no longer used for released features
|
|
@@ -34,7 +33,8 @@ exports.released = [
|
|
|
34
33
|
'await_support',
|
|
35
34
|
'certificate_bundle',
|
|
36
35
|
'async_local_context',
|
|
37
|
-
'undici_instrumentation'
|
|
36
|
+
'undici_instrumentation',
|
|
37
|
+
'aws_bedrock_instrumentation'
|
|
38
38
|
]
|
|
39
39
|
|
|
40
40
|
// flags that are no longer used for unreleased features
|
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
AI: { OPENAI }
|
|
20
20
|
} = require('../../lib/metrics/names')
|
|
21
21
|
const semver = require('semver')
|
|
22
|
+
const { DESTINATIONS } = require('../config/attribute-filter')
|
|
22
23
|
|
|
23
24
|
let TRACKING_METRIC = OPENAI.TRACKING_PREFIX
|
|
24
25
|
|
|
@@ -282,6 +283,8 @@ module.exports = function initialize(agent, openai, moduleName, shim) {
|
|
|
282
283
|
err
|
|
283
284
|
})
|
|
284
285
|
}
|
|
286
|
+
|
|
287
|
+
segment.transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_EVENT, 'llm', true)
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
}
|
|
@@ -301,6 +304,8 @@ module.exports = function initialize(agent, openai, moduleName, shim) {
|
|
|
301
304
|
promise: true,
|
|
302
305
|
// eslint-disable-next-line max-params
|
|
303
306
|
after(_shim, _fn, _name, err, response, segment) {
|
|
307
|
+
segment.transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_EVENT, 'llm', true)
|
|
308
|
+
|
|
304
309
|
if (!response) {
|
|
305
310
|
// If we get an error, it is possible that `response = null`.
|
|
306
311
|
// In that case, we define it to be an empty object.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
const common = module.exports
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a message segment name from the given message descriptor.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
* @param {MessageShim} shim The shim the segment will be constructed by.
|
|
14
|
+
* @param {object} msgDesc The message descriptor.
|
|
15
|
+
* @param {string} action Produce or consume?
|
|
16
|
+
* @returns {string} The generated name of the message segment.
|
|
17
|
+
*/
|
|
18
|
+
common._nameMessageSegment = function _nameMessageSegment(shim, msgDesc, action) {
|
|
19
|
+
let name =
|
|
20
|
+
shim._metrics.PREFIX +
|
|
21
|
+
shim._metrics.LIBRARY +
|
|
22
|
+
'/' +
|
|
23
|
+
(msgDesc.destinationType || shim.EXCHANGE) +
|
|
24
|
+
'/' +
|
|
25
|
+
action
|
|
26
|
+
|
|
27
|
+
if (msgDesc.destinationName) {
|
|
28
|
+
name += shim._metrics.NAMED + msgDesc.destinationName
|
|
29
|
+
} else {
|
|
30
|
+
name += shim._metrics.TEMP
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return name
|
|
34
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
const TraceSegment = require('../../transaction/trace/segment')
|
|
8
|
+
const genericRecorder = require('../../metrics/recorders/generic')
|
|
9
|
+
const { _nameMessageSegment } = require('./common')
|
|
10
|
+
const specs = require('../specs')
|
|
11
|
+
module.exports = createRecorder
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generates the spec for the consumer
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
* @param {object} params to function
|
|
18
|
+
* @param {MessageShim} params.shim instance of shim
|
|
19
|
+
* @param {Function} params.fn consumer function
|
|
20
|
+
* @param {string} params.fnName name of function
|
|
21
|
+
* @param {Array} params.args arguments passed to original consume function
|
|
22
|
+
* @param {specs.MessageSpec} params.spec spec for the wrapped consume function
|
|
23
|
+
* @returns {specs.MessageSpec} new spec
|
|
24
|
+
*/
|
|
25
|
+
function updateSpecFromArgs({ shim, fn, fnName, args, spec }) {
|
|
26
|
+
let msgDesc = null
|
|
27
|
+
if (shim.isFunction(spec)) {
|
|
28
|
+
msgDesc = spec.call(this, shim, fn, fnName, args)
|
|
29
|
+
msgDesc = new specs.MessageSpec(msgDesc)
|
|
30
|
+
} else {
|
|
31
|
+
msgDesc = new specs.MessageSpec(spec)
|
|
32
|
+
const destIdx = shim.normalizeIndex(args.length, spec.destinationName)
|
|
33
|
+
if (destIdx !== null) {
|
|
34
|
+
msgDesc.destinationName = args[destIdx]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return msgDesc
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Binds the consumer callback to the active segment.
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
* @param {object} params to function
|
|
46
|
+
* @param {MessageShim} params.shim instance of shim
|
|
47
|
+
* @param {Array} params.args arguments passed to original consume function
|
|
48
|
+
* @param {specs.MessageSpec} params.msgDesc spec for the wrapped consume function
|
|
49
|
+
* @param {TraceSegment} params.segment active segment to bind callback
|
|
50
|
+
* @param {boolean} params.getParams flag to copy message parameters to segment
|
|
51
|
+
* @param {Function} params.resHandler function to handle response from callback to obtain the message parameters
|
|
52
|
+
*/
|
|
53
|
+
function bindCallback({ shim, args, msgDesc, segment, getParams, resHandler }) {
|
|
54
|
+
const cbIdx = shim.normalizeIndex(args.length, msgDesc.callback)
|
|
55
|
+
if (cbIdx !== null) {
|
|
56
|
+
shim.bindCallbackSegment(args, cbIdx, segment)
|
|
57
|
+
|
|
58
|
+
// If we have a callback and a results handler, then wrap the callback so
|
|
59
|
+
// we can call the results handler and get the message properties.
|
|
60
|
+
if (resHandler) {
|
|
61
|
+
shim.wrap(args, cbIdx, function wrapCb(shim, cb, cbName) {
|
|
62
|
+
if (shim.isFunction(cb)) {
|
|
63
|
+
return function cbWrapper() {
|
|
64
|
+
const cbArgs = shim.argsToArray.apply(shim, arguments)
|
|
65
|
+
const msgProps = resHandler.call(this, shim, cb, cbName, cbArgs)
|
|
66
|
+
if (getParams && msgProps && msgProps.parameters) {
|
|
67
|
+
shim.copySegmentParameters(segment, msgProps.parameters)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return cb.apply(this, arguments)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Binds the consumer function to the async context and checks return to possibly
|
|
80
|
+
* bind the promise
|
|
81
|
+
*
|
|
82
|
+
* @private
|
|
83
|
+
* @param {object} params to function
|
|
84
|
+
* @param {MessageShim} params.shim instance of shim
|
|
85
|
+
* @param {Function} params.fn consumer function
|
|
86
|
+
* @param {string} params.fnName name of function
|
|
87
|
+
* @param {Array} params.args arguments passed to original consume function
|
|
88
|
+
* @param {specs.MessageSpec} params.msgDesc spec for the wrapped consume function
|
|
89
|
+
* @param {TraceSegment} params.segment active segment to bind callback
|
|
90
|
+
* @param {boolean} params.getParams flag to copy message parameters to segment
|
|
91
|
+
* @param {Function} params.resHandler function to handle response from callback to obtain the message parameters
|
|
92
|
+
* @returns {Promise|*} response from consume function
|
|
93
|
+
*/
|
|
94
|
+
function bindConsumer({ shim, fn, fnName, args, msgDesc, segment, getParams, resHandler }) {
|
|
95
|
+
// Call the method in the context of our segment.
|
|
96
|
+
let ret = shim.applySegment(fn, segment, true, this, args)
|
|
97
|
+
|
|
98
|
+
if (ret && msgDesc.promise && shim.isPromise(ret)) {
|
|
99
|
+
ret = shim.bindPromise(ret, segment)
|
|
100
|
+
|
|
101
|
+
// Intercept the promise to handle the result.
|
|
102
|
+
if (resHandler) {
|
|
103
|
+
ret = ret.then(function interceptValue(res) {
|
|
104
|
+
const msgProps = resHandler.call(this, shim, fn, fnName, res)
|
|
105
|
+
if (getParams && msgProps && msgProps.parameters) {
|
|
106
|
+
shim.copySegmentParameters(segment, msgProps.parameters)
|
|
107
|
+
}
|
|
108
|
+
return res
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return ret
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @private
|
|
119
|
+
* @param {object} params to function
|
|
120
|
+
* @param {MessageShim} params.shim instance of shim
|
|
121
|
+
* @param {Function} params.fn function that is being wrapped
|
|
122
|
+
* @param {string} params.fnName name of function
|
|
123
|
+
* @param {specs.MessageSpec} params.spec spec for the wrapped consume function
|
|
124
|
+
* @returns {Function} recorder for consume function
|
|
125
|
+
*/
|
|
126
|
+
function createRecorder({ shim, fn, fnName, spec }) {
|
|
127
|
+
return function consumeRecorder() {
|
|
128
|
+
const parent = shim.getSegment()
|
|
129
|
+
if (!parent || !parent.transaction.isActive()) {
|
|
130
|
+
shim.logger.trace('Not recording consume, no active transaction.')
|
|
131
|
+
return fn.apply(this, arguments)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Process the message args.
|
|
135
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
136
|
+
const msgDesc = updateSpecFromArgs.call(this, { shim, fn, fnName, args, spec })
|
|
137
|
+
|
|
138
|
+
// Make the segment if we can.
|
|
139
|
+
if (!msgDesc) {
|
|
140
|
+
shim.logger.trace('Not recording consume, no message descriptor.')
|
|
141
|
+
return fn.apply(this, args)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const name = _nameMessageSegment(shim, msgDesc, shim._metrics.CONSUME)
|
|
145
|
+
|
|
146
|
+
// Adds details needed by createSegment when used with a spec
|
|
147
|
+
msgDesc.name = name
|
|
148
|
+
msgDesc.recorder = genericRecorder
|
|
149
|
+
msgDesc.parent = parent
|
|
150
|
+
|
|
151
|
+
const segment = shim.createSegment(msgDesc)
|
|
152
|
+
const getParams = shim.agent.config.message_tracer.segment_parameters.enabled
|
|
153
|
+
const resHandler = shim.isFunction(msgDesc.messageHandler) ? msgDesc.messageHandler : null
|
|
154
|
+
|
|
155
|
+
bindCallback({ shim, args, msgDesc, segment, getParams, resHandler })
|
|
156
|
+
return bindConsumer.call(this, {
|
|
157
|
+
shim,
|
|
158
|
+
fn,
|
|
159
|
+
fnName,
|
|
160
|
+
args,
|
|
161
|
+
msgDesc,
|
|
162
|
+
segment,
|
|
163
|
+
getParams,
|
|
164
|
+
resHandler
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|