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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const apiGateway = require('./api-gateway')
|
|
9
9
|
const headerAttributes = require('../header-attributes')
|
|
10
10
|
const get = require('../util/get')
|
|
11
|
-
const logger = require('../logger').child({component: 'aws-lambda'})
|
|
11
|
+
const logger = require('../logger').child({ component: 'aws-lambda' })
|
|
12
12
|
const recordBackground = require('../metrics/recorders/other')
|
|
13
13
|
const recordWeb = require('../metrics/recorders/http')
|
|
14
14
|
const TransactionShim = require('../shim/transaction-shim')
|
|
@@ -106,7 +106,7 @@ class AwsLambda {
|
|
|
106
106
|
})
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
return shim.bindCreateTransaction(wrappedHandler, {type: shim.BG})
|
|
109
|
+
return shim.bindCreateTransaction(wrappedHandler, { type: shim.BG })
|
|
110
110
|
|
|
111
111
|
function wrappedHandler() {
|
|
112
112
|
const args = shim.argsToArray.apply(shim, arguments)
|
|
@@ -138,17 +138,12 @@ class AwsLambda {
|
|
|
138
138
|
resultProcessor = getApiGatewayLambdaProxyResultProcessor(transaction)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
142
141
|
const cbIndex = args.length - 1
|
|
143
142
|
|
|
144
143
|
// Add transaction ending closure to the list of functions to be called on
|
|
145
144
|
// beforeExit (i.e. in the case that context.{done,fail,succeed} or callback
|
|
146
145
|
// were not called).
|
|
147
|
-
const txnEnder = endTransaction.bind(
|
|
148
|
-
null,
|
|
149
|
-
transaction,
|
|
150
|
-
transactionEnders.length
|
|
151
|
-
)
|
|
146
|
+
const txnEnder = endTransaction.bind(null, transaction, transactionEnders.length)
|
|
152
147
|
|
|
153
148
|
transactionEnders.push(txnEnder)
|
|
154
149
|
|
|
@@ -171,10 +166,7 @@ class AwsLambda {
|
|
|
171
166
|
})
|
|
172
167
|
|
|
173
168
|
const awsAttributes = awsLambda._getAwsAgentAttributes(event, context)
|
|
174
|
-
transaction.trace.attributes.addAttributes(
|
|
175
|
-
ATTR_DEST.TRANS_COMMON,
|
|
176
|
-
awsAttributes
|
|
177
|
-
)
|
|
169
|
+
transaction.trace.attributes.addAttributes(ATTR_DEST.TRANS_COMMON, awsAttributes)
|
|
178
170
|
|
|
179
171
|
shim.agent.setLambdaArn(context.invokedFunctionArn)
|
|
180
172
|
|
|
@@ -201,17 +193,20 @@ class AwsLambda {
|
|
|
201
193
|
// we need to store the error in uncaughtException
|
|
202
194
|
// otherwise the transaction will end before they are captured
|
|
203
195
|
function lambdaInterceptPromise(prom, resultProcessor, cb) {
|
|
204
|
-
return prom.then(
|
|
205
|
-
|
|
206
|
-
resultProcessor
|
|
196
|
+
return prom.then(
|
|
197
|
+
function onThen(arg) {
|
|
198
|
+
if (resultProcessor) {
|
|
199
|
+
resultProcessor(arg)
|
|
200
|
+
}
|
|
201
|
+
cb()
|
|
202
|
+
return arg
|
|
203
|
+
},
|
|
204
|
+
function onCatch(err) {
|
|
205
|
+
uncaughtException = err
|
|
206
|
+
cb()
|
|
207
|
+
throw err // This is not our error, just rethrowing the promise rejection.
|
|
207
208
|
}
|
|
208
|
-
|
|
209
|
-
return arg
|
|
210
|
-
}, function onCatch(err) {
|
|
211
|
-
uncaughtException = err
|
|
212
|
-
cb()
|
|
213
|
-
throw err // This is not our error, just rethrowing the promise rejection.
|
|
214
|
-
})
|
|
209
|
+
)
|
|
215
210
|
}
|
|
216
211
|
|
|
217
212
|
function wrapCallbackAndCaptureError(transaction, txnEnder, cb, processResult) {
|
|
@@ -285,8 +280,11 @@ function setEventSourceAttributes(event, attributes) {
|
|
|
285
280
|
} else if (event.records && event.deliveryStreamArn) {
|
|
286
281
|
// Kinesis Firehose
|
|
287
282
|
attributes[EVENT_SOURCE_ARN_KEY] = event.deliveryStreamArn
|
|
288
|
-
} else if (
|
|
289
|
-
event.requestContext
|
|
283
|
+
} else if (
|
|
284
|
+
event.requestContext &&
|
|
285
|
+
event.requestContext.elb &&
|
|
286
|
+
event.requestContext.elb.targetGroupArn
|
|
287
|
+
) {
|
|
290
288
|
attributes[EVENT_SOURCE_ARN_KEY] = event.requestContext.elb.targetGroupArn
|
|
291
289
|
} else if (event.resources && event.resources[0]) {
|
|
292
290
|
attributes[EVENT_SOURCE_ARN_KEY] = event.resources[0]
|
|
@@ -319,10 +317,7 @@ function setWebRequest(shim, transaction, request) {
|
|
|
319
317
|
request.method
|
|
320
318
|
)
|
|
321
319
|
|
|
322
|
-
segment.addSpanAttribute(
|
|
323
|
-
'request.method',
|
|
324
|
-
request.method
|
|
325
|
-
)
|
|
320
|
+
segment.addSpanAttribute('request.method', request.method)
|
|
326
321
|
|
|
327
322
|
transaction.port = request.url.port
|
|
328
323
|
|
|
@@ -335,10 +330,7 @@ function setWebRequest(shim, transaction, request) {
|
|
|
335
330
|
request.url.path
|
|
336
331
|
)
|
|
337
332
|
|
|
338
|
-
segment.addSpanAttribute(
|
|
339
|
-
'request.uri',
|
|
340
|
-
request.url.path
|
|
341
|
-
)
|
|
333
|
+
segment.addSpanAttribute('request.uri', request.url.path)
|
|
342
334
|
|
|
343
335
|
headerAttributes.collectRequestHeaders(request.headers, transaction)
|
|
344
336
|
|
|
@@ -351,11 +343,10 @@ function setWebRequest(shim, transaction, request) {
|
|
|
351
343
|
}
|
|
352
344
|
|
|
353
345
|
function lowercaseObjectKeys(original) {
|
|
354
|
-
const lowercaseObject = Object.keys(original)
|
|
355
|
-
.
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}, {})
|
|
346
|
+
const lowercaseObject = Object.keys(original).reduce((destination, key) => {
|
|
347
|
+
destination[key.toLowerCase()] = original[key]
|
|
348
|
+
return destination
|
|
349
|
+
}, {})
|
|
359
350
|
|
|
360
351
|
return lowercaseObject
|
|
361
352
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
const logger = require('../logger').child({component: 'ConglomerateShim'})
|
|
8
|
+
const logger = require('../logger').child({ component: 'ConglomerateShim' })
|
|
9
9
|
const Shim = require('./shim')
|
|
10
10
|
|
|
11
|
-
const {MODULE_TYPE} = require('./constants')
|
|
11
|
+
const { MODULE_TYPE } = require('./constants')
|
|
12
12
|
const SHIM_CLASSES = {
|
|
13
13
|
[MODULE_TYPE.GENERIC]: Shim,
|
|
14
14
|
[MODULE_TYPE.DATASTORE]: require('./datastore-shim'),
|
|
@@ -27,7 +27,7 @@ const SHIM_CLASSES = {
|
|
|
27
27
|
class ConglomerateShim extends Shim {
|
|
28
28
|
constructor(agent, moduleName, resolvedName) {
|
|
29
29
|
super(agent, moduleName, resolvedName)
|
|
30
|
-
this._logger = logger.child({module: moduleName})
|
|
30
|
+
this._logger = logger.child({ module: moduleName })
|
|
31
31
|
this._resolvedName = resolvedName
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -62,7 +62,7 @@ class ConglomerateShim extends Shim {
|
|
|
62
62
|
makeSpecializedShim(type, submodule) {
|
|
63
63
|
const ShimClass = SHIM_CLASSES[type]
|
|
64
64
|
const shim = new ShimClass(this.agent, this.moduleName, this._resolvedName)
|
|
65
|
-
shim._logger = shim._logger.child({submodule})
|
|
65
|
+
shim._logger = shim._logger.child({ submodule })
|
|
66
66
|
return shim
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const dbutil = require('../db/utils')
|
|
9
9
|
const hasOwnProperty = require('../util/properties').hasOwn
|
|
10
|
-
const logger = require('../logger').child({component: 'DatastoreShim'})
|
|
10
|
+
const logger = require('../logger').child({ component: 'DatastoreShim' })
|
|
11
11
|
const metrics = require('../metrics/names')
|
|
12
12
|
const parseSql = require('../db/query-parsers/sql')
|
|
13
13
|
const ParsedStatement = require('../db/parsed-statement')
|
|
@@ -15,7 +15,6 @@ const Shim = require('./shim')
|
|
|
15
15
|
const urltils = require('../util/urltils')
|
|
16
16
|
const util = require('util')
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* An enumeration of well-known datastores so that new instrumentations can use
|
|
21
20
|
* the same names we already use for first-party instrumentation.
|
|
@@ -47,7 +46,7 @@ const DATASTORE_NAMES = {
|
|
|
47
46
|
const INSTANCE_UNKNOWN = 'unknown'
|
|
48
47
|
|
|
49
48
|
const defaultParsers = {
|
|
50
|
-
|
|
49
|
+
SQL: parseSql
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
/**
|
|
@@ -93,7 +92,7 @@ const QUERY_PARSERS = {
|
|
|
93
92
|
*/
|
|
94
93
|
function DatastoreShim(agent, moduleName, resolvedName, datastoreId) {
|
|
95
94
|
Shim.call(this, agent, moduleName, resolvedName)
|
|
96
|
-
this._logger = logger.child({module: moduleName})
|
|
95
|
+
this._logger = logger.child({ module: moduleName })
|
|
97
96
|
if (datastoreId) {
|
|
98
97
|
this.setDatastore(datastoreId)
|
|
99
98
|
}
|
|
@@ -326,8 +325,8 @@ function setDatastore(datastore) {
|
|
|
326
325
|
|
|
327
326
|
this._datastore = datastore
|
|
328
327
|
|
|
329
|
-
this._logger = this._logger.child({datastore: this._metrics.PREFIX})
|
|
330
|
-
this.logger.trace({metrics: this._metrics}, 'Datastore metric names set')
|
|
328
|
+
this._logger = this._logger.child({ datastore: this._metrics.PREFIX })
|
|
329
|
+
this.logger.trace({ metrics: this._metrics }, 'Datastore metric names set')
|
|
331
330
|
}
|
|
332
331
|
|
|
333
332
|
/**
|
|
@@ -358,10 +357,7 @@ function setParser(parser) {
|
|
|
358
357
|
} else if (this.isFunction(parser)) {
|
|
359
358
|
this.queryParser = parser
|
|
360
359
|
} else {
|
|
361
|
-
this.logger.trace(
|
|
362
|
-
"Received invalid parser (%s)",
|
|
363
|
-
parser
|
|
364
|
-
)
|
|
360
|
+
this.logger.trace('Received invalid parser (%s)', parser)
|
|
365
361
|
}
|
|
366
362
|
}
|
|
367
363
|
|
|
@@ -548,10 +544,9 @@ function parseQuery(query, nodule) {
|
|
|
548
544
|
}
|
|
549
545
|
}
|
|
550
546
|
|
|
551
|
-
var queryRecorded =
|
|
547
|
+
var queryRecorded =
|
|
552
548
|
this.agent.config.transaction_tracer.record_sql === 'raw' ||
|
|
553
549
|
this.agent.config.transaction_tracer.record_sql === 'obfuscated'
|
|
554
|
-
)
|
|
555
550
|
|
|
556
551
|
return new ParsedStatement(
|
|
557
552
|
this._metrics.PREFIX,
|
|
@@ -733,18 +728,17 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
733
728
|
// If we're not actually recording this, then just return the segment
|
|
734
729
|
// descriptor now.
|
|
735
730
|
if (hasOwnProperty(queryDesc, 'record') && queryDesc.record === false) {
|
|
736
|
-
var parameters =
|
|
737
|
-
_normalizeParameters.call(shim, queryDesc.parameters || Object.create(null))
|
|
731
|
+
var parameters = _normalizeParameters.call(shim, queryDesc.parameters || Object.create(null))
|
|
738
732
|
return {
|
|
739
733
|
name: queryDesc.name || fnName,
|
|
740
734
|
parameters,
|
|
741
|
-
callback:
|
|
742
|
-
rowCallback:
|
|
743
|
-
stream:
|
|
744
|
-
after:
|
|
745
|
-
promise:
|
|
746
|
-
internal:
|
|
747
|
-
opaque:
|
|
735
|
+
callback: 'callback' in queryDesc ? queryDesc.callback : null,
|
|
736
|
+
rowCallback: 'rowCallback' in queryDesc ? queryDesc.rowCallback : null,
|
|
737
|
+
stream: 'stream' in queryDesc ? queryDesc.stream : null,
|
|
738
|
+
after: 'after' in queryDesc ? queryDesc.after : null,
|
|
739
|
+
promise: 'promise' in queryDesc ? queryDesc.promise : null,
|
|
740
|
+
internal: 'internal' in queryDesc ? queryDesc.internal : false,
|
|
741
|
+
opaque: 'opaque' in queryDesc ? queryDesc.opaque : false
|
|
748
742
|
}
|
|
749
743
|
}
|
|
750
744
|
|
|
@@ -760,18 +754,17 @@ function _recordQuery(suffix, nodule, properties, querySpec) {
|
|
|
760
754
|
shim.logger.trace('Found and parsed query %s -> %s', parsed.type, name)
|
|
761
755
|
|
|
762
756
|
// Return the segment descriptor.
|
|
763
|
-
var parameters =
|
|
764
|
-
_normalizeParameters.call(shim, queryDesc.parameters || Object.create(null))
|
|
757
|
+
var parameters = _normalizeParameters.call(shim, queryDesc.parameters || Object.create(null))
|
|
765
758
|
return {
|
|
766
759
|
name: shim._metrics.STATEMENT + name,
|
|
767
760
|
parameters: parameters,
|
|
768
|
-
callback:
|
|
769
|
-
rowCallback:
|
|
770
|
-
stream:
|
|
771
|
-
after:
|
|
772
|
-
promise:
|
|
773
|
-
internal:
|
|
774
|
-
opaque:
|
|
761
|
+
callback: 'callback' in queryDesc ? queryDesc.callback : null,
|
|
762
|
+
rowCallback: 'rowCallback' in queryDesc ? queryDesc.rowCallback : null,
|
|
763
|
+
stream: 'stream' in queryDesc ? queryDesc.stream : null,
|
|
764
|
+
after: 'after' in queryDesc ? queryDesc.after : null,
|
|
765
|
+
promise: 'promise' in queryDesc ? queryDesc.promise : null,
|
|
766
|
+
internal: 'internal' in queryDesc ? queryDesc.internal : true,
|
|
767
|
+
opaque: 'opaque' in queryDesc ? queryDesc.opaque : false,
|
|
775
768
|
recorder: function queryRecorder(segment, scope) {
|
|
776
769
|
if (segment) {
|
|
777
770
|
parsed.recordMetrics(segment, scope)
|
|
@@ -823,7 +816,7 @@ function _recordOperationMetrics(segment, scope) {
|
|
|
823
816
|
)
|
|
824
817
|
|
|
825
818
|
const attributes = segment.getAttributes()
|
|
826
|
-
if (attributes.host && attributes.port_path_or_id
|
|
819
|
+
if (attributes.host && attributes.port_path_or_id) {
|
|
827
820
|
const instanceName = [
|
|
828
821
|
metrics.DB.INSTANCE,
|
|
829
822
|
this._metrics.PREFIX,
|
|
@@ -892,13 +885,11 @@ function _normalizeParameters(parameters) {
|
|
|
892
885
|
// Add database name if provided and enabled.
|
|
893
886
|
if (!dsTracerConf.database_name_reporting.enabled) {
|
|
894
887
|
delete parameters.database_name
|
|
895
|
-
} else if (
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
? String(parameters.database_name)
|
|
901
|
-
: (parameters.database_name || INSTANCE_UNKNOWN)
|
|
888
|
+
} else if (hasOwnProperty(parameters, 'database_name') && parameters.database_name !== false) {
|
|
889
|
+
parameters.database_name =
|
|
890
|
+
typeof parameters.database_name === 'number'
|
|
891
|
+
? String(parameters.database_name)
|
|
892
|
+
: parameters.database_name || INSTANCE_UNKNOWN
|
|
902
893
|
}
|
|
903
894
|
|
|
904
895
|
// Add instance information if enabled.
|
package/lib/shim/index.js
CHANGED
|
@@ -15,6 +15,14 @@ const PromiseShim = require('./promise-shim')
|
|
|
15
15
|
const TransactionShim = require('./transaction-shim')
|
|
16
16
|
const WebFrameworkShim = require('./webframework-shim')
|
|
17
17
|
const properties = require('../util/properties')
|
|
18
|
+
const SHIM_TYPE_MAP = Object.create(null)
|
|
19
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.GENERIC] = Shim
|
|
20
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.CONGLOMERATE] = ConglomerateShim
|
|
21
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.DATASTORE] = DatastoreShim
|
|
22
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.MESSAGE] = MessageShim
|
|
23
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.PROMISE] = PromiseShim
|
|
24
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.TRANSACTION] = TransactionShim
|
|
25
|
+
SHIM_TYPE_MAP[constants.MODULE_TYPE.WEB_FRAMEWORK] = WebFrameworkShim
|
|
18
26
|
|
|
19
27
|
function createShimFromType(type, agent, moduleName, resolvedName) {
|
|
20
28
|
var shim = null
|
|
@@ -27,15 +35,6 @@ function createShimFromType(type, agent, moduleName, resolvedName) {
|
|
|
27
35
|
return shim
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
var SHIM_TYPE_MAP = Object.create(null)
|
|
31
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.GENERIC] = Shim
|
|
32
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.CONGLOMERATE] = ConglomerateShim
|
|
33
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.DATASTORE] = DatastoreShim
|
|
34
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.MESSAGE] = MessageShim
|
|
35
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.PROMISE] = PromiseShim
|
|
36
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.TRANSACTION] = TransactionShim
|
|
37
|
-
SHIM_TYPE_MAP[constants.MODULE_TYPE.WEB_FRAMEWORK] = WebFrameworkShim
|
|
38
|
-
|
|
39
38
|
exports.constants = constants
|
|
40
39
|
exports.Shim = Shim
|
|
41
40
|
exports.ConglomerateShim = ConglomerateShim
|
package/lib/shim/message-shim.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
var copy = require('../util/copy')
|
|
9
9
|
var genericRecorder = require('../metrics/recorders/generic')
|
|
10
|
-
var logger = require('../logger').child({component: 'MessageShim'})
|
|
10
|
+
var logger = require('../logger').child({ component: 'MessageShim' })
|
|
11
11
|
var messageTransactionRecorder = require('../metrics/recorders/message-transaction')
|
|
12
12
|
var props = require('../util/properties')
|
|
13
13
|
var TransactionShim = require('./transaction-shim')
|
|
@@ -16,7 +16,6 @@ var util = require('util')
|
|
|
16
16
|
|
|
17
17
|
var ATTR_DESTS = require('../config/attribute-filter').DESTINATIONS
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* Enumeration of well-known message brokers.
|
|
22
21
|
*
|
|
@@ -60,7 +59,6 @@ const DESTINATION_TYPES = {
|
|
|
60
59
|
TOPIC: 'Topic'
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
|
|
64
62
|
/**
|
|
65
63
|
* Constructs a shim specialized for instrumenting message brokers.
|
|
66
64
|
*
|
|
@@ -83,7 +81,7 @@ const DESTINATION_TYPES = {
|
|
|
83
81
|
*/
|
|
84
82
|
function MessageShim(agent, moduleName, resolvedName) {
|
|
85
83
|
TransactionShim.call(this, agent, moduleName, resolvedName)
|
|
86
|
-
this._logger = logger.child({module: moduleName})
|
|
84
|
+
this._logger = logger.child({ module: moduleName })
|
|
87
85
|
this._metrics = null
|
|
88
86
|
this._transportType = TransactionShim.TRANSPORT_TYPES.UNKNOWN
|
|
89
87
|
}
|
|
@@ -293,8 +291,8 @@ function setLibrary(library) {
|
|
|
293
291
|
this._transportType = LIBRARY_TRANSPORT_TYPES[library]
|
|
294
292
|
}
|
|
295
293
|
|
|
296
|
-
this._logger = this._logger.child({library: library})
|
|
297
|
-
this.logger.trace({metrics: this._metrics}, 'Library metric names set')
|
|
294
|
+
this._logger = this._logger.child({ library: library })
|
|
295
|
+
this.logger.trace({ metrics: this._metrics }, 'Library metric names set')
|
|
298
296
|
}
|
|
299
297
|
|
|
300
298
|
/**
|
|
@@ -461,8 +459,7 @@ function recordConsume(nodule, properties, spec) {
|
|
|
461
459
|
|
|
462
460
|
var segment = shim.createSegment(msgDesc)
|
|
463
461
|
var getParams = shim.agent.config.message_tracer.segment_parameters.enabled
|
|
464
|
-
var resHandler = shim.isFunction(msgDesc.messageHandler)
|
|
465
|
-
? msgDesc.messageHandler : null
|
|
462
|
+
var resHandler = shim.isFunction(msgDesc.messageHandler) ? msgDesc.messageHandler : null
|
|
466
463
|
|
|
467
464
|
var cbIdx = shim.normalizeIndex(args.length, msgDesc.callback)
|
|
468
465
|
if (cbIdx !== null) {
|
|
@@ -571,10 +568,14 @@ function recordPurgeQueue(nodule, properties, spec) {
|
|
|
571
568
|
}
|
|
572
569
|
|
|
573
570
|
return {
|
|
574
|
-
name: _nameMessageSegment(
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
571
|
+
name: _nameMessageSegment(
|
|
572
|
+
shim,
|
|
573
|
+
{
|
|
574
|
+
destinationType: shim.QUEUE,
|
|
575
|
+
destinationName: queue
|
|
576
|
+
},
|
|
577
|
+
shim._metrics.PURGE
|
|
578
|
+
),
|
|
578
579
|
recorder: genericRecorder,
|
|
579
580
|
callback: descriptor.callback,
|
|
580
581
|
promise: descriptor.promise,
|
|
@@ -672,10 +673,7 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
672
673
|
}
|
|
673
674
|
|
|
674
675
|
if (consumerIdx !== null) {
|
|
675
|
-
args[consumerIdx] = shim.wrap(
|
|
676
|
-
args[consumerIdx],
|
|
677
|
-
makeWrapConsumer(queue, destName)
|
|
678
|
-
)
|
|
676
|
+
args[consumerIdx] = shim.wrap(args[consumerIdx], makeWrapConsumer(queue, destName))
|
|
679
677
|
}
|
|
680
678
|
|
|
681
679
|
return fn.apply(this, args)
|
|
@@ -718,112 +716,110 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
718
716
|
return consumer
|
|
719
717
|
}
|
|
720
718
|
|
|
721
|
-
return shim.bindCreateTransaction(
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
719
|
+
return shim.bindCreateTransaction(
|
|
720
|
+
function createConsumeTrans() {
|
|
721
|
+
// If there is no transaction or we're in a pre-existing transaction,
|
|
722
|
+
// then don't do anything. Note that the latter should never happen.
|
|
723
|
+
var args = shim.argsToArray.apply(shim, arguments)
|
|
724
|
+
var tx = shim.tracer.getTransaction()
|
|
726
725
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
726
|
+
if (!tx || tx.baseSegment) {
|
|
727
|
+
shim.logger.debug({ transaction: !!tx }, 'Failed to start message transaction.')
|
|
728
|
+
return consumer.apply(this, args)
|
|
729
|
+
}
|
|
731
730
|
|
|
732
|
-
|
|
731
|
+
var msgDesc = spec.messageHandler.call(this, shim, consumer, cName, args)
|
|
733
732
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
733
|
+
// If message could not be handled, immediately kill this transaction.
|
|
734
|
+
if (!msgDesc) {
|
|
735
|
+
shim.logger.debug('No description for message, cancelling transaction.')
|
|
736
|
+
tx.setForceIgnore(true)
|
|
737
|
+
tx.end()
|
|
738
|
+
return consumer.apply(this, args)
|
|
739
|
+
}
|
|
741
740
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
741
|
+
// Derive the transaction name.
|
|
742
|
+
shim.setDefaults(msgDesc, msgDescDefaults)
|
|
743
|
+
var txName = _nameMessageTransaction(shim, msgDesc)
|
|
744
|
+
tx.setPartialName(txName)
|
|
745
|
+
tx.baseSegment = shim.createSegment({
|
|
746
|
+
name: tx.getFullName(),
|
|
747
|
+
recorder: messageTransactionRecorder
|
|
748
|
+
})
|
|
750
749
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
750
|
+
// Add would-be baseSegment attributes to transaction trace
|
|
751
|
+
for (var key in msgDesc.parameters) {
|
|
752
|
+
if (props.hasOwn(msgDesc.parameters, key)) {
|
|
753
|
+
tx.trace.attributes.addAttribute(
|
|
754
|
+
ATTR_DESTS.NONE,
|
|
755
|
+
'message.parameters.' + key,
|
|
756
|
+
msgDesc.parameters[key]
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
tx.baseSegment.attributes.addAttribute(
|
|
760
|
+
ATTR_DESTS.NONE,
|
|
761
|
+
'message.parameters.' + key,
|
|
762
|
+
msgDesc.parameters[key]
|
|
763
|
+
)
|
|
764
|
+
}
|
|
764
765
|
}
|
|
765
|
-
}
|
|
766
766
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
767
|
+
// If we have a routing key, add it to the transaction. Note that it is
|
|
768
|
+
// camel cased here, but snake cased in the segment parameters.
|
|
769
|
+
if (!shim.agent.config.high_security) {
|
|
770
|
+
if (msgDesc.routingKey) {
|
|
771
|
+
tx.trace.attributes.addAttribute(
|
|
772
|
+
ATTR_DESTS.TRANS_COMMON,
|
|
773
|
+
'message.routingKey',
|
|
774
|
+
msgDesc.routingKey
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
tx.baseSegment.addSpanAttribute('message.routingKey', msgDesc.routingKey)
|
|
778
|
+
}
|
|
779
|
+
if (shim.isString(msgDesc.queue)) {
|
|
780
|
+
tx.trace.attributes.addAttribute(
|
|
781
|
+
ATTR_DESTS.TRANS_COMMON,
|
|
782
|
+
'message.queueName',
|
|
783
|
+
msgDesc.queue
|
|
784
|
+
)
|
|
785
|
+
|
|
786
|
+
tx.baseSegment.addSpanAttribute('message.queueName', msgDesc.queue)
|
|
787
|
+
}
|
|
781
788
|
}
|
|
782
|
-
if (
|
|
783
|
-
tx.
|
|
784
|
-
ATTR_DESTS.TRANS_COMMON,
|
|
785
|
-
'message.queueName',
|
|
786
|
-
msgDesc.queue
|
|
787
|
-
)
|
|
788
|
-
|
|
789
|
-
tx.baseSegment.addSpanAttribute(
|
|
790
|
-
'message.queueName',
|
|
791
|
-
msgDesc.queue
|
|
792
|
-
)
|
|
789
|
+
if (msgDesc.headers) {
|
|
790
|
+
shim.handleCATHeaders(msgDesc.headers, tx.baseSegment, shim._transportType)
|
|
793
791
|
}
|
|
794
|
-
}
|
|
795
|
-
if (msgDesc.headers) {
|
|
796
|
-
shim.handleCATHeaders(msgDesc.headers, tx.baseSegment, shim._transportType)
|
|
797
|
-
}
|
|
798
792
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
793
|
+
shim.logger.trace('Started message transaction %s named %s', tx.id, txName)
|
|
794
|
+
|
|
795
|
+
// Execute the original function and attempt to hook in the transaction
|
|
796
|
+
// finish.
|
|
797
|
+
var ret = null
|
|
798
|
+
try {
|
|
799
|
+
ret = shim.applySegment(consumer, tx.baseSegment, true, this, args)
|
|
800
|
+
} finally {
|
|
801
|
+
if (shim.isPromise(ret)) {
|
|
802
|
+
shim.logger.trace('Got a promise, attaching tx %s ending to promise', tx.id)
|
|
803
|
+
ret = shim.interceptPromise(ret, endTransaction)
|
|
804
|
+
} else if (!tx.handledExternally) {
|
|
805
|
+
// We have no way of knowing when this transaction ended! ABORT!
|
|
806
|
+
shim.logger.trace('Immediately ending message tx %s', tx.id)
|
|
807
|
+
setImmediate(endTransaction)
|
|
808
|
+
}
|
|
814
809
|
}
|
|
815
|
-
}
|
|
816
810
|
|
|
817
|
-
|
|
811
|
+
return ret
|
|
818
812
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
813
|
+
function endTransaction() {
|
|
814
|
+
tx.finalizeName(null) // Use existing partial name.
|
|
815
|
+
tx.end()
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
type: shim.MESSAGE,
|
|
820
|
+
nest: true
|
|
822
821
|
}
|
|
823
|
-
|
|
824
|
-
type: shim.MESSAGE,
|
|
825
|
-
nest: true
|
|
826
|
-
})
|
|
822
|
+
)
|
|
827
823
|
}
|
|
828
824
|
}
|
|
829
825
|
}
|
|
@@ -843,8 +839,12 @@ function recordSubscribedConsume(nodule, properties, spec) {
|
|
|
843
839
|
*/
|
|
844
840
|
function _nameMessageSegment(shim, msgDesc, action) {
|
|
845
841
|
var name =
|
|
846
|
-
shim._metrics.PREFIX +
|
|
847
|
-
|
|
842
|
+
shim._metrics.PREFIX +
|
|
843
|
+
shim._metrics.LIBRARY +
|
|
844
|
+
'/' +
|
|
845
|
+
(msgDesc.destinationType || shim.EXCHANGE) +
|
|
846
|
+
'/' +
|
|
847
|
+
action
|
|
848
848
|
|
|
849
849
|
if (msgDesc.destinationName) {
|
|
850
850
|
name += shim._metrics.NAMED + msgDesc.destinationName
|
|
@@ -856,9 +856,7 @@ function _nameMessageSegment(shim, msgDesc, action) {
|
|
|
856
856
|
}
|
|
857
857
|
|
|
858
858
|
function _nameMessageTransaction(shim, msgDesc) {
|
|
859
|
-
var name =
|
|
860
|
-
shim._metrics.LIBRARY + '/' +
|
|
861
|
-
(msgDesc.destinationType || shim.EXCHANGE) + '/'
|
|
859
|
+
var name = shim._metrics.LIBRARY + '/' + (msgDesc.destinationType || shim.EXCHANGE) + '/'
|
|
862
860
|
|
|
863
861
|
if (msgDesc.destinationName) {
|
|
864
862
|
name += shim._metrics.NAMED + msgDesc.destinationName
|