newrelic 7.5.2 → 8.3.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 +4989 -4886
- package/THIRD_PARTY_NOTICES.md +625 -216
- package/api.js +105 -174
- package/bin/test-naming-rules.js +38 -32
- package/bin/tracetractor +0 -1
- package/index.js +12 -18
- package/lib/agent.js +108 -111
- package/lib/aggregators/base-aggregator.js +1 -1
- package/lib/aggregators/event-aggregator.js +6 -6
- package/lib/attributes.js +12 -13
- package/lib/collector/api.js +32 -42
- package/lib/collector/facts.js +67 -65
- package/lib/collector/http-agents.js +30 -27
- package/lib/collector/parse-response.js +1 -2
- package/lib/collector/remote-method.js +43 -36
- package/lib/collector/serverless.js +13 -18
- package/lib/collector/ssl/certificates.js +1056 -1056
- package/lib/config/attribute-filter.js +90 -82
- package/lib/config/default.js +30 -18
- package/lib/config/env.js +17 -12
- package/lib/config/harvest-config-validator.js +1 -1
- package/lib/config/index.js +160 -177
- package/lib/config/merge-server-config.js +7 -5
- package/lib/custom-events/custom-event-aggregator.js +1 -1
- package/lib/db/parse-sql.js +6 -9
- package/lib/db/parsed-statement.js +6 -13
- package/lib/db/query-parsers/sql.js +6 -9
- package/lib/db/query-sample.js +7 -3
- package/lib/db/query-trace-aggregator.js +12 -12
- package/lib/db/utils.js +1 -1
- package/lib/environment.js +173 -138
- package/lib/errors/error-collector.js +18 -31
- package/lib/errors/error-event-aggregator.js +1 -1
- package/lib/errors/error-trace-aggregator.js +2 -3
- package/lib/errors/helper.js +21 -30
- package/lib/errors/index.js +16 -28
- package/lib/feature_flags.js +5 -8
- package/lib/grpc/connection/states.js +6 -6
- package/lib/grpc/connection.js +35 -46
- package/lib/header-attributes.js +49 -53
- package/lib/instrumentation/amqplib.js +8 -17
- package/lib/instrumentation/bluebird.js +61 -20
- package/lib/instrumentation/cassandra-driver.js +2 -2
- package/lib/instrumentation/connect.js +4 -3
- package/lib/instrumentation/core/async_hooks.js +11 -4
- package/lib/instrumentation/core/child_process.js +20 -28
- package/lib/instrumentation/core/crypto.js +1 -7
- package/lib/instrumentation/core/dns.js +3 -7
- package/lib/instrumentation/core/domain.js +2 -8
- package/lib/instrumentation/core/fs.js +22 -37
- package/lib/instrumentation/core/globals.js +3 -7
- package/lib/instrumentation/core/http-outbound.js +15 -40
- package/lib/instrumentation/core/http.js +29 -63
- package/lib/instrumentation/core/inspector.js +6 -10
- package/lib/instrumentation/core/net.js +3 -1
- package/lib/instrumentation/core/timers.js +17 -24
- package/lib/instrumentation/core/zlib.js +2 -10
- package/lib/instrumentation/express.js +4 -2
- package/lib/instrumentation/fastify/spec-builders.js +5 -0
- package/lib/instrumentation/fastify.js +37 -10
- package/lib/instrumentation/hapi/hapi-17.js +9 -10
- package/lib/instrumentation/hapi.js +15 -15
- package/lib/instrumentation/ioredis.js +1 -2
- package/lib/instrumentation/memcached.js +39 -43
- package/lib/instrumentation/mongodb/common.js +218 -0
- package/lib/instrumentation/mongodb/constants.js +87 -0
- package/lib/instrumentation/mongodb/v2-mongo.js +110 -0
- package/lib/instrumentation/mongodb/v3-mongo.js +80 -0
- package/lib/instrumentation/mongodb/v4-mongo.js +90 -0
- package/lib/instrumentation/mongodb.js +20 -312
- package/lib/instrumentation/mysql.js +33 -26
- package/lib/instrumentation/oracle.js +10 -14
- package/lib/instrumentation/pg.js +30 -21
- package/lib/instrumentation/promise.js +20 -17
- package/lib/instrumentation/redis.js +30 -30
- package/lib/instrumentation/when.js +9 -1
- package/lib/instrumentations.js +24 -24
- package/lib/logger.js +1 -1
- package/lib/metrics/index.js +37 -17
- package/lib/metrics/mapper.js +9 -9
- package/lib/metrics/metric-aggregator.js +5 -10
- package/lib/metrics/names.js +8 -7
- package/lib/metrics/normalizer/rule.js +6 -7
- package/lib/metrics/normalizer/tx_segment.js +17 -13
- package/lib/metrics/normalizer.js +30 -33
- package/lib/metrics/recorders/custom.js +3 -1
- package/lib/metrics/recorders/distributed-trace.js +3 -18
- package/lib/metrics/recorders/generic.js +3 -2
- package/lib/metrics/recorders/http.js +4 -6
- package/lib/metrics/recorders/http_external.js +1 -3
- package/lib/metrics/recorders/message-transaction.js +2 -12
- package/lib/metrics/recorders/other.js +2 -12
- package/lib/parse-proc-cpuinfo.js +11 -16
- package/lib/parse-proc-meminfo.js +5 -3
- package/lib/prioritized-attributes.js +12 -17
- package/lib/priority-queue.js +1 -1
- package/lib/proxy/grpc.js +1 -1
- package/lib/reservoir.js +9 -3
- package/lib/sampler.js +12 -13
- package/lib/serverless/api-gateway.js +3 -3
- package/lib/serverless/aws-lambda.js +28 -37
- package/lib/shim/conglomerate-shim.js +4 -4
- package/lib/shim/datastore-shim.js +29 -38
- package/lib/shim/index.js +8 -9
- package/lib/shim/message-shim.js +111 -113
- package/lib/shim/promise-shim.js +18 -13
- package/lib/shim/shim.js +72 -66
- package/lib/shim/specs/index.js +18 -19
- package/lib/shim/transaction-shim.js +26 -36
- package/lib/shim/webframework-shim.js +25 -35
- package/lib/shimmer.js +184 -166
- package/lib/spans/create-span-event-aggregator.js +24 -44
- package/lib/spans/span-context.js +4 -10
- package/lib/spans/span-event-aggregator.js +68 -13
- package/lib/spans/span-event.js +5 -7
- package/lib/spans/span-streamer.js +10 -18
- package/lib/spans/streaming-span-event-aggregator.js +1 -1
- package/lib/spans/streaming-span-event.js +4 -4
- package/lib/stats/apdex.js +5 -11
- package/lib/stats/index.js +12 -17
- package/lib/system-info.js +7 -3
- package/lib/timer.js +30 -16
- package/lib/transaction/dt-payload.js +1 -1
- package/lib/transaction/handle.js +19 -19
- package/lib/transaction/index.js +94 -112
- package/lib/transaction/name-state.js +5 -6
- package/lib/transaction/trace/aggregator.js +78 -73
- package/lib/transaction/trace/exclusive-time-calculator.js +5 -9
- package/lib/transaction/trace/index.js +26 -24
- package/lib/transaction/trace/segment.js +39 -56
- package/lib/transaction/tracecontext.js +37 -45
- package/lib/transaction/tracer/index.js +79 -44
- package/lib/transaction/transaction-event-aggregator.js +29 -31
- package/lib/uninstrumented.js +4 -5
- package/lib/util/attribute-types.js +1 -5
- package/lib/util/byte-limit.js +0 -1
- package/lib/util/cat.js +5 -13
- package/lib/util/codec.js +8 -4
- package/lib/util/deep-equal.js +48 -18
- package/lib/util/flatten.js +5 -2
- package/lib/util/hashes.js +2 -2
- package/lib/util/label-parser.js +7 -13
- package/lib/util/logger.js +31 -13
- package/lib/util/process-version.js +1 -1
- package/lib/util/properties.js +1 -1
- package/lib/util/sql/obfuscate.js +7 -17
- package/lib/util/stream-sink.js +2 -3
- package/lib/util/urltils.js +9 -13
- package/lib/utilization/aws-info.js +2 -3
- package/lib/utilization/azure-info.js +32 -30
- package/lib/utilization/common.js +5 -4
- package/lib/utilization/docker-info.js +4 -6
- package/lib/utilization/gcp-info.js +36 -35
- package/lib/utilization/index.js +1 -1
- package/lib/utilization/kubernetes-info.js +2 -2
- package/lib/utilization/pcf-info.js +4 -4
- package/package.json +32 -18
- package/stub_api.js +8 -6
package/lib/shim/promise-shim.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
const logger = require('../logger').child({component: 'PromiseShim'})
|
|
8
|
+
const logger = require('../logger').child({ component: 'PromiseShim' })
|
|
9
9
|
const Shim = require('./shim')
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -13,6 +13,7 @@ const Shim = require('./shim')
|
|
|
13
13
|
*
|
|
14
14
|
* @extends Shim
|
|
15
15
|
*/
|
|
16
|
+
/* eslint-disable camelcase */
|
|
16
17
|
class PromiseShim extends Shim {
|
|
17
18
|
/**
|
|
18
19
|
* Constructs a shim associated with the given agent instance, specialized for
|
|
@@ -31,7 +32,7 @@ class PromiseShim extends Shim {
|
|
|
31
32
|
*/
|
|
32
33
|
constructor(agent, moduleName, resolvedName) {
|
|
33
34
|
super(agent, moduleName, resolvedName)
|
|
34
|
-
this._logger = logger.child({module: moduleName})
|
|
35
|
+
this._logger = logger.child({ module: moduleName })
|
|
35
36
|
this._class = null
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -399,9 +400,9 @@ function _wrapThen(shim, fn, name, useAllParams) {
|
|
|
399
400
|
|
|
400
401
|
function wrapHandler(handler, i, length) {
|
|
401
402
|
if (
|
|
402
|
-
!shim.isFunction(handler) ||
|
|
403
|
-
shim.isWrapped(handler)
|
|
404
|
-
(!useAllParams && i !==
|
|
403
|
+
!shim.isFunction(handler) || // Not a function
|
|
404
|
+
shim.isWrapped(handler) || // Already wrapped
|
|
405
|
+
(!useAllParams && i !== length - 1) // Don't want all and not last
|
|
405
406
|
) {
|
|
406
407
|
isWrapped = shim.isWrapped(handler)
|
|
407
408
|
return handler
|
|
@@ -532,7 +533,7 @@ class Contextualizer {
|
|
|
532
533
|
}
|
|
533
534
|
|
|
534
535
|
setSegment(segment) {
|
|
535
|
-
return this.context.segments[this.idx] = segment
|
|
536
|
+
return (this.context.segments[this.idx] = segment)
|
|
536
537
|
}
|
|
537
538
|
|
|
538
539
|
toJSON() {
|
|
@@ -553,16 +554,20 @@ class Contextualizer {
|
|
|
553
554
|
|
|
554
555
|
// No `finally` means we need to hook into resolve and reject individually and
|
|
555
556
|
// pass through whatever happened.
|
|
556
|
-
return prom.then(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
557
|
+
return prom.then(
|
|
558
|
+
function __NR_thenContext(val) {
|
|
559
|
+
__NR_continueContext()
|
|
560
|
+
return val
|
|
561
|
+
},
|
|
562
|
+
function __NR_catchContext(err) {
|
|
563
|
+
__NR_continueContext()
|
|
564
|
+
throw err // Re-throwing promise rejection, this is not New Relic's error.
|
|
565
|
+
}
|
|
566
|
+
)
|
|
563
567
|
|
|
564
568
|
function __NR_continueContext() {
|
|
565
569
|
self.setSegment(nextContext.getSegment())
|
|
566
570
|
}
|
|
567
571
|
}
|
|
568
572
|
}
|
|
573
|
+
/* eslint-enable camelcase */
|
package/lib/shim/shim.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const arity = require('../util/arity')
|
|
9
9
|
const constants = require('./constants')
|
|
10
10
|
const hasOwnProperty = require('../util/properties').hasOwn
|
|
11
|
-
const logger = require('../logger').child({component: 'Shim'})
|
|
11
|
+
const logger = require('../logger').child({ component: 'Shim' })
|
|
12
12
|
const path = require('path')
|
|
13
13
|
const specs = require('./specs')
|
|
14
14
|
const util = require('util')
|
|
@@ -33,7 +33,7 @@ function Shim(agent, moduleName, resolvedName) {
|
|
|
33
33
|
throw new Error('Shim must be initialized with an agent and module name.')
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
this._logger = logger.child({module: moduleName})
|
|
36
|
+
this._logger = logger.child({ module: moduleName })
|
|
37
37
|
this._agent = agent
|
|
38
38
|
this._toExport = null
|
|
39
39
|
this._debug = false
|
|
@@ -593,7 +593,7 @@ function wrap(nodule, properties, spec, args) {
|
|
|
593
593
|
}
|
|
594
594
|
|
|
595
595
|
// TODO: Add option for omitting __NR_original; unwrappable: false
|
|
596
|
-
spec = this.setDefaults(spec, {matchArity: false})
|
|
596
|
+
spec = this.setDefaults(spec, { matchArity: false })
|
|
597
597
|
|
|
598
598
|
// If we're just wrapping one thing, just wrap it and return.
|
|
599
599
|
if (properties == null) {
|
|
@@ -794,7 +794,7 @@ function wrapClass(nodule, properties, spec, args) {
|
|
|
794
794
|
properties = null
|
|
795
795
|
}
|
|
796
796
|
if (this.isFunction(spec)) {
|
|
797
|
-
spec = {pre: null, post: spec}
|
|
797
|
+
spec = { pre: null, post: spec }
|
|
798
798
|
} else {
|
|
799
799
|
spec.pre = spec.pre || null
|
|
800
800
|
spec.post = spec.post || null
|
|
@@ -812,9 +812,7 @@ function wrapClass(nodule, properties, spec, args) {
|
|
|
812
812
|
|
|
813
813
|
// When es6 classes are being wrapped, we need to use an es6 class due to
|
|
814
814
|
// the fact our es5 wrapper depends on calling the constructor without `new`.
|
|
815
|
-
var wrapper = spec.es6 || /^class /.test(Base.toString())
|
|
816
|
-
? _es6WrapClass
|
|
817
|
-
: _es5WrapClass
|
|
815
|
+
var wrapper = spec.es6 || /^class /.test(Base.toString()) ? _es6WrapClass : _es5WrapClass
|
|
818
816
|
|
|
819
817
|
return wrapper(shim, Base, fnName, spec, args)
|
|
820
818
|
})
|
|
@@ -837,7 +835,7 @@ function wrapClass(nodule, properties, spec, args) {
|
|
|
837
835
|
* @return {*} The return value from `spec`.
|
|
838
836
|
*/
|
|
839
837
|
function wrapExport(nodule, spec) {
|
|
840
|
-
return this._toExport = this.wrap(nodule, null, spec)
|
|
838
|
+
return (this._toExport = this.wrap(nodule, null, spec))
|
|
841
839
|
}
|
|
842
840
|
|
|
843
841
|
/**
|
|
@@ -950,10 +948,7 @@ function record(nodule, properties, recordNamer) {
|
|
|
950
948
|
return fnApply.call(fn, this, arguments)
|
|
951
949
|
}
|
|
952
950
|
|
|
953
|
-
if (
|
|
954
|
-
segDesc.callbackRequired &&
|
|
955
|
-
!_hasValidCallbackArg(shim, args, segDesc.callback)
|
|
956
|
-
) {
|
|
951
|
+
if (segDesc.callbackRequired && !_hasValidCallbackArg(shim, args, segDesc.callback)) {
|
|
957
952
|
return fnApply.call(fn, this, arguments)
|
|
958
953
|
}
|
|
959
954
|
|
|
@@ -961,7 +956,8 @@ function record(nodule, properties, recordNamer) {
|
|
|
961
956
|
// - We are _not_ making an internal segment.
|
|
962
957
|
// - OR the parent segment is either not internal or not from this shim.
|
|
963
958
|
var shouldCreateSegment = !(
|
|
964
|
-
parent.opaque ||
|
|
959
|
+
parent.opaque ||
|
|
960
|
+
(segDesc.internal && parent.internal && shim === parent.shim)
|
|
965
961
|
)
|
|
966
962
|
|
|
967
963
|
var segment = shouldCreateSegment ? _rawCreateSegment(shim, segDesc) : parent
|
|
@@ -1019,15 +1015,18 @@ function record(nodule, properties, recordNamer) {
|
|
|
1019
1015
|
ret = shim.applySegment(fn, segment, true, ctx, args, segDesc.inContext)
|
|
1020
1016
|
if (segDesc.after && segDesc.promise && shim.isPromise(ret)) {
|
|
1021
1017
|
promised = true
|
|
1022
|
-
return ret.then(
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1018
|
+
return ret.then(
|
|
1019
|
+
function onThen(val) {
|
|
1020
|
+
segment.touch()
|
|
1021
|
+
segDesc.after(shim, fn, name, null, val)
|
|
1022
|
+
return val
|
|
1023
|
+
},
|
|
1024
|
+
function onCatch(err) {
|
|
1025
|
+
segment.touch()
|
|
1026
|
+
segDesc.after(shim, fn, name, err, null)
|
|
1027
|
+
throw err // NOTE: This is not an error from our instrumentation.
|
|
1028
|
+
}
|
|
1029
|
+
)
|
|
1031
1030
|
}
|
|
1032
1031
|
return ret
|
|
1033
1032
|
} catch (err) {
|
|
@@ -1199,7 +1198,7 @@ function bindSegment(nodule, property, segment, full) {
|
|
|
1199
1198
|
// segment is `null`, and thus `true` (the full param) is detected as the
|
|
1200
1199
|
// segment.
|
|
1201
1200
|
if (segment != null && !this.isObject(segment)) {
|
|
1202
|
-
this.logger.debug({segment: segment}, 'Segment is not a segment, not binding.')
|
|
1201
|
+
this.logger.debug({ segment: segment }, 'Segment is not a segment, not binding.')
|
|
1203
1202
|
return nodule
|
|
1204
1203
|
}
|
|
1205
1204
|
|
|
@@ -1254,7 +1253,8 @@ function bindCallbackSegment(args, cbIdx, parentSegment) {
|
|
|
1254
1253
|
// Bad index.
|
|
1255
1254
|
this.logger.debug(
|
|
1256
1255
|
'Invalid index %d for args of length %d, not binding callback segment',
|
|
1257
|
-
cbIdx,
|
|
1256
|
+
cbIdx,
|
|
1257
|
+
args.length
|
|
1258
1258
|
)
|
|
1259
1259
|
return
|
|
1260
1260
|
}
|
|
@@ -1271,10 +1271,13 @@ function bindCallbackSegment(args, cbIdx, parentSegment) {
|
|
|
1271
1271
|
if (realParent) {
|
|
1272
1272
|
realParent.opaque = false
|
|
1273
1273
|
}
|
|
1274
|
-
var segment = _rawCreateSegment(
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1274
|
+
var segment = _rawCreateSegment(
|
|
1275
|
+
shim,
|
|
1276
|
+
new specs.SegmentSpec({
|
|
1277
|
+
name: 'Callback: ' + name,
|
|
1278
|
+
parent: realParent
|
|
1279
|
+
})
|
|
1280
|
+
)
|
|
1278
1281
|
|
|
1279
1282
|
if (segment) {
|
|
1280
1283
|
segment.async = false
|
|
@@ -1310,7 +1313,6 @@ function getSegment(obj) {
|
|
|
1310
1313
|
return this.tracer.getSegment()
|
|
1311
1314
|
}
|
|
1312
1315
|
|
|
1313
|
-
|
|
1314
1316
|
/**
|
|
1315
1317
|
* Retrieves the segment associated with the given object, or the currently
|
|
1316
1318
|
* active segment if no object is given.
|
|
@@ -1349,7 +1351,7 @@ function getActiveSegment(obj) {
|
|
|
1349
1351
|
*
|
|
1350
1352
|
*/
|
|
1351
1353
|
function setActiveSegment(segment) {
|
|
1352
|
-
return this.tracer.segment = segment
|
|
1354
|
+
return (this.tracer.segment = segment)
|
|
1353
1355
|
}
|
|
1354
1356
|
|
|
1355
1357
|
/**
|
|
@@ -1467,7 +1469,7 @@ function createSegment(name, recorder, parent) {
|
|
|
1467
1469
|
var opts = null
|
|
1468
1470
|
if (this.isString(name)) {
|
|
1469
1471
|
// createSegment(name [, recorder] [, parent])
|
|
1470
|
-
opts = new specs.SegmentSpec({name})
|
|
1472
|
+
opts = new specs.SegmentSpec({ name })
|
|
1471
1473
|
|
|
1472
1474
|
// if the recorder arg is not used, it can either be omitted or null
|
|
1473
1475
|
if (this.isFunction(recorder) || this.isNull(recorder)) {
|
|
@@ -1509,7 +1511,7 @@ function _rawCreateSegment(shim, opts) {
|
|
|
1509
1511
|
}
|
|
1510
1512
|
shim.logger.trace(opts, 'Created segment')
|
|
1511
1513
|
} else {
|
|
1512
|
-
shim.logger.debug(opts,'Failed to create segment')
|
|
1514
|
+
shim.logger.debug(opts, 'Failed to create segment')
|
|
1513
1515
|
}
|
|
1514
1516
|
|
|
1515
1517
|
return segment
|
|
@@ -1525,7 +1527,7 @@ function _rawCreateSegment(shim, opts) {
|
|
|
1525
1527
|
* @return {string} The name of the object if it has one, else `<anonymous>`.
|
|
1526
1528
|
*/
|
|
1527
1529
|
function getName(obj) {
|
|
1528
|
-
return String(
|
|
1530
|
+
return String(!obj || obj === true ? obj : obj.name || '<anonymous>')
|
|
1529
1531
|
}
|
|
1530
1532
|
|
|
1531
1533
|
/**
|
|
@@ -1690,7 +1692,7 @@ function normalizeIndex(arrayLength, idx) {
|
|
|
1690
1692
|
if (idx < 0) {
|
|
1691
1693
|
idx = arrayLength + idx
|
|
1692
1694
|
}
|
|
1693
|
-
return
|
|
1695
|
+
return idx < 0 || idx >= arrayLength ? null : idx
|
|
1694
1696
|
}
|
|
1695
1697
|
|
|
1696
1698
|
/**
|
|
@@ -1856,7 +1858,7 @@ function proxy(source, properties, dest) {
|
|
|
1856
1858
|
return source[prop]
|
|
1857
1859
|
},
|
|
1858
1860
|
set: function proxySet(val) {
|
|
1859
|
-
return source[prop] = val
|
|
1861
|
+
return (source[prop] = val)
|
|
1860
1862
|
}
|
|
1861
1863
|
})
|
|
1862
1864
|
})
|
|
@@ -1877,7 +1879,7 @@ function shimRequire(filePath) {
|
|
|
1877
1879
|
return require(path.resolve(this._moduleRoot, filePath))
|
|
1878
1880
|
} catch (e) {
|
|
1879
1881
|
this.logger.debug(
|
|
1880
|
-
|
|
1882
|
+
"Failed to load '%s' from module root: '%s'. Stack: %s",
|
|
1881
1883
|
filePath,
|
|
1882
1884
|
this._moduleRoot,
|
|
1883
1885
|
e.stack
|
|
@@ -1901,13 +1903,16 @@ function interceptPromise(prom, cb) {
|
|
|
1901
1903
|
if (this.isFunction(prom.finally)) {
|
|
1902
1904
|
return prom.finally(cb)
|
|
1903
1905
|
}
|
|
1904
|
-
return prom.then(
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1906
|
+
return prom.then(
|
|
1907
|
+
function onThen(arg) {
|
|
1908
|
+
cb()
|
|
1909
|
+
return arg
|
|
1910
|
+
},
|
|
1911
|
+
function onCatch(err) {
|
|
1912
|
+
cb()
|
|
1913
|
+
throw err // This is not our error, just rethrowing the promise rejection.
|
|
1914
|
+
}
|
|
1915
|
+
)
|
|
1911
1916
|
}
|
|
1912
1917
|
|
|
1913
1918
|
/**
|
|
@@ -2178,7 +2183,8 @@ function _bindStream(shim, stream, segment, spec) {
|
|
|
2178
2183
|
if (!segment || !shim.isFunction(stream.emit)) {
|
|
2179
2184
|
shim.logger.trace(
|
|
2180
2185
|
'Not binding stream; have segment=%j; typeof emit=%s',
|
|
2181
|
-
!!segment,
|
|
2186
|
+
!!segment,
|
|
2187
|
+
typeof stream.emit
|
|
2182
2188
|
)
|
|
2183
2189
|
return
|
|
2184
2190
|
}
|
|
@@ -2239,28 +2245,28 @@ function _bindStream(shim, stream, segment, spec) {
|
|
|
2239
2245
|
}
|
|
2240
2246
|
|
|
2241
2247
|
/**
|
|
2242
|
-
* Wraps an es6-style class using a subclass.
|
|
2243
|
-
*
|
|
2244
|
-
* - `_es6WrapClass(shim, Base, fnName, spec, args)`
|
|
2245
|
-
*
|
|
2246
|
-
* @private
|
|
2247
|
-
*
|
|
2248
|
-
* @param {Shim} shim
|
|
2249
|
-
* The shim performing the wrapping/binding.
|
|
2250
|
-
*
|
|
2251
|
-
* @param {class} Base
|
|
2252
|
-
* The es6 class to be wrapped.
|
|
2253
|
-
*
|
|
2254
|
-
* @param {string} fnName
|
|
2255
|
-
* The name of the base class.
|
|
2256
|
-
*
|
|
2257
|
-
* @param {ClassWrapSpec} spec
|
|
2258
|
-
* The spec with pre- and post-execution hooks to call.
|
|
2259
|
-
*
|
|
2260
|
-
* @param {Array.<*>} args
|
|
2261
|
-
* Extra arguments to pass through to the pre- and post-execution hooks.
|
|
2262
|
-
*
|
|
2263
|
-
* @return {class} A class that extends Base with execution hooks.
|
|
2248
|
+
* Wraps an es6-style class using a subclass.
|
|
2249
|
+
*
|
|
2250
|
+
* - `_es6WrapClass(shim, Base, fnName, spec, args)`
|
|
2251
|
+
*
|
|
2252
|
+
* @private
|
|
2253
|
+
*
|
|
2254
|
+
* @param {Shim} shim
|
|
2255
|
+
* The shim performing the wrapping/binding.
|
|
2256
|
+
*
|
|
2257
|
+
* @param {class} Base
|
|
2258
|
+
* The es6 class to be wrapped.
|
|
2259
|
+
*
|
|
2260
|
+
* @param {string} fnName
|
|
2261
|
+
* The name of the base class.
|
|
2262
|
+
*
|
|
2263
|
+
* @param {ClassWrapSpec} spec
|
|
2264
|
+
* The spec with pre- and post-execution hooks to call.
|
|
2265
|
+
*
|
|
2266
|
+
* @param {Array.<*>} args
|
|
2267
|
+
* Extra arguments to pass through to the pre- and post-execution hooks.
|
|
2268
|
+
*
|
|
2269
|
+
* @return {class} A class that extends Base with execution hooks.
|
|
2264
2270
|
*/
|
|
2265
2271
|
function _es6WrapClass(shim, Base, fnName, spec, args) {
|
|
2266
2272
|
return class WrappedClass extends Base {
|
package/lib/shim/specs/index.js
CHANGED
|
@@ -48,35 +48,34 @@ function WrapSpec(spec) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
function SegmentSpec(spec) {
|
|
51
|
-
this.name
|
|
52
|
-
this.recorder
|
|
53
|
-
this.inContext
|
|
54
|
-
this.parent
|
|
51
|
+
this.name = hasOwnProperty(spec, 'name') ? spec.name : null
|
|
52
|
+
this.recorder = hasOwnProperty(spec, 'recorder') ? spec.recorder : null
|
|
53
|
+
this.inContext = hasOwnProperty(spec, 'inContext') ? spec.inContext : null
|
|
54
|
+
this.parent = hasOwnProperty(spec, 'parent') ? spec.parent : null
|
|
55
55
|
this.parameters = hasOwnProperty(spec, 'parameters') ? spec.parameters : null
|
|
56
|
-
this.internal
|
|
57
|
-
this.opaque
|
|
56
|
+
this.internal = hasOwnProperty(spec, 'internal') ? spec.internal : false
|
|
57
|
+
this.opaque = hasOwnProperty(spec, 'opaque') ? spec.opaque : false
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function RecorderSpec(spec) {
|
|
61
61
|
SegmentSpec.call(this, spec)
|
|
62
|
-
this.stream
|
|
63
|
-
this.promise
|
|
64
|
-
this.callback
|
|
65
|
-
this.rowCallback
|
|
66
|
-
this.after
|
|
67
|
-
this.callbackRequired =
|
|
68
|
-
hasOwnProperty(spec, 'callbackRequired') ? spec.callbackRequired : null
|
|
62
|
+
this.stream = hasOwnProperty(spec, 'stream') ? spec.stream : null
|
|
63
|
+
this.promise = hasOwnProperty(spec, 'promise') ? spec.promise : null
|
|
64
|
+
this.callback = hasOwnProperty(spec, 'callback') ? spec.callback : null
|
|
65
|
+
this.rowCallback = hasOwnProperty(spec, 'rowCallback') ? spec.rowCallback : null
|
|
66
|
+
this.after = hasOwnProperty(spec, 'after') ? spec.after : null
|
|
67
|
+
this.callbackRequired = hasOwnProperty(spec, 'callbackRequired') ? spec.callbackRequired : null
|
|
69
68
|
}
|
|
70
69
|
util.inherits(RecorderSpec, SegmentSpec)
|
|
71
70
|
|
|
72
71
|
function MiddlewareSpec(spec) {
|
|
73
72
|
RecorderSpec.call(this, spec)
|
|
74
|
-
this.req
|
|
75
|
-
this.res
|
|
76
|
-
this.next
|
|
77
|
-
this.type
|
|
78
|
-
this.route
|
|
79
|
-
this.params
|
|
73
|
+
this.req = hasOwnProperty(spec, 'req') ? spec.req : ARG_INDEXES.FIRST
|
|
74
|
+
this.res = hasOwnProperty(spec, 'res') ? spec.res : ARG_INDEXES.SECOND
|
|
75
|
+
this.next = hasOwnProperty(spec, 'next') ? spec.next : ARG_INDEXES.THIRD
|
|
76
|
+
this.type = hasOwnProperty(spec, 'type') ? spec.type : 'MIDDLEWARE'
|
|
77
|
+
this.route = hasOwnProperty(spec, 'route') ? spec.route : null
|
|
78
|
+
this.params = hasOwnProperty(spec, 'params') ? spec.params : _defaultGetParams
|
|
80
79
|
this.appendPath = hasOwnProperty(spec, 'appendPath') ? spec.appendPath : true
|
|
81
80
|
}
|
|
82
81
|
util.inherits(MiddlewareSpec, RecorderSpec)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const cat = require('../util/cat')
|
|
9
9
|
const hashes = require('../util/hashes')
|
|
10
|
-
const logger = require('../logger').child({component: 'TransactionShim'})
|
|
10
|
+
const logger = require('../logger').child({ component: 'TransactionShim' })
|
|
11
11
|
const Shim = require('./shim')
|
|
12
12
|
const Transaction = require('../transaction')
|
|
13
13
|
const util = require('util')
|
|
@@ -50,7 +50,7 @@ const TRANSACTION_TYPES_SET = Transaction.TYPES_SET
|
|
|
50
50
|
*/
|
|
51
51
|
function TransactionShim(agent, moduleName, resolvedName) {
|
|
52
52
|
Shim.call(this, agent, moduleName, resolvedName)
|
|
53
|
-
this._logger = logger.child({module: moduleName})
|
|
53
|
+
this._logger = logger.child({ module: moduleName })
|
|
54
54
|
}
|
|
55
55
|
module.exports = TransactionShim
|
|
56
56
|
util.inherits(TransactionShim, Shim)
|
|
@@ -71,7 +71,6 @@ Object.keys(Transaction.TYPES).forEach(function defineTypeEnum(type) {
|
|
|
71
71
|
Shim.defineProperty(TransactionShim.prototype, type, Transaction.TYPES[type])
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
|
|
75
74
|
/**
|
|
76
75
|
* Enumeration of possible transaction transport types used for distributed tracing.
|
|
77
76
|
*
|
|
@@ -81,16 +80,8 @@ Object.keys(Transaction.TYPES).forEach(function defineTypeEnum(type) {
|
|
|
81
80
|
* @memberof TransactionShim.prototype
|
|
82
81
|
* @enum {string}
|
|
83
82
|
*/
|
|
84
|
-
Shim.defineProperty(
|
|
85
|
-
|
|
86
|
-
'TRANSPORT_TYPES',
|
|
87
|
-
Transaction.TRANSPORT_TYPES
|
|
88
|
-
)
|
|
89
|
-
Shim.defineProperty(
|
|
90
|
-
TransactionShim.prototype,
|
|
91
|
-
'TRANSPORT_TYPES',
|
|
92
|
-
Transaction.TRANSPORT_TYPES
|
|
93
|
-
)
|
|
83
|
+
Shim.defineProperty(TransactionShim, 'TRANSPORT_TYPES', Transaction.TRANSPORT_TYPES)
|
|
84
|
+
Shim.defineProperty(TransactionShim.prototype, 'TRANSPORT_TYPES', Transaction.TRANSPORT_TYPES)
|
|
94
85
|
|
|
95
86
|
TransactionShim.prototype.bindCreateTransaction = bindCreateTransaction
|
|
96
87
|
TransactionShim.prototype.pushTransactionName = pushTransactionName
|
|
@@ -158,9 +149,10 @@ function bindCreateTransaction(nodule, property, spec) {
|
|
|
158
149
|
// Refuse to perform the wrapping if `spec.type` is not valid.
|
|
159
150
|
if (!TRANSACTION_TYPES_SET[spec.type]) {
|
|
160
151
|
this.logger.error(
|
|
161
|
-
{stack:
|
|
152
|
+
{ stack: new Error().stack },
|
|
162
153
|
'Invalid spec type "%s", must be one of %j.',
|
|
163
|
-
spec.type,
|
|
154
|
+
spec.type,
|
|
155
|
+
Object.keys(TRANSACTION_TYPES_SET)
|
|
164
156
|
)
|
|
165
157
|
return nodule
|
|
166
158
|
}
|
|
@@ -293,7 +285,8 @@ function handleCATHeaders(headers, segment, transportType) {
|
|
|
293
285
|
var catId = null
|
|
294
286
|
var transactionData = null
|
|
295
287
|
var appData = null
|
|
296
|
-
|
|
288
|
+
// eslint-disable-next-line guard-for-in
|
|
289
|
+
for (var key in headers) {
|
|
297
290
|
if (MATCH_CAT_ID_HEADER.test(key)) {
|
|
298
291
|
catId = headers[key]
|
|
299
292
|
} else if (MATCH_CAT_TRANSACTION_HEADER.test(key)) {
|
|
@@ -344,9 +337,7 @@ function insertCATRequestHeaders(headers, useAlternateHeaderNames) {
|
|
|
344
337
|
const distributedTracingEnabled = this.agent.config.distributed_tracing.enabled
|
|
345
338
|
|
|
346
339
|
if (!distributedTracingEnabled && !crossAppTracingEnabled) {
|
|
347
|
-
this.logger.trace(
|
|
348
|
-
'Distributed Tracing and CAT are both disabled, not adding headers.'
|
|
349
|
-
)
|
|
340
|
+
this.logger.trace('Distributed Tracing and CAT are both disabled, not adding headers.')
|
|
350
341
|
return
|
|
351
342
|
}
|
|
352
343
|
|
|
@@ -404,7 +395,7 @@ function insertCATRequestHeaders(headers, useAlternateHeaderNames) {
|
|
|
404
395
|
this.logger.trace('Added CAT headers for transaction %s', tx.id)
|
|
405
396
|
}
|
|
406
397
|
} catch (e) {
|
|
407
|
-
this.logger.warn({error: e.stack}, 'Failed to serialize CAT header!')
|
|
398
|
+
this.logger.warn({ error: e.stack }, 'Failed to serialize CAT header!')
|
|
408
399
|
}
|
|
409
400
|
}
|
|
410
401
|
}
|
|
@@ -465,23 +456,24 @@ function insertCATReplyHeader(headers, useAlternateHeaderNames) {
|
|
|
465
456
|
var appData = null
|
|
466
457
|
var txName = tx.getFullName()
|
|
467
458
|
try {
|
|
468
|
-
appData = hashes.obfuscateNameUsingKey(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
459
|
+
appData = hashes.obfuscateNameUsingKey(
|
|
460
|
+
JSON.stringify([
|
|
461
|
+
config.cross_process_id,
|
|
462
|
+
txName,
|
|
463
|
+
tx.queueTime / 1000,
|
|
464
|
+
tx.catResponseTime / 1000,
|
|
465
|
+
contentLength,
|
|
466
|
+
tx.id,
|
|
467
|
+
false
|
|
468
|
+
]),
|
|
469
|
+
config.encoding_key
|
|
470
|
+
)
|
|
477
471
|
} catch (e) {
|
|
478
|
-
this.logger.warn({error: e.stack}, 'Failed to serialize CAT data for %s', txName)
|
|
472
|
+
this.logger.warn({ error: e.stack }, 'Failed to serialize CAT data for %s', txName)
|
|
479
473
|
}
|
|
480
474
|
|
|
481
475
|
// Add the header.
|
|
482
|
-
headers[
|
|
483
|
-
useAlternateHeaderNames ? MQ_CAT_APP_DATA_HEADER : HTTP_CAT_APP_DATA_HEADER
|
|
484
|
-
] = appData
|
|
476
|
+
headers[useAlternateHeaderNames ? MQ_CAT_APP_DATA_HEADER : HTTP_CAT_APP_DATA_HEADER] = appData
|
|
485
477
|
this.logger.trace('Added outbound response CAT headers for transaction %s', tx.id)
|
|
486
478
|
}
|
|
487
479
|
|
|
@@ -505,9 +497,7 @@ function _handleCATReplyHeader(shim, segment, appData) {
|
|
|
505
497
|
// Attempt to parse the app data header.
|
|
506
498
|
var config = shim.agent.config
|
|
507
499
|
try {
|
|
508
|
-
appData = JSON.parse(
|
|
509
|
-
hashes.deobfuscateNameUsingKey(appData, config.encoding_key)
|
|
510
|
-
)
|
|
500
|
+
appData = JSON.parse(hashes.deobfuscateNameUsingKey(appData, config.encoding_key))
|
|
511
501
|
} catch (e) {
|
|
512
502
|
shim.logger.warn('Unparsable CAT application data header: %s', appData)
|
|
513
503
|
return
|