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.
Files changed (134) hide show
  1. package/NEWS.md +76 -0
  2. package/README.md +7 -6
  3. package/THIRD_PARTY_NOTICES.md +95 -35
  4. package/api.js +74 -68
  5. package/bin/test-naming-rules.js +22 -22
  6. package/lib/agent.js +4 -4
  7. package/lib/attributes.js +2 -2
  8. package/lib/collector/api.js +12 -12
  9. package/lib/collector/facts.js +1 -1
  10. package/lib/collector/http-agents.js +12 -11
  11. package/lib/collector/key-parser.js +1 -1
  12. package/lib/collector/remote-method.js +27 -26
  13. package/lib/config/attribute-filter.js +23 -23
  14. package/lib/config/default.js +12 -10
  15. package/lib/config/hsm.js +1 -1
  16. package/lib/config/index.js +82 -66
  17. package/lib/config/lasp.js +3 -3
  18. package/lib/config/merge-server-config.js +1 -1
  19. package/lib/db/parse-sql.js +8 -8
  20. package/lib/db/parsed-statement.js +9 -8
  21. package/lib/db/query-parsers/sql.js +7 -7
  22. package/lib/db/query-sample.js +9 -9
  23. package/lib/db/query-trace-aggregator.js +4 -4
  24. package/lib/db/statement-matcher.js +5 -5
  25. package/lib/db/utils.js +1 -1
  26. package/lib/environment.js +43 -43
  27. package/lib/errors/error-collector.js +2 -2
  28. package/lib/errors/error-trace-aggregator.js +1 -1
  29. package/lib/errors/helper.js +3 -3
  30. package/lib/errors/index.js +17 -17
  31. package/lib/feature_flags.js +7 -5
  32. package/lib/header-attributes.js +6 -6
  33. package/lib/header-processing.js +1 -1
  34. package/lib/instrumentation/amqplib.js +26 -26
  35. package/lib/instrumentation/bluebird.js +3 -3
  36. package/lib/instrumentation/cassandra-driver.js +7 -3
  37. package/lib/instrumentation/connect.js +4 -4
  38. package/lib/instrumentation/core/async_hooks.js +6 -6
  39. package/lib/instrumentation/core/domain.js +2 -2
  40. package/lib/instrumentation/core/globals.js +1 -1
  41. package/lib/instrumentation/core/http-outbound.js +15 -84
  42. package/lib/instrumentation/core/http.js +34 -67
  43. package/lib/instrumentation/core/inspector.js +2 -2
  44. package/lib/instrumentation/core/timers.js +7 -7
  45. package/lib/instrumentation/core/zlib.js +2 -2
  46. package/lib/instrumentation/director.js +4 -4
  47. package/lib/instrumentation/express.js +8 -8
  48. package/lib/instrumentation/fastify/spec-builders.js +57 -47
  49. package/lib/instrumentation/fastify.js +85 -24
  50. package/lib/instrumentation/generic-pool.js +1 -1
  51. package/lib/instrumentation/hapi/hapi-17.js +11 -11
  52. package/lib/instrumentation/hapi/shared.js +1 -1
  53. package/lib/instrumentation/hapi.js +22 -22
  54. package/lib/instrumentation/ioredis.js +7 -7
  55. package/lib/instrumentation/memcached.js +7 -7
  56. package/lib/instrumentation/mongodb/common.js +16 -5
  57. package/lib/instrumentation/mysql.js +19 -19
  58. package/lib/instrumentation/oracle.js +15 -15
  59. package/lib/instrumentation/pg.js +4 -4
  60. package/lib/instrumentation/promise.js +46 -46
  61. package/lib/instrumentation/q.js +2 -2
  62. package/lib/instrumentation/redis.js +11 -11
  63. package/lib/instrumentation/restify.js +1 -1
  64. package/lib/instrumentation/undici.js +242 -0
  65. package/lib/instrumentation/vision.js +4 -4
  66. package/lib/instrumentation/when.js +3 -3
  67. package/lib/instrumentations.js +2 -1
  68. package/lib/logger.js +5 -5
  69. package/lib/metrics/index.js +15 -15
  70. package/lib/metrics/mapper.js +7 -7
  71. package/lib/metrics/normalizer/rule.js +9 -9
  72. package/lib/metrics/normalizer/tx_segment.js +17 -17
  73. package/lib/metrics/normalizer.js +22 -22
  74. package/lib/metrics/recorders/custom.js +5 -5
  75. package/lib/metrics/recorders/generic.js +3 -3
  76. package/lib/metrics/recorders/http.js +7 -7
  77. package/lib/metrics/recorders/http_external.js +7 -7
  78. package/lib/metrics/recorders/message-transaction.js +5 -6
  79. package/lib/metrics/recorders/other.js +5 -5
  80. package/lib/parse-proc-cpuinfo.js +25 -19
  81. package/lib/parse-proc-meminfo.js +8 -2
  82. package/lib/prioritized-attributes.js +2 -2
  83. package/lib/priority-queue.js +10 -10
  84. package/lib/reservoir.js +3 -3
  85. package/lib/sampler.js +26 -26
  86. package/lib/serverless/aws-lambda.js +8 -2
  87. package/lib/shim/datastore-shim.js +35 -32
  88. package/lib/shim/index.js +2 -2
  89. package/lib/shim/message-shim.js +47 -47
  90. package/lib/shim/promise-shim.js +1 -1
  91. package/lib/shim/shim.js +61 -61
  92. package/lib/shim/specs/index.js +3 -3
  93. package/lib/shim/transaction-shim.js +44 -192
  94. package/lib/shim/webframework-shim.js +52 -52
  95. package/lib/spans/span-event.js +1 -1
  96. package/lib/spans/streaming-span-attributes.js +1 -1
  97. package/lib/stats/apdex.js +2 -2
  98. package/lib/stats/index.js +2 -2
  99. package/lib/system-info.js +23 -23
  100. package/lib/timer.js +5 -5
  101. package/lib/transaction/dt-payload.js +1 -1
  102. package/lib/transaction/index.js +40 -40
  103. package/lib/transaction/name-state.js +14 -14
  104. package/lib/transaction/trace/exclusive-time-calculator.js +6 -6
  105. package/lib/transaction/trace/index.js +14 -14
  106. package/lib/transaction/trace/segment.js +18 -18
  107. package/lib/transaction/tracecontext.js +1 -1
  108. package/lib/transaction/tracer/index.js +53 -49
  109. package/lib/uninstrumented.js +7 -7
  110. package/lib/util/arity.js +2 -2
  111. package/lib/util/byte-limit.js +4 -4
  112. package/lib/util/cat.js +269 -24
  113. package/lib/util/codec.js +2 -2
  114. package/lib/util/copy.js +2 -2
  115. package/lib/util/deep-equal.js +10 -10
  116. package/lib/util/flatten.js +4 -4
  117. package/lib/util/hashes.js +14 -14
  118. package/lib/util/label-parser.js +17 -17
  119. package/lib/util/logger.js +24 -24
  120. package/lib/util/process-version.js +2 -2
  121. package/lib/util/properties.js +4 -4
  122. package/lib/util/sql/obfuscate.js +15 -15
  123. package/lib/util/stream-sink.js +3 -3
  124. package/lib/util/unwrapped-core.js +2 -2
  125. package/lib/util/urltils.js +16 -16
  126. package/lib/utilization/aws-info.js +7 -7
  127. package/lib/utilization/azure-info.js +6 -6
  128. package/lib/utilization/common.js +13 -13
  129. package/lib/utilization/docker-info.js +11 -11
  130. package/lib/utilization/gcp-info.js +4 -4
  131. package/lib/utilization/index.js +5 -5
  132. package/lib/utilization/pcf-info.js +9 -9
  133. package/package.json +13 -6
  134. 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 {Object} params
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 {Object} client mongo client instance
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
- let [{ host, port, socketPath }] = obj.s.db.s.client.s.options.hosts
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
- let host = null
198
- let port = null
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
- var dbutils = require('../db/utils')
9
- var properties = require('../util/properties')
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
- var connProto = Object.getPrototypeOf(connection)
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
- var proto = Object.getPrototypeOf(poolCluster)
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
- var proto = Object.getPrototypeOf(connectable)
64
+ const proto = Object.getPrototypeOf(connectable)
65
65
  shim.wrap(proto, 'getConnection', function doWrapGetConnection(shim, fn) {
66
66
  return function wrappedGetConnection() {
67
- var args = shim.toArray(arguments)
68
- var cbIdx = args.length - 1
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
- var cb = args[cbIdx]
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
- var proto = Object.getPrototypeOf(queriable)
122
+ const proto = Object.getPrototypeOf(queriable)
123
123
 
124
- var describe
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
- var query = ''
143
- var callback = null
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
- var extractedArgs = extractQueryArgs(shim, args)
171
+ const extractedArgs = extractQueryArgs(shim, args)
172
172
 
173
173
  // Pull out instance attributes.
174
- var parameters = getInstanceParameters(shim, this, extractedArgs.query)
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
- var extractedArgs = extractQueryArgs(shim, args)
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
- var parameters = { host: null, port_path_or_id: null, database_name: null }
208
- var conf = queryable.config
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
- var databaseName = queryable.__NR_databaseName || null
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
- var databaseName = dbutils.extractDatabaseChangeFromUse(query)
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
- var logger = require('../logger').child({ component: 'oracle' })
9
- var shimmer = require('../shimmer')
10
- var parseSql = require('../db/parse-sql')
11
- var ORACLE = require('../metrics/names').ORACLE
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
- var tracer = agent.tracer
15
- var wrapped = false
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
- var connection = connect.apply(this, arguments)
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
- var proto = Object.getPrototypeOf(connection)
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
- var reader = createReader.apply(this, arguments)
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
- var ps = parseSql(ORACLE.PREFIX, args[0])
77
- var collection = ps.collection
78
- var operation = ps.operation
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
- var ps = parseSql(ORACLE.PREFIX, sql)
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
- var ps = parseSql(ORACLE.PREFIX, sql)
117
- var prepared = prepare.apply(this, arguments)
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
- var config = args[0]
12
- var statement
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
- var origGetter = pgsql.__lookupGetter__('native')
101
+ const origGetter = pgsql.__lookupGetter__('native')
102
102
  if (origGetter) {
103
103
  delete pgsql.native
104
104
  pgsql.__defineGetter__('native', function getNative() {
105
- var temp = origGetter()
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
- var util = require('util')
9
- var properties = require('../util/properties')
10
- var shimmer = require('../shimmer')
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
- var Promise = library[spec.constructor]
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
- var passThrough = spec.$static && spec.$static.$passThrough
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
- var parent = agent.tracer.segment
148
- var promise = null
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
- var cnstrctArgs = agent.tracer.slice(arguments)
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
- var segmentName = 'Promise ' + (executor.name || '<anonymous>')
163
- var context = {
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
- var segment = _createSegment(segmentName)
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
- var parent = agent.tracer.getSegment()
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
- var context = {
229
+ const context = {
230
230
  promise: this,
231
231
  self: null,
232
232
  args: null
233
233
  }
234
234
  if (!this.__NR_context) {
235
- var segmentName = 'Promise ' + executor.name || '<anonymous>'
236
- var segment = _createSegment(segmentName)
235
+ const segmentName = 'Promise ' + executor.name || '<anonymous>'
236
+ const segment = _createSegment(segmentName)
237
237
  Contextualizer.link(null, this, segment, spec.useFinally)
238
238
  }
239
- var args = [].slice.call(arguments)
239
+ const args = [].slice.call(arguments)
240
240
  args[0] = wrapExecutorContext(context, this.__NR_context.getSegment())
241
- var ret = caller.apply(this, args)
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
- var promise = context.promise
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
- var segmentNamePrefix = 'Promise#' + name + ' '
327
- var thenSegment = agent.tracer.getSegment()
328
- var promise = this
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
- var isWrapped = false
332
- var args = [].map.call(arguments, wrapHandler)
333
- var next = then.apply(this, args)
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
- var promSegment = next.__NR_context.getSegment()
357
- var segmentName = segmentNamePrefix + (fn.name || '<anonymous>')
358
- var segment = _createSegment(segmentName, promSegment)
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
- var ret = null
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
- var CAST_SEGMENT_NAME = 'Promise.' + name
386
+ const CAST_SEGMENT_NAME = 'Promise.' + name
387
387
  return function __NR_wrappedCast() {
388
- var segment = _createSegment(CAST_SEGMENT_NAME)
389
- var prom = cast.apply(this, arguments)
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
- var WRAP_SEGMENT_NAME = 'Promise.' + name
402
+ const WRAP_SEGMENT_NAME = 'Promise.' + name
403
403
  return function __NR_wrappedPromisify() {
404
- var promisified = promisify.apply(this, arguments)
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
- var segment = _createSegment(WRAP_SEGMENT_NAME)
416
- var prom = agent.tracer.bindFunction(promisified, segment, true).apply(this, arguments)
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
- var ctxlzr = prev && prev.__NR_context
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
- var parent = ctxlzr
493
- var child = ctxlzr.child
494
- var branchIdx = ctxlzr.context.branch()
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
- var idx = ctxlzr.child === false ? ctxlzr.context.branch() : ctxlzr.idx
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
- var segments = this.context.segments
531
- var segment = segments[this.idx] || segments[this.parentIdx] || segments[0]
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
- var segments = this.context.segments
537
- var segment = segments[this.idx]
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
- var self = this
554
- var nextContext = prom.__NR_context
553
+ const self = this
554
+ const nextContext = prom.__NR_context
555
555
  if (!nextContext) {
556
556
  return prom
557
557
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var wrap = require('../shimmer').wrapMethod
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
- var savedRunAfter = Q.nextTick.runAfter
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
- var hasOwnProperty = require('../util/properties').hasOwn
9
- var stringify = require('json-stringify-safe')
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
- var proto = redis && redis.RedisClient && redis.RedisClient.prototype
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
- var commandObject = args[0]
24
- var keys = commandObject.args
25
- var parameters = getInstanceParameters(this)
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
- var self = this
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
- var keys = args[1]
62
- var parameters = getInstanceParameters(this)
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
- var last = args[args.length - 1]
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
- var db = (hasOwnProperty(client, 'selected_db') ? client.selected_db : opts.db) || 0
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
- var routings = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch']
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,