newrelic 8.3.0 → 8.4.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 +34 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/api.js +74 -68
- package/bin/test-naming-rules.js +22 -22
- package/lib/agent.js +4 -4
- package/lib/attributes.js +2 -2
- package/lib/collector/api.js +12 -12
- package/lib/collector/facts.js +1 -1
- package/lib/collector/http-agents.js +12 -11
- package/lib/collector/key-parser.js +1 -1
- package/lib/collector/remote-method.js +27 -26
- package/lib/config/attribute-filter.js +23 -23
- package/lib/config/default.js +12 -10
- package/lib/config/hsm.js +1 -1
- package/lib/config/index.js +82 -66
- package/lib/config/lasp.js +3 -3
- package/lib/config/merge-server-config.js +1 -1
- package/lib/db/parse-sql.js +8 -8
- package/lib/db/parsed-statement.js +9 -8
- package/lib/db/query-parsers/sql.js +7 -7
- package/lib/db/query-sample.js +9 -9
- package/lib/db/query-trace-aggregator.js +4 -4
- package/lib/db/statement-matcher.js +5 -5
- package/lib/db/utils.js +1 -1
- package/lib/environment.js +43 -43
- package/lib/errors/error-collector.js +2 -2
- package/lib/errors/error-trace-aggregator.js +1 -1
- package/lib/errors/helper.js +3 -3
- package/lib/errors/index.js +17 -17
- package/lib/header-attributes.js +6 -6
- package/lib/header-processing.js +1 -1
- package/lib/instrumentation/amqplib.js +26 -26
- package/lib/instrumentation/bluebird.js +3 -3
- package/lib/instrumentation/cassandra-driver.js +7 -3
- package/lib/instrumentation/connect.js +4 -4
- package/lib/instrumentation/core/async_hooks.js +6 -6
- package/lib/instrumentation/core/domain.js +2 -2
- package/lib/instrumentation/core/globals.js +1 -1
- package/lib/instrumentation/core/http-outbound.js +14 -83
- package/lib/instrumentation/core/http.js +34 -67
- package/lib/instrumentation/core/inspector.js +2 -2
- package/lib/instrumentation/core/timers.js +7 -7
- package/lib/instrumentation/core/zlib.js +2 -2
- package/lib/instrumentation/director.js +4 -4
- package/lib/instrumentation/express.js +8 -8
- package/lib/instrumentation/generic-pool.js +1 -1
- package/lib/instrumentation/hapi/hapi-17.js +11 -11
- package/lib/instrumentation/hapi/shared.js +1 -1
- package/lib/instrumentation/hapi.js +22 -22
- package/lib/instrumentation/ioredis.js +7 -7
- package/lib/instrumentation/memcached.js +7 -7
- package/lib/instrumentation/mongodb/common.js +4 -1
- package/lib/instrumentation/mysql.js +19 -19
- package/lib/instrumentation/oracle.js +15 -15
- package/lib/instrumentation/pg.js +4 -4
- package/lib/instrumentation/promise.js +46 -46
- package/lib/instrumentation/q.js +2 -2
- package/lib/instrumentation/redis.js +11 -11
- package/lib/instrumentation/restify.js +1 -1
- package/lib/instrumentation/vision.js +4 -4
- package/lib/instrumentation/when.js +3 -3
- package/lib/instrumentations.js +1 -1
- package/lib/logger.js +5 -5
- package/lib/metrics/index.js +15 -15
- package/lib/metrics/mapper.js +7 -7
- package/lib/metrics/normalizer/rule.js +9 -9
- package/lib/metrics/normalizer/tx_segment.js +17 -17
- package/lib/metrics/normalizer.js +22 -22
- package/lib/metrics/recorders/custom.js +5 -5
- package/lib/metrics/recorders/generic.js +3 -3
- package/lib/metrics/recorders/http.js +7 -7
- package/lib/metrics/recorders/http_external.js +7 -7
- package/lib/metrics/recorders/message-transaction.js +5 -6
- package/lib/metrics/recorders/other.js +5 -5
- package/lib/parse-proc-cpuinfo.js +18 -18
- package/lib/parse-proc-meminfo.js +2 -2
- package/lib/prioritized-attributes.js +2 -2
- package/lib/priority-queue.js +10 -10
- package/lib/reservoir.js +3 -3
- package/lib/sampler.js +26 -26
- package/lib/shim/datastore-shim.js +35 -32
- package/lib/shim/index.js +2 -2
- package/lib/shim/message-shim.js +47 -47
- package/lib/shim/promise-shim.js +1 -1
- package/lib/shim/shim.js +61 -61
- package/lib/shim/specs/index.js +3 -3
- package/lib/shim/transaction-shim.js +44 -192
- package/lib/shim/webframework-shim.js +52 -52
- package/lib/spans/span-event.js +1 -1
- package/lib/spans/streaming-span-attributes.js +1 -1
- package/lib/stats/apdex.js +2 -2
- package/lib/stats/index.js +2 -2
- package/lib/system-info.js +23 -23
- package/lib/timer.js +5 -5
- package/lib/transaction/dt-payload.js +1 -1
- package/lib/transaction/index.js +40 -40
- package/lib/transaction/name-state.js +14 -14
- package/lib/transaction/trace/exclusive-time-calculator.js +6 -6
- package/lib/transaction/trace/index.js +14 -14
- package/lib/transaction/trace/segment.js +18 -18
- package/lib/transaction/tracecontext.js +1 -1
- package/lib/transaction/tracer/index.js +53 -49
- package/lib/uninstrumented.js +7 -7
- package/lib/util/arity.js +2 -2
- package/lib/util/byte-limit.js +4 -4
- package/lib/util/cat.js +269 -24
- package/lib/util/codec.js +2 -2
- package/lib/util/copy.js +2 -2
- package/lib/util/deep-equal.js +10 -10
- package/lib/util/flatten.js +4 -4
- package/lib/util/hashes.js +14 -14
- package/lib/util/label-parser.js +17 -17
- package/lib/util/logger.js +24 -24
- package/lib/util/process-version.js +2 -2
- package/lib/util/properties.js +4 -4
- package/lib/util/sql/obfuscate.js +15 -15
- package/lib/util/stream-sink.js +3 -3
- package/lib/util/unwrapped-core.js +2 -2
- package/lib/util/urltils.js +16 -16
- package/lib/utilization/aws-info.js +7 -7
- package/lib/utilization/azure-info.js +6 -6
- package/lib/utilization/common.js +13 -13
- package/lib/utilization/docker-info.js +11 -11
- package/lib/utilization/gcp-info.js +4 -4
- package/lib/utilization/index.js +5 -5
- package/lib/utilization/pcf-info.js +9 -9
- package/package.json +7 -2
- package/stub_api.js +8 -8
|
@@ -345,7 +345,7 @@ function setDatastore(datastore) {
|
|
|
345
345
|
*/
|
|
346
346
|
function setParser(parser) {
|
|
347
347
|
if (this.isString(parser)) {
|
|
348
|
-
|
|
348
|
+
const newParser = defaultParsers[parser]
|
|
349
349
|
if (newParser) {
|
|
350
350
|
this.queryParser = newParser
|
|
351
351
|
} else {
|
|
@@ -407,7 +407,7 @@ function recordOperation(nodule, properties, opSpec) {
|
|
|
407
407
|
shim.logger.trace('Recording datastore operation "%s"', fnName)
|
|
408
408
|
|
|
409
409
|
// Derive the segment information.
|
|
410
|
-
|
|
410
|
+
let segDesc = null
|
|
411
411
|
if (shim.isFunction(opSpec)) {
|
|
412
412
|
segDesc = opSpec.call(this, shim, fn, fnName, args)
|
|
413
413
|
} else {
|
|
@@ -531,9 +531,9 @@ function recordBatchQuery(nodule, properties, querySpec) {
|
|
|
531
531
|
* @see DatastoreShim#setParser
|
|
532
532
|
*/
|
|
533
533
|
function parseQuery(query, nodule) {
|
|
534
|
-
|
|
534
|
+
const parsed = this.queryParser.call(nodule, query)
|
|
535
535
|
|
|
536
|
-
|
|
536
|
+
let collection = parsed.collection
|
|
537
537
|
// strip enclosing special characters from collection (table) name
|
|
538
538
|
if (typeof collection === 'string' && collection.length > 2) {
|
|
539
539
|
if (/^[\[{'"`]/.test(collection)) {
|
|
@@ -544,7 +544,7 @@ function parseQuery(query, nodule) {
|
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
546
|
|
|
547
|
-
|
|
547
|
+
const queryRecorded =
|
|
548
548
|
this.agent.config.transaction_tracer.record_sql === 'raw' ||
|
|
549
549
|
this.agent.config.transaction_tracer.record_sql === 'obfuscated'
|
|
550
550
|
|
|
@@ -574,14 +574,14 @@ function parseQuery(query, nodule) {
|
|
|
574
574
|
* the segment active when the row callback is first called.
|
|
575
575
|
*/
|
|
576
576
|
function bindRowCallbackSegment(args, cbIdx, parentSegment) {
|
|
577
|
-
|
|
577
|
+
const idx = this.normalizeIndex(args.length, cbIdx)
|
|
578
578
|
if (idx === null) {
|
|
579
579
|
this.logger.debug('Not binding row callback, invalid cbIdx %s', cbIdx)
|
|
580
580
|
return
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
// Pull out the callback and make sure it is a function.
|
|
584
|
-
|
|
584
|
+
const cb = args[idx]
|
|
585
585
|
if (!this.isFunction(cb)) {
|
|
586
586
|
this.logger.debug('Argument %d is not a function, not binding row callback', cbIdx)
|
|
587
587
|
return cb
|
|
@@ -589,16 +589,16 @@ function bindRowCallbackSegment(args, cbIdx, parentSegment) {
|
|
|
589
589
|
this.logger.trace('Wrapping argument %d as a row callback.', cbIdx)
|
|
590
590
|
|
|
591
591
|
// We have a little state to maintain through potentially multiple calls.
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
592
|
+
let callCounter = 0
|
|
593
|
+
let segment = null
|
|
594
|
+
const segmentName = 'Callback: ' + this.getName(cb)
|
|
595
|
+
const shim = this
|
|
596
596
|
|
|
597
|
-
|
|
597
|
+
const wrapper = this.bindSegment(function rowCallbackWrapper() {
|
|
598
598
|
// The first time this row callback is fired we want to touch the parent
|
|
599
599
|
// segment and create the callback segment.
|
|
600
600
|
if (++callCounter === 1) {
|
|
601
|
-
|
|
601
|
+
const realParent = parentSegment || shim.getSegment()
|
|
602
602
|
realParent && realParent.touch()
|
|
603
603
|
segment = shim.createSegment(segmentName, realParent)
|
|
604
604
|
|
|
@@ -633,7 +633,7 @@ function bindRowCallbackSegment(args, cbIdx, parentSegment) {
|
|
|
633
633
|
*/
|
|
634
634
|
function captureInstanceAttributes(host, port, database) {
|
|
635
635
|
// See if we are currently in a segment created by us.
|
|
636
|
-
|
|
636
|
+
const segment = this.getSegment()
|
|
637
637
|
if (!segment || segment.shim !== this) {
|
|
638
638
|
this.logger.trace(
|
|
639
639
|
'Not adding db instance metric attributes to segment %j',
|
|
@@ -644,13 +644,13 @@ function captureInstanceAttributes(host, port, database) {
|
|
|
644
644
|
this.logger.trace('Adding db instance attributes to segment %j', segment.name)
|
|
645
645
|
|
|
646
646
|
// Normalize the instance attributes.
|
|
647
|
-
|
|
647
|
+
const attributes = _normalizeParameters.call(this, {
|
|
648
648
|
host,
|
|
649
649
|
port_path_or_id: port,
|
|
650
650
|
database_name: database
|
|
651
651
|
})
|
|
652
652
|
|
|
653
|
-
for (
|
|
653
|
+
for (const key in attributes) {
|
|
654
654
|
if (attributes[key]) {
|
|
655
655
|
segment.addAttribute(key, attributes[key])
|
|
656
656
|
}
|
|
@@ -720,7 +720,7 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
720
720
|
return this.record(nodule, properties, function queryRecord(shim, fn, fnName, args) {
|
|
721
721
|
shim.logger.trace('Determining query information for %j', fnName)
|
|
722
722
|
|
|
723
|
-
|
|
723
|
+
let queryDesc = querySpec
|
|
724
724
|
if (shim.isFunction(querySpec)) {
|
|
725
725
|
queryDesc = querySpec.call(this, shim, fn, fnName, args)
|
|
726
726
|
}
|
|
@@ -728,7 +728,10 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
728
728
|
// If we're not actually recording this, then just return the segment
|
|
729
729
|
// descriptor now.
|
|
730
730
|
if (hasOwnProperty(queryDesc, 'record') && queryDesc.record === false) {
|
|
731
|
-
|
|
731
|
+
const parameters = _normalizeParameters.call(
|
|
732
|
+
shim,
|
|
733
|
+
queryDesc.parameters || Object.create(null)
|
|
734
|
+
)
|
|
732
735
|
return {
|
|
733
736
|
name: queryDesc.name || fnName,
|
|
734
737
|
parameters,
|
|
@@ -743,21 +746,21 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
743
746
|
}
|
|
744
747
|
|
|
745
748
|
// Fetch the query string.
|
|
746
|
-
|
|
749
|
+
const queryStr = _extractQueryStr.call(shim, fn, fnName, queryDesc, this, args)
|
|
747
750
|
if (!shim.isString(queryStr)) {
|
|
748
751
|
return null
|
|
749
752
|
}
|
|
750
753
|
|
|
751
754
|
// Parse the query and assemble the name.
|
|
752
|
-
|
|
753
|
-
|
|
755
|
+
const parsed = shim.parseQuery(queryStr, this)
|
|
756
|
+
const name = (parsed.collection || 'other') + '/' + parsed.operation + suffix
|
|
754
757
|
shim.logger.trace('Found and parsed query %s -> %s', parsed.type, name)
|
|
755
758
|
|
|
756
759
|
// Return the segment descriptor.
|
|
757
|
-
|
|
760
|
+
const parameters = _normalizeParameters.call(shim, queryDesc.parameters || Object.create(null))
|
|
758
761
|
return {
|
|
759
762
|
name: shim._metrics.STATEMENT + name,
|
|
760
|
-
parameters
|
|
763
|
+
parameters,
|
|
761
764
|
callback: 'callback' in queryDesc ? queryDesc.callback : null,
|
|
762
765
|
rowCallback: 'rowCallback' in queryDesc ? queryDesc.rowCallback : null,
|
|
763
766
|
stream: 'stream' in queryDesc ? queryDesc.stream : null,
|
|
@@ -794,11 +797,11 @@ function _recordOperationMetrics(segment, scope) {
|
|
|
794
797
|
return
|
|
795
798
|
}
|
|
796
799
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
800
|
+
const duration = segment.getDurationInMillis()
|
|
801
|
+
const exclusive = segment.getExclusiveDurationInMillis()
|
|
802
|
+
const transaction = segment.transaction
|
|
803
|
+
const type = transaction.isWeb() ? 'allWeb' : 'allOther'
|
|
804
|
+
const operation = segment.name
|
|
802
805
|
|
|
803
806
|
if (scope) {
|
|
804
807
|
transaction.measure(operation, scope, duration, exclusive)
|
|
@@ -845,9 +848,9 @@ function _recordOperationMetrics(segment, scope) {
|
|
|
845
848
|
* @return {?string} The query from the arguments if found, otherwise `null`.
|
|
846
849
|
*/
|
|
847
850
|
function _extractQueryStr(fn, fnName, spec, ctx, args) {
|
|
848
|
-
|
|
851
|
+
let queryStr = spec.query
|
|
849
852
|
if (this.isNumber(queryStr)) {
|
|
850
|
-
|
|
853
|
+
const queryIdx = this.normalizeIndex(args.length, queryStr)
|
|
851
854
|
if (queryIdx === null) {
|
|
852
855
|
this.logger.debug('Invalid query index %d of %d', queryStr, args.length)
|
|
853
856
|
return null
|
|
@@ -877,8 +880,8 @@ function _extractQueryStr(fn, fnName, spec, ctx, args) {
|
|
|
877
880
|
*/
|
|
878
881
|
function _normalizeParameters(parameters) {
|
|
879
882
|
parameters = parameters || Object.create(null)
|
|
880
|
-
|
|
881
|
-
|
|
883
|
+
const config = this.agent.config
|
|
884
|
+
const dsTracerConf = config.datastore_tracer
|
|
882
885
|
|
|
883
886
|
parameters.product = parameters.product || this._datastore
|
|
884
887
|
|
package/lib/shim/index.js
CHANGED
|
@@ -25,9 +25,9 @@ SHIM_TYPE_MAP[constants.MODULE_TYPE.TRANSACTION] = TransactionShim
|
|
|
25
25
|
SHIM_TYPE_MAP[constants.MODULE_TYPE.WEB_FRAMEWORK] = WebFrameworkShim
|
|
26
26
|
|
|
27
27
|
function createShimFromType(type, agent, moduleName, resolvedName) {
|
|
28
|
-
|
|
28
|
+
let shim = null
|
|
29
29
|
if (properties.hasOwn(SHIM_TYPE_MAP, type)) {
|
|
30
|
-
|
|
30
|
+
const ShimClass = SHIM_TYPE_MAP[type]
|
|
31
31
|
shim = new ShimClass(agent, moduleName, resolvedName)
|
|
32
32
|
} else {
|
|
33
33
|
shim = new Shim(agent, moduleName, resolvedName)
|
package/lib/shim/message-shim.js
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const copy = require('../util/copy')
|
|
9
|
+
const genericRecorder = require('../metrics/recorders/generic')
|
|
10
|
+
const logger = require('../logger').child({ component: 'MessageShim' })
|
|
11
|
+
const messageTransactionRecorder = require('../metrics/recorders/message-transaction')
|
|
12
|
+
const props = require('../util/properties')
|
|
13
|
+
const TransactionShim = require('./transaction-shim')
|
|
14
|
+
const Shim = require('./shim') // For Shim.defineProperty
|
|
15
|
+
const util = require('util')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const ATTR_DESTS = require('../config/attribute-filter').DESTINATIONS
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Enumeration of well-known message brokers.
|
|
@@ -332,12 +332,12 @@ function recordProduce(nodule, properties, recordNamer) {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
return this.record(nodule, properties, function recordProd(shim) {
|
|
335
|
-
|
|
335
|
+
const msgDesc = recordNamer.apply(this, arguments)
|
|
336
336
|
if (!msgDesc) {
|
|
337
337
|
return null
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
|
|
340
|
+
const name = _nameMessageSegment(shim, msgDesc, shim._metrics.PRODUCE)
|
|
341
341
|
if (!shim.agent.config.message_tracer.segment_parameters.enabled) {
|
|
342
342
|
delete msgDesc.parameters
|
|
343
343
|
} else if (msgDesc.routingKey) {
|
|
@@ -401,7 +401,7 @@ function recordConsume(nodule, properties, spec) {
|
|
|
401
401
|
spec = properties
|
|
402
402
|
properties = null
|
|
403
403
|
}
|
|
404
|
-
|
|
404
|
+
const DEFAULT_SPEC = {
|
|
405
405
|
destinationName: null,
|
|
406
406
|
promise: false,
|
|
407
407
|
callback: null,
|
|
@@ -418,15 +418,15 @@ function recordConsume(nodule, properties, spec) {
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
return function consumeRecorder() {
|
|
421
|
-
|
|
421
|
+
const parent = shim.getSegment()
|
|
422
422
|
if (!parent || !parent.transaction.isActive()) {
|
|
423
423
|
shim.logger.trace('Not recording consume, no active transaction.')
|
|
424
424
|
return fn.apply(this, arguments)
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
// Process the message args.
|
|
428
|
-
|
|
429
|
-
|
|
428
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
429
|
+
let msgDesc = null
|
|
430
430
|
if (shim.isFunction(spec)) {
|
|
431
431
|
msgDesc = spec.call(this, shim, fn, fnName, args)
|
|
432
432
|
shim.setDefaults(msgDesc, DEFAULT_SPEC)
|
|
@@ -438,7 +438,7 @@ function recordConsume(nodule, properties, spec) {
|
|
|
438
438
|
messageHandler: spec.messageHandler
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
|
|
441
|
+
const destIdx = shim.normalizeIndex(args.length, spec.destinationName)
|
|
442
442
|
if (destIdx !== null) {
|
|
443
443
|
msgDesc.destinationName = args[destIdx]
|
|
444
444
|
}
|
|
@@ -457,11 +457,11 @@ function recordConsume(nodule, properties, spec) {
|
|
|
457
457
|
msgDesc.recorder = genericRecorder
|
|
458
458
|
msgDesc.parent = parent
|
|
459
459
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
460
|
+
const segment = shim.createSegment(msgDesc)
|
|
461
|
+
const getParams = shim.agent.config.message_tracer.segment_parameters.enabled
|
|
462
|
+
const resHandler = shim.isFunction(msgDesc.messageHandler) ? msgDesc.messageHandler : null
|
|
463
463
|
|
|
464
|
-
|
|
464
|
+
const cbIdx = shim.normalizeIndex(args.length, msgDesc.callback)
|
|
465
465
|
if (cbIdx !== null) {
|
|
466
466
|
shim.bindCallbackSegment(args, cbIdx, segment)
|
|
467
467
|
|
|
@@ -471,8 +471,8 @@ function recordConsume(nodule, properties, spec) {
|
|
|
471
471
|
shim.wrap(args, cbIdx, function wrapCb(shim, cb, cbName) {
|
|
472
472
|
if (shim.isFunction(cb)) {
|
|
473
473
|
return function cbWrapper() {
|
|
474
|
-
|
|
475
|
-
|
|
474
|
+
const cbArgs = shim.argsToArray.apply(shim, arguments)
|
|
475
|
+
const msgProps = resHandler.call(this, shim, cb, cbName, cbArgs)
|
|
476
476
|
if (getParams && msgProps && msgProps.parameters) {
|
|
477
477
|
shim.copySegmentParameters(segment, msgProps.parameters)
|
|
478
478
|
}
|
|
@@ -485,12 +485,12 @@ function recordConsume(nodule, properties, spec) {
|
|
|
485
485
|
}
|
|
486
486
|
|
|
487
487
|
// Call the method in the context of our segment.
|
|
488
|
-
|
|
488
|
+
let ret = shim.applySegment(fn, segment, true, this, args)
|
|
489
489
|
|
|
490
490
|
// Intercept the promise to handle the result.
|
|
491
491
|
if (resHandler && ret && msgDesc.promise && shim.isPromise(ret)) {
|
|
492
492
|
ret = ret.then(function interceptValue(res) {
|
|
493
|
-
|
|
493
|
+
const msgProps = resHandler.call(this, shim, fn, fnName, res)
|
|
494
494
|
if (getParams && msgProps && msgProps.parameters) {
|
|
495
495
|
shim.copySegmentParameters(segment, msgProps.parameters)
|
|
496
496
|
}
|
|
@@ -545,7 +545,7 @@ function recordPurgeQueue(nodule, properties, spec) {
|
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
// Fill the spec with defaults.
|
|
548
|
-
|
|
548
|
+
const specIsFunction = this.isFunction(spec)
|
|
549
549
|
if (!specIsFunction) {
|
|
550
550
|
spec = this.setDefaults(spec, {
|
|
551
551
|
queue: null,
|
|
@@ -556,14 +556,14 @@ function recordPurgeQueue(nodule, properties, spec) {
|
|
|
556
556
|
}
|
|
557
557
|
|
|
558
558
|
return this.record(nodule, properties, function purgeRecorder(shim, fn, name, args) {
|
|
559
|
-
|
|
559
|
+
let descriptor = spec
|
|
560
560
|
if (specIsFunction) {
|
|
561
561
|
descriptor = spec.apply(this, arguments)
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
|
|
564
|
+
let queue = descriptor.queue
|
|
565
565
|
if (shim.isNumber(queue)) {
|
|
566
|
-
|
|
566
|
+
const queueIdx = shim.normalizeIndex(args.length, descriptor.queue)
|
|
567
567
|
queue = args[queueIdx]
|
|
568
568
|
}
|
|
569
569
|
|
|
@@ -650,23 +650,23 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
650
650
|
return nodule
|
|
651
651
|
}
|
|
652
652
|
|
|
653
|
-
|
|
653
|
+
const destNameIsArg = this.isNumber(spec.destinationName)
|
|
654
654
|
|
|
655
655
|
// Must wrap the subscribe method independently to ensure that we can wrap
|
|
656
656
|
// the consumer regardless of transaction state.
|
|
657
|
-
|
|
657
|
+
const wrapped = this.wrap(nodule, properties, function wrapSubscribe(shim, fn) {
|
|
658
658
|
if (!shim.isFunction(fn)) {
|
|
659
659
|
return fn
|
|
660
660
|
}
|
|
661
661
|
return function wrappedSubscribe() {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
662
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
663
|
+
const queueIdx = shim.normalizeIndex(args.length, spec.queue)
|
|
664
|
+
const consumerIdx = shim.normalizeIndex(args.length, spec.consumer)
|
|
665
|
+
const queue = queueIdx === null ? null : args[queueIdx]
|
|
666
|
+
let destName = null
|
|
667
667
|
|
|
668
668
|
if (destNameIsArg) {
|
|
669
|
-
|
|
669
|
+
const destNameIdx = shim.normalizeIndex(args.length, spec.destinationName)
|
|
670
670
|
if (destNameIdx !== null) {
|
|
671
671
|
destName = args[destNameIdx]
|
|
672
672
|
}
|
|
@@ -686,8 +686,8 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
686
686
|
// This could happen for instance if the function signature is
|
|
687
687
|
// `fn(consumer [, callback])` and specified as `consumer: shim.FIRST`,
|
|
688
688
|
// `callback: shim.LAST`.
|
|
689
|
-
|
|
690
|
-
|
|
689
|
+
const consumerIdx = shim.normalizeIndex(args.length, spec.consumer)
|
|
690
|
+
let cbIdx = shim.normalizeIndex(args.length, spec.callback)
|
|
691
691
|
if (cbIdx === consumerIdx) {
|
|
692
692
|
cbIdx = null
|
|
693
693
|
}
|
|
@@ -703,7 +703,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
703
703
|
})
|
|
704
704
|
|
|
705
705
|
function makeWrapConsumer(queue, destinationName) {
|
|
706
|
-
|
|
706
|
+
const msgDescDefaults = copy.shallow(spec)
|
|
707
707
|
if (destNameIsArg && destinationName != null) {
|
|
708
708
|
msgDescDefaults.destinationName = destinationName
|
|
709
709
|
}
|
|
@@ -720,15 +720,15 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
720
720
|
function createConsumeTrans() {
|
|
721
721
|
// If there is no transaction or we're in a pre-existing transaction,
|
|
722
722
|
// then don't do anything. Note that the latter should never happen.
|
|
723
|
-
|
|
724
|
-
|
|
723
|
+
const args = shim.argsToArray.apply(shim, arguments)
|
|
724
|
+
const tx = shim.tracer.getTransaction()
|
|
725
725
|
|
|
726
726
|
if (!tx || tx.baseSegment) {
|
|
727
727
|
shim.logger.debug({ transaction: !!tx }, 'Failed to start message transaction.')
|
|
728
728
|
return consumer.apply(this, args)
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
-
|
|
731
|
+
const msgDesc = spec.messageHandler.call(this, shim, consumer, cName, args)
|
|
732
732
|
|
|
733
733
|
// If message could not be handled, immediately kill this transaction.
|
|
734
734
|
if (!msgDesc) {
|
|
@@ -740,7 +740,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
740
740
|
|
|
741
741
|
// Derive the transaction name.
|
|
742
742
|
shim.setDefaults(msgDesc, msgDescDefaults)
|
|
743
|
-
|
|
743
|
+
const txName = _nameMessageTransaction(shim, msgDesc)
|
|
744
744
|
tx.setPartialName(txName)
|
|
745
745
|
tx.baseSegment = shim.createSegment({
|
|
746
746
|
name: tx.getFullName(),
|
|
@@ -748,7 +748,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
748
748
|
})
|
|
749
749
|
|
|
750
750
|
// Add would-be baseSegment attributes to transaction trace
|
|
751
|
-
for (
|
|
751
|
+
for (const key in msgDesc.parameters) {
|
|
752
752
|
if (props.hasOwn(msgDesc.parameters, key)) {
|
|
753
753
|
tx.trace.attributes.addAttribute(
|
|
754
754
|
ATTR_DESTS.NONE,
|
|
@@ -794,7 +794,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
794
794
|
|
|
795
795
|
// Execute the original function and attempt to hook in the transaction
|
|
796
796
|
// finish.
|
|
797
|
-
|
|
797
|
+
let ret = null
|
|
798
798
|
try {
|
|
799
799
|
ret = shim.applySegment(consumer, tx.baseSegment, true, this, args)
|
|
800
800
|
} finally {
|
|
@@ -838,7 +838,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
838
838
|
* @return {string} The generated name of the message segment.
|
|
839
839
|
*/
|
|
840
840
|
function _nameMessageSegment(shim, msgDesc, action) {
|
|
841
|
-
|
|
841
|
+
let name =
|
|
842
842
|
shim._metrics.PREFIX +
|
|
843
843
|
shim._metrics.LIBRARY +
|
|
844
844
|
'/' +
|
|
@@ -856,7 +856,7 @@ function _nameMessageSegment(shim, msgDesc, action) {
|
|
|
856
856
|
}
|
|
857
857
|
|
|
858
858
|
function _nameMessageTransaction(shim, msgDesc) {
|
|
859
|
-
|
|
859
|
+
let name = shim._metrics.LIBRARY + '/' + (msgDesc.destinationType || shim.EXCHANGE) + '/'
|
|
860
860
|
|
|
861
861
|
if (msgDesc.destinationName) {
|
|
862
862
|
name += shim._metrics.NAMED + msgDesc.destinationName
|
package/lib/shim/promise-shim.js
CHANGED
|
@@ -154,7 +154,7 @@ class PromiseShim extends Shim {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
return function wrappedExecutorCaller(executor) {
|
|
157
|
-
|
|
157
|
+
const parent = shim.getActiveSegment()
|
|
158
158
|
if (!this || !parent) {
|
|
159
159
|
return caller.apply(this, arguments)
|
|
160
160
|
}
|