newrelic 8.3.0 → 8.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEWS.md +76 -0
- package/README.md +7 -6
- package/THIRD_PARTY_NOTICES.md +95 -35
- 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/feature_flags.js +7 -5
- 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 +15 -84
- 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/fastify/spec-builders.js +57 -47
- package/lib/instrumentation/fastify.js +85 -24
- 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 +16 -5
- 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/undici.js +242 -0
- package/lib/instrumentation/vision.js +4 -4
- package/lib/instrumentation/when.js +3 -3
- package/lib/instrumentations.js +2 -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 +25 -19
- package/lib/parse-proc-meminfo.js +8 -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/serverless/aws-lambda.js +8 -2
- 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 +13 -6
- package/stub_api.js +8 -8
|
@@ -47,9 +47,11 @@ common.instrumentCollection = function instrumentCollection(shim, Collection) {
|
|
|
47
47
|
* Instruments all methods from constants.DB_OPS on
|
|
48
48
|
* the Db class.
|
|
49
49
|
*
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {object} params
|
|
51
51
|
* @param {Shim} params.shim
|
|
52
52
|
* @param {Db} params.Db
|
|
53
|
+
* @param shim
|
|
54
|
+
* @param Db
|
|
53
55
|
*/
|
|
54
56
|
common.instrumentDb = function instrumentDb(shim, Db) {
|
|
55
57
|
if (Db && Db.prototype) {
|
|
@@ -62,6 +64,7 @@ common.instrumentDb = function instrumentDb(shim, Db) {
|
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* Sets up the desc for all instrumented query methods
|
|
67
|
+
*
|
|
65
68
|
* @param {Shim} shim
|
|
66
69
|
* @param {string} methodName
|
|
67
70
|
*/
|
|
@@ -123,7 +126,7 @@ common.captureAttributesOnStarted = function captureAttributesOnStarted(shim, in
|
|
|
123
126
|
* @param {Shim} shim
|
|
124
127
|
* @param {string} connStr
|
|
125
128
|
* @param {string} db database name
|
|
126
|
-
* @param {
|
|
129
|
+
* @param {object} client mongo client instance
|
|
127
130
|
*/
|
|
128
131
|
function setHostPort(shim, connStr, db, client) {
|
|
129
132
|
const parts = connStr.split(':')
|
|
@@ -153,6 +156,9 @@ function setHostPort(shim, connStr, db, client) {
|
|
|
153
156
|
* for the query segment. v4 refactored where the toplogy is stored.
|
|
154
157
|
* You can now get the details via the client obj that's deeply nested
|
|
155
158
|
* See: https://github.com/mongodb/node-mongodb-native/pull/2594/files#diff-1d214e57ddda9095d296e5700ebce701333bfefcf417e234c584d14091b2f50dR168
|
|
159
|
+
*
|
|
160
|
+
* @param shim
|
|
161
|
+
* @param obj
|
|
156
162
|
*/
|
|
157
163
|
function getInstanceAttributeParameters(shim, obj) {
|
|
158
164
|
if (obj.s && obj.s.db && obj.s.topology) {
|
|
@@ -173,7 +179,10 @@ function getInstanceAttributeParameters(shim, obj) {
|
|
|
173
179
|
obj.s.db.s.client.s.options.hosts.length
|
|
174
180
|
) {
|
|
175
181
|
// hosts is an array but we will always pull the first for consistency
|
|
176
|
-
|
|
182
|
+
const hosts = obj.s.db.s.client.s.options.hosts
|
|
183
|
+
let host = hosts[0].host
|
|
184
|
+
let port = hosts[0].port
|
|
185
|
+
const socketPath = hosts[0].socketPath
|
|
177
186
|
|
|
178
187
|
if (socketPath) {
|
|
179
188
|
port = socketPath
|
|
@@ -194,8 +203,10 @@ function getInstanceAttributeParameters(shim, obj) {
|
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
function doCapture(conf, database) {
|
|
197
|
-
|
|
198
|
-
|
|
206
|
+
// in older versions of 3.x the host/port
|
|
207
|
+
// lived directly on the topology.s.options
|
|
208
|
+
let host = conf.host
|
|
209
|
+
let port = conf.port
|
|
199
210
|
|
|
200
211
|
// servers is an array but we will always pull the first for consistency
|
|
201
212
|
if (conf.servers && conf.servers.length) {
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const dbutils = require('../db/utils')
|
|
9
|
+
const properties = require('../util/properties')
|
|
10
10
|
|
|
11
11
|
module.exports = function initialize(agent, mysql, moduleName, shim) {
|
|
12
12
|
shim.setDatastore(shim.MYSQL)
|
|
@@ -16,7 +16,7 @@ module.exports = function initialize(agent, mysql, moduleName, shim) {
|
|
|
16
16
|
function wrapCreateConnection(shim, fn, fnName, connection) {
|
|
17
17
|
shim.logger.debug('Wrapping Connection#query')
|
|
18
18
|
if (wrapQueriable(shim, connection, false)) {
|
|
19
|
-
|
|
19
|
+
const connProto = Object.getPrototypeOf(connection)
|
|
20
20
|
shim.setInternalProperty(connProto, '__NR_storeDatabase', true)
|
|
21
21
|
shim.unwrap(mysql, 'createConnection')
|
|
22
22
|
}
|
|
@@ -33,7 +33,7 @@ module.exports = function initialize(agent, mysql, moduleName, shim) {
|
|
|
33
33
|
shim.wrapReturn(mysql, 'createPoolCluster', wrapCreatePoolCluster)
|
|
34
34
|
function wrapCreatePoolCluster(shim, fn, fnName, poolCluster) {
|
|
35
35
|
shim.logger.debug('Wrapping PoolCluster#of')
|
|
36
|
-
|
|
36
|
+
const proto = Object.getPrototypeOf(poolCluster)
|
|
37
37
|
shim.wrapReturn(proto, 'of', wrapPoolClusterOf)
|
|
38
38
|
function wrapPoolClusterOf(shim, of, _n, poolNamespace) {
|
|
39
39
|
if (wrapGetConnection(shim, poolNamespace)) {
|
|
@@ -61,11 +61,11 @@ function wrapGetConnection(shim, connectable) {
|
|
|
61
61
|
return false
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const proto = Object.getPrototypeOf(connectable)
|
|
65
65
|
shim.wrap(proto, 'getConnection', function doWrapGetConnection(shim, fn) {
|
|
66
66
|
return function wrappedGetConnection() {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const args = shim.toArray(arguments)
|
|
68
|
+
const cbIdx = args.length - 1
|
|
69
69
|
|
|
70
70
|
if (shim.isFunction(args[cbIdx]) && !shim.isWrapped(args[cbIdx])) {
|
|
71
71
|
shim.logger.trace(
|
|
@@ -74,7 +74,7 @@ function wrapGetConnection(shim, connectable) {
|
|
|
74
74
|
},
|
|
75
75
|
'Wrapping callback with segment'
|
|
76
76
|
)
|
|
77
|
-
|
|
77
|
+
let cb = args[cbIdx]
|
|
78
78
|
if (!shim.__wrappedPoolConnection) {
|
|
79
79
|
cb = shim.wrap(cb, wrapGetConnectionCallback)
|
|
80
80
|
}
|
|
@@ -119,9 +119,9 @@ function wrapQueriable(shim, queriable, isPoolQuery) {
|
|
|
119
119
|
return false
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
const proto = Object.getPrototypeOf(queriable)
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
let describe
|
|
125
125
|
if (isPoolQuery) {
|
|
126
126
|
describe = describePoolQuery
|
|
127
127
|
} else {
|
|
@@ -139,8 +139,8 @@ function wrapQueriable(shim, queriable, isPoolQuery) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
function extractQueryArgs(shim, args) {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
let query = ''
|
|
143
|
+
let callback = null
|
|
144
144
|
|
|
145
145
|
// Figure out the query parameter.
|
|
146
146
|
if (shim.isString(args[0])) {
|
|
@@ -168,10 +168,10 @@ function extractQueryArgs(shim, args) {
|
|
|
168
168
|
|
|
169
169
|
function describeQuery(shim, queryFn, fnName, args) {
|
|
170
170
|
shim.logger.trace('Recording query')
|
|
171
|
-
|
|
171
|
+
const extractedArgs = extractQueryArgs(shim, args)
|
|
172
172
|
|
|
173
173
|
// Pull out instance attributes.
|
|
174
|
-
|
|
174
|
+
const parameters = getInstanceParameters(shim, this, extractedArgs.query)
|
|
175
175
|
|
|
176
176
|
shim.logger.trace(
|
|
177
177
|
{
|
|
@@ -193,7 +193,7 @@ function describeQuery(shim, queryFn, fnName, args) {
|
|
|
193
193
|
|
|
194
194
|
function describePoolQuery(shim, queryFn, fnName, args) {
|
|
195
195
|
shim.logger.trace('Recording pool query')
|
|
196
|
-
|
|
196
|
+
const extractedArgs = extractQueryArgs(shim, args)
|
|
197
197
|
return {
|
|
198
198
|
stream: true,
|
|
199
199
|
query: null,
|
|
@@ -204,10 +204,10 @@ function describePoolQuery(shim, queryFn, fnName, args) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
function getInstanceParameters(shim, queryable, query) {
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
const parameters = { host: null, port_path_or_id: null, database_name: null }
|
|
208
|
+
let conf = queryable.config
|
|
209
209
|
conf = (conf && conf.connectionConfig) || conf
|
|
210
|
-
|
|
210
|
+
let databaseName = queryable.__NR_databaseName || null
|
|
211
211
|
if (conf) {
|
|
212
212
|
parameters.database_name = databaseName = databaseName || conf.database
|
|
213
213
|
|
|
@@ -229,7 +229,7 @@ function getInstanceParameters(shim, queryable, query) {
|
|
|
229
229
|
|
|
230
230
|
function storeDatabaseName(shim, queryable, query) {
|
|
231
231
|
if (queryable.__NR_storeDatabase) {
|
|
232
|
-
|
|
232
|
+
const databaseName = dbutils.extractDatabaseChangeFromUse(query)
|
|
233
233
|
if (databaseName) {
|
|
234
234
|
shim.setInternalProperty(queryable, '__NR_databaseName', databaseName)
|
|
235
235
|
}
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const logger = require('../logger').child({ component: 'oracle' })
|
|
9
|
+
const shimmer = require('../shimmer')
|
|
10
|
+
const parseSql = require('../db/parse-sql')
|
|
11
|
+
const ORACLE = require('../metrics/names').ORACLE
|
|
12
12
|
|
|
13
13
|
module.exports = function initialize(agent, oracle) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const tracer = agent.tracer
|
|
15
|
+
let wrapped = false
|
|
16
16
|
|
|
17
17
|
logger.trace('wrapping oracle.connect and oracle.connectSync')
|
|
18
18
|
|
|
@@ -31,7 +31,7 @@ module.exports = function initialize(agent, oracle) {
|
|
|
31
31
|
|
|
32
32
|
shimmer.wrapMethod(oracle, 'Oracle', 'connectSync', function wrapSyncConnect(connect) {
|
|
33
33
|
return function wrappedSyncConnect() {
|
|
34
|
-
|
|
34
|
+
const connection = connect.apply(this, arguments)
|
|
35
35
|
ensureConnectionWrapped(connection)
|
|
36
36
|
return connection
|
|
37
37
|
}
|
|
@@ -51,13 +51,13 @@ module.exports = function initialize(agent, oracle) {
|
|
|
51
51
|
return tracer.wrapFunctionNoSegment(connect, 'connect')
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const proto = Object.getPrototypeOf(connection)
|
|
55
55
|
wrapConnectionExecute(proto, tracer)
|
|
56
56
|
wrapConnectionPrepare(proto, tracer)
|
|
57
57
|
|
|
58
58
|
shimmer.wrapMethod(proto, 'Oracle', 'reader', function wrapMethod(createReader) {
|
|
59
59
|
return function wrappedConnect(sql) {
|
|
60
|
-
|
|
60
|
+
const reader = createReader.apply(this, arguments)
|
|
61
61
|
wrapReader(reader, tracer, sql)
|
|
62
62
|
return reader
|
|
63
63
|
}
|
|
@@ -73,9 +73,9 @@ function wrapConnectionExecute(connection, tracer) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function wrappedExecute(segment, args, bind) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
const ps = parseSql(ORACLE.PREFIX, args[0])
|
|
77
|
+
const collection = ps.collection
|
|
78
|
+
const operation = ps.operation
|
|
79
79
|
|
|
80
80
|
segment.name = ORACLE.STATEMENT + collection + '/Connection.execute/' + operation
|
|
81
81
|
logger.trace('capturing oracle query. collection: %s, Operation: %s', collection, operation)
|
|
@@ -87,7 +87,7 @@ function wrapConnectionExecute(connection, tracer) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
function wrapReader(reader, tracer, sql) {
|
|
90
|
-
|
|
90
|
+
const ps = parseSql(ORACLE.PREFIX, sql)
|
|
91
91
|
shimmer.wrapMethod(reader, 'Oracle.Reader', 'nextRow', wrapNextRow)
|
|
92
92
|
shimmer.wrapMethod(reader, 'Oracle.Reader', 'nextRows', wrapNextRows)
|
|
93
93
|
|
|
@@ -113,8 +113,8 @@ function wrapConnectionPrepare(connection, tracer) {
|
|
|
113
113
|
|
|
114
114
|
function wrapPrepare(prepare) {
|
|
115
115
|
return function wrappedPrepare(sql) {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const ps = parseSql(ORACLE.PREFIX, sql)
|
|
117
|
+
const prepared = prepare.apply(this, arguments)
|
|
118
118
|
shimmer.wrapMethod(prepared, 'Oracle', 'execute', wrapExecute)
|
|
119
119
|
return prepared
|
|
120
120
|
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
const semver = require('semver')
|
|
9
9
|
|
|
10
10
|
function getQuery(shim, original, name, args) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const config = args[0]
|
|
12
|
+
let statement
|
|
13
13
|
if (config && (typeof config === 'string' || config instanceof String)) {
|
|
14
14
|
statement = config
|
|
15
15
|
} else if (config && config.text) {
|
|
@@ -98,11 +98,11 @@ module.exports = function initialize(agent, pgsql, moduleName, shim) {
|
|
|
98
98
|
// client. The original getter replaces itself with the instance of the native
|
|
99
99
|
// client, so only instrument if the getter exists (otherwise assume already
|
|
100
100
|
// instrumented).
|
|
101
|
-
|
|
101
|
+
const origGetter = pgsql.__lookupGetter__('native')
|
|
102
102
|
if (origGetter) {
|
|
103
103
|
delete pgsql.native
|
|
104
104
|
pgsql.__defineGetter__('native', function getNative() {
|
|
105
|
-
|
|
105
|
+
const temp = origGetter()
|
|
106
106
|
if (temp != null) {
|
|
107
107
|
instrumentPGNative(temp)
|
|
108
108
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const util = require('util')
|
|
9
|
+
const properties = require('../util/properties')
|
|
10
|
+
const shimmer = require('../shimmer')
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @namespace Library.Spec
|
|
@@ -92,7 +92,7 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
92
92
|
wrapStaticMethods(library, spec.name, spec.$library)
|
|
93
93
|
|
|
94
94
|
// Wrap prototype methods.
|
|
95
|
-
|
|
95
|
+
const Promise = library[spec.constructor]
|
|
96
96
|
wrapPrototype(Promise.prototype)
|
|
97
97
|
wrapStaticMethods(Promise, spec.constructor, spec.$static)
|
|
98
98
|
|
|
@@ -114,7 +114,7 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
114
114
|
})
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
const passThrough = spec.$static && spec.$static.$passThrough
|
|
118
118
|
if (passThrough) {
|
|
119
119
|
passThrough.forEach(function assignProxy(proxyProp) {
|
|
120
120
|
if (!properties.hasOwn(wrappedPromise, proxyProp)) {
|
|
@@ -144,8 +144,8 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
144
144
|
return Promise(executor) // eslint-disable-line new-cap
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
const parent = agent.tracer.segment
|
|
148
|
+
let promise = null
|
|
149
149
|
if (
|
|
150
150
|
!parent ||
|
|
151
151
|
!parent.transaction.isActive() ||
|
|
@@ -155,19 +155,19 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
155
155
|
// We are expecting one function argument for executor, anything else is
|
|
156
156
|
// non-standard, do not attempt to wrap. Also do not attempt to wrap if we
|
|
157
157
|
// are not in a transaction.
|
|
158
|
-
|
|
158
|
+
const cnstrctArgs = agent.tracer.slice(arguments)
|
|
159
159
|
cnstrctArgs.unshift(Promise) // `unshift` === `push_front`
|
|
160
160
|
promise = new (Promise.bind.apply(Promise, cnstrctArgs))()
|
|
161
161
|
} else {
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const segmentName = 'Promise ' + (executor.name || '<anonymous>')
|
|
163
|
+
const context = {
|
|
164
164
|
promise: null,
|
|
165
165
|
self: null,
|
|
166
166
|
args: null
|
|
167
167
|
}
|
|
168
168
|
promise = new Promise(wrapExecutorContext(context))
|
|
169
169
|
context.promise = promise
|
|
170
|
-
|
|
170
|
+
const segment = _createSegment(segmentName)
|
|
171
171
|
Contextualizer.link(null, promise, segment, spec.useFinally)
|
|
172
172
|
|
|
173
173
|
agent.tracer.segment = segment
|
|
@@ -221,24 +221,24 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
221
221
|
|
|
222
222
|
function wrapExecutorCaller(caller) {
|
|
223
223
|
return function wrappedExecutorCaller(executor) {
|
|
224
|
-
|
|
224
|
+
const parent = agent.tracer.getSegment()
|
|
225
225
|
if (!(this instanceof Promise) || !parent || !parent.transaction.isActive()) {
|
|
226
226
|
return caller.apply(this, arguments)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
const context = {
|
|
230
230
|
promise: this,
|
|
231
231
|
self: null,
|
|
232
232
|
args: null
|
|
233
233
|
}
|
|
234
234
|
if (!this.__NR_context) {
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
const segmentName = 'Promise ' + executor.name || '<anonymous>'
|
|
236
|
+
const segment = _createSegment(segmentName)
|
|
237
237
|
Contextualizer.link(null, this, segment, spec.useFinally)
|
|
238
238
|
}
|
|
239
|
-
|
|
239
|
+
const args = [].slice.call(arguments)
|
|
240
240
|
args[0] = wrapExecutorContext(context, this.__NR_context.getSegment())
|
|
241
|
-
|
|
241
|
+
const ret = caller.apply(this, args)
|
|
242
242
|
|
|
243
243
|
// Bluebird catches executor errors and auto-rejects when it catches them,
|
|
244
244
|
// thus we need to do so as well.
|
|
@@ -274,7 +274,7 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
274
274
|
|
|
275
275
|
function wrapResolver(context, fn) {
|
|
276
276
|
return function wrappedResolveReject(val) {
|
|
277
|
-
|
|
277
|
+
const promise = context.promise
|
|
278
278
|
if (promise && promise.__NR_context) {
|
|
279
279
|
promise.__NR_context.getSegment().touch()
|
|
280
280
|
}
|
|
@@ -323,14 +323,14 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
323
323
|
return then.apply(this, arguments)
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
326
|
+
const segmentNamePrefix = 'Promise#' + name + ' '
|
|
327
|
+
const thenSegment = agent.tracer.getSegment()
|
|
328
|
+
const promise = this
|
|
329
329
|
|
|
330
330
|
// Wrap up the arguments and execute the real then.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
let isWrapped = false
|
|
332
|
+
const args = [].map.call(arguments, wrapHandler)
|
|
333
|
+
const next = then.apply(this, args)
|
|
334
334
|
|
|
335
335
|
// If we got a promise (which we should have), link the parent's context.
|
|
336
336
|
if (!isWrapped && next instanceof Promise && next !== promise) {
|
|
@@ -353,15 +353,15 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
353
353
|
return fn.apply(this, arguments)
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
356
|
+
let promSegment = next.__NR_context.getSegment()
|
|
357
|
+
const segmentName = segmentNamePrefix + (fn.name || '<anonymous>')
|
|
358
|
+
const segment = _createSegment(segmentName, promSegment)
|
|
359
359
|
if (segment && segment !== promSegment) {
|
|
360
360
|
next.__NR_context.setSegment(segment)
|
|
361
361
|
promSegment = segment
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
-
|
|
364
|
+
let ret = null
|
|
365
365
|
try {
|
|
366
366
|
ret = agent.tracer.bindFunction(fn, promSegment, true).apply(this, arguments)
|
|
367
367
|
} finally {
|
|
@@ -383,10 +383,10 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
383
383
|
return cast
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
|
|
386
|
+
const CAST_SEGMENT_NAME = 'Promise.' + name
|
|
387
387
|
return function __NR_wrappedCast() {
|
|
388
|
-
|
|
389
|
-
|
|
388
|
+
const segment = _createSegment(CAST_SEGMENT_NAME)
|
|
389
|
+
const prom = cast.apply(this, arguments)
|
|
390
390
|
if (segment) {
|
|
391
391
|
Contextualizer.link(null, prom, segment, spec.useFinally)
|
|
392
392
|
}
|
|
@@ -399,9 +399,9 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
399
399
|
return promisify
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
|
|
402
|
+
const WRAP_SEGMENT_NAME = 'Promise.' + name
|
|
403
403
|
return function __NR_wrappedPromisify() {
|
|
404
|
-
|
|
404
|
+
const promisified = promisify.apply(this, arguments)
|
|
405
405
|
if (typeof promisified !== 'function') {
|
|
406
406
|
return promisified
|
|
407
407
|
}
|
|
@@ -412,8 +412,8 @@ module.exports = function initialize(agent, library, spec) {
|
|
|
412
412
|
|
|
413
413
|
return __NR_wrappedPromisified
|
|
414
414
|
function __NR_wrappedPromisified() {
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
const segment = _createSegment(WRAP_SEGMENT_NAME)
|
|
416
|
+
const prom = agent.tracer.bindFunction(promisified, segment, true).apply(this, arguments)
|
|
417
417
|
|
|
418
418
|
if (segment) {
|
|
419
419
|
Contextualizer.link(null, prom, segment, spec.useFinally)
|
|
@@ -466,7 +466,7 @@ function Contextualizer(idx, context, useFinally) {
|
|
|
466
466
|
module.exports.Contextualizer = Contextualizer
|
|
467
467
|
|
|
468
468
|
Contextualizer.link = function link(prev, next, segment, useFinally) {
|
|
469
|
-
|
|
469
|
+
let ctxlzr = prev && prev.__NR_context
|
|
470
470
|
if (ctxlzr && !ctxlzr.isActive()) {
|
|
471
471
|
ctxlzr = prev.__NR_context = null
|
|
472
472
|
}
|
|
@@ -489,9 +489,9 @@ Contextualizer.link = function link(prev, next, segment, useFinally) {
|
|
|
489
489
|
//
|
|
490
490
|
// Note: This does not account for branches of branches. That may result
|
|
491
491
|
// in improperly parented segments.
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
492
|
+
let parent = ctxlzr
|
|
493
|
+
let child = ctxlzr.child
|
|
494
|
+
const branchIdx = ctxlzr.context.branch()
|
|
495
495
|
do {
|
|
496
496
|
child.parentIdx = parent.idx
|
|
497
497
|
child.idx = branchIdx
|
|
@@ -507,7 +507,7 @@ Contextualizer.link = function link(prev, next, segment, useFinally) {
|
|
|
507
507
|
|
|
508
508
|
// If this is a branching link then create a new branch for the next promise.
|
|
509
509
|
// Otherwise, we can just piggy-back on the previous link's spot.
|
|
510
|
-
|
|
510
|
+
const idx = ctxlzr.child === false ? ctxlzr.context.branch() : ctxlzr.idx
|
|
511
511
|
|
|
512
512
|
// Create a new context for this next promise.
|
|
513
513
|
next.__NR_context = new Contextualizer(idx, ctxlzr.context, ctxlzr.useFinally)
|
|
@@ -527,14 +527,14 @@ Contextualizer.link = function link(prev, next, segment, useFinally) {
|
|
|
527
527
|
Contextualizer.prototype = Object.create(null)
|
|
528
528
|
|
|
529
529
|
Contextualizer.prototype.isActive = function isActive() {
|
|
530
|
-
|
|
531
|
-
|
|
530
|
+
const segments = this.context.segments
|
|
531
|
+
const segment = segments[this.idx] || segments[this.parentIdx] || segments[0]
|
|
532
532
|
return segment && segment.transaction.isActive()
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
Contextualizer.prototype.getSegment = function getSegment() {
|
|
536
|
-
|
|
537
|
-
|
|
536
|
+
const segments = this.context.segments
|
|
537
|
+
let segment = segments[this.idx]
|
|
538
538
|
if (segment == null) {
|
|
539
539
|
segment = segments[this.idx] = segments[this.parentIdx] || segments[0]
|
|
540
540
|
}
|
|
@@ -550,8 +550,8 @@ Contextualizer.prototype.toJSON = function toJSON() {
|
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
Contextualizer.prototype.continue = function continueContext(prom) {
|
|
553
|
-
|
|
554
|
-
|
|
553
|
+
const self = this
|
|
554
|
+
const nextContext = prom.__NR_context
|
|
555
555
|
if (!nextContext) {
|
|
556
556
|
return prom
|
|
557
557
|
}
|
package/lib/instrumentation/q.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const wrap = require('../shimmer').wrapMethod
|
|
9
9
|
|
|
10
10
|
module.exports = initialize
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ function initialize(agent, Q) {
|
|
|
17
17
|
if (Q.nextTick) {
|
|
18
18
|
// The wrap() call for nextTick wipes the sub-function. Save a reference
|
|
19
19
|
// now so it can be restored later
|
|
20
|
-
|
|
20
|
+
const savedRunAfter = Q.nextTick.runAfter
|
|
21
21
|
|
|
22
22
|
wrap(Q, 'Q', 'nextTick', wrapUninstrumented)
|
|
23
23
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const hasOwnProperty = require('../util/properties').hasOwn
|
|
9
|
+
const stringify = require('json-stringify-safe')
|
|
10
10
|
|
|
11
11
|
module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
12
|
-
|
|
12
|
+
const proto = redis && redis.RedisClient && redis.RedisClient.prototype
|
|
13
13
|
if (!proto) {
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
@@ -20,9 +20,9 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
20
20
|
proto,
|
|
21
21
|
'internal_send_command',
|
|
22
22
|
function wrapInternalSendCommand(shim, _, __, args) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const commandObject = args[0]
|
|
24
|
+
const keys = commandObject.args
|
|
25
|
+
const parameters = getInstanceParameters(this)
|
|
26
26
|
|
|
27
27
|
if (keys && keys.length > 0) {
|
|
28
28
|
try {
|
|
@@ -40,7 +40,7 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
40
40
|
if (shim.isFunction(commandObject.callback)) {
|
|
41
41
|
shim.bindCallbackSegment(commandObject, 'callback', segment)
|
|
42
42
|
} else {
|
|
43
|
-
|
|
43
|
+
const self = this
|
|
44
44
|
commandObject.callback = shim.bindSegment(
|
|
45
45
|
function NRCallback(err) {
|
|
46
46
|
if (err && self.emit instanceof Function) {
|
|
@@ -58,8 +58,8 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
58
58
|
} else {
|
|
59
59
|
// For redis versions <2.6.1
|
|
60
60
|
shim.recordOperation(proto, 'send_command', function wrapSendCommand(shim, _, __, args) {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const keys = args[1]
|
|
62
|
+
const parameters = getInstanceParameters(this)
|
|
63
63
|
|
|
64
64
|
if (keys && !shim.isFunction(keys)) {
|
|
65
65
|
try {
|
|
@@ -74,7 +74,7 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
74
74
|
name: args[0] || 'other',
|
|
75
75
|
parameters: parameters,
|
|
76
76
|
callback: function bindCallback(shim, _f, _n, segment) {
|
|
77
|
-
|
|
77
|
+
const last = args[args.length - 1]
|
|
78
78
|
if (shim.isFunction(last)) {
|
|
79
79
|
shim.bindCallbackSegment(args, shim.LAST, segment)
|
|
80
80
|
} else if (shim.isArray(last) && shim.isFunction(last[last.length - 1])) {
|
|
@@ -108,7 +108,7 @@ module.exports = function initialize(agent, redis, moduleName, shim) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function doCapture(opts) {
|
|
111
|
-
|
|
111
|
+
const db = (hasOwnProperty(client, 'selected_db') ? client.selected_db : opts.db) || 0
|
|
112
112
|
|
|
113
113
|
return {
|
|
114
114
|
host: opts.host || 'localhost',
|
|
@@ -47,7 +47,7 @@ module.exports = function initialize(agent, restify, moduleName, shim) {
|
|
|
47
47
|
|
|
48
48
|
function wrapServer(serverProto) {
|
|
49
49
|
// These are all the methods for mounting routed middleware.
|
|
50
|
-
|
|
50
|
+
const routings = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch']
|
|
51
51
|
shim.wrapMiddlewareMounter(serverProto, routings, {
|
|
52
52
|
route: shim.FIRST,
|
|
53
53
|
endpoint: shim.LAST,
|