newrelic 9.5.0 → 9.7.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.
Files changed (104) hide show
  1. package/NEWS.md +14 -0
  2. package/api.js +2 -0
  3. package/bin/test-naming-rules.js +1 -1
  4. package/esm-loader.mjs +1 -3
  5. package/index.js +6 -5
  6. package/lib/adaptive-sampler.js +1 -2
  7. package/lib/agent.js +2 -0
  8. package/lib/aggregators/event-aggregator.js +2 -2
  9. package/lib/attributes.js +2 -4
  10. package/lib/collector/api.js +20 -12
  11. package/lib/collector/facts.js +1 -3
  12. package/lib/collector/parse-response.js +3 -1
  13. package/lib/collector/remote-method.js +10 -10
  14. package/lib/config/attribute-filter.js +14 -16
  15. package/lib/config/default.js +544 -286
  16. package/lib/config/formatters.js +108 -0
  17. package/lib/config/harvest-config-validator.js +3 -5
  18. package/lib/config/index.js +74 -93
  19. package/lib/environment.js +6 -5
  20. package/lib/errors/error-collector.js +6 -3
  21. package/lib/errors/helper.js +10 -18
  22. package/lib/errors/index.js +12 -6
  23. package/lib/grpc/connection.js +12 -5
  24. package/lib/header-attributes.js +4 -2
  25. package/lib/header-processing.js +2 -2
  26. package/lib/instrumentation/@hapi/hapi.js +231 -1
  27. package/lib/instrumentation/{vision.js → @hapi/vision.js} +0 -0
  28. package/lib/instrumentation/@node-redis/client.js +2 -0
  29. package/lib/instrumentation/amqplib.js +2 -0
  30. package/lib/instrumentation/core/async_hooks.js +3 -4
  31. package/lib/instrumentation/core/globals.js +12 -10
  32. package/lib/instrumentation/core/http-outbound.js +17 -17
  33. package/lib/instrumentation/core/http.js +16 -27
  34. package/lib/instrumentation/core/timers.js +5 -1
  35. package/lib/instrumentation/fastify.js +1 -3
  36. package/lib/instrumentation/grpc-js/grpc.js +14 -3
  37. package/lib/instrumentation/memcached.js +5 -0
  38. package/lib/instrumentation/mongodb/common.js +3 -0
  39. package/lib/instrumentation/mongodb/v2-mongo.js +6 -3
  40. package/lib/instrumentation/mongodb.js +1 -1
  41. package/lib/instrumentation/mysql/mysql.js +6 -5
  42. package/lib/instrumentation/nr-winston-transport.js +3 -4
  43. package/lib/instrumentation/promise.js +22 -18
  44. package/lib/instrumentation/redis.js +2 -0
  45. package/lib/instrumentation/undici.js +12 -15
  46. package/lib/instrumentations.js +1 -1
  47. package/lib/metrics/mapper.js +2 -3
  48. package/lib/metrics/metric-aggregator.js +1 -3
  49. package/lib/metrics/names.js +19 -15
  50. package/lib/metrics/normalizer/rule.js +6 -7
  51. package/lib/metrics/normalizer/tx_segment.js +3 -2
  52. package/lib/metrics/normalizer.js +5 -3
  53. package/lib/parse-proc-cpuinfo.js +11 -6
  54. package/lib/serverless/api-gateway.js +3 -4
  55. package/lib/serverless/aws-lambda.js +3 -3
  56. package/lib/shim/conglomerate-shim.js +2 -3
  57. package/lib/shim/constants.js +1 -16
  58. package/lib/shim/datastore-shim.js +24 -105
  59. package/lib/shim/index.js +7 -0
  60. package/lib/shim/message-shim.js +2 -0
  61. package/lib/shim/promise-shim.js +66 -59
  62. package/lib/shim/shim.js +44 -89
  63. package/lib/shim/transaction-shim.js +1 -1
  64. package/lib/shim/webframework-shim.js +4 -8
  65. package/lib/shimmer.js +29 -23
  66. package/lib/spans/map-to-streaming-type.js +0 -2
  67. package/lib/spans/span-context.js +2 -0
  68. package/lib/spans/span-event-aggregator.js +2 -2
  69. package/lib/spans/span-event.js +2 -2
  70. package/lib/spans/span-streamer.js +4 -0
  71. package/lib/spans/streaming-span-event-aggregator.js +2 -4
  72. package/lib/spans/streaming-span-event.js +3 -2
  73. package/lib/symbols.js +26 -0
  74. package/lib/system-info.js +4 -7
  75. package/lib/timer.js +8 -6
  76. package/lib/transaction/dt-payload.js +4 -3
  77. package/lib/transaction/handle.js +12 -2
  78. package/lib/transaction/index.js +19 -18
  79. package/lib/transaction/name-state.js +17 -2
  80. package/lib/transaction/trace/aggregator.js +4 -12
  81. package/lib/transaction/trace/index.js +7 -5
  82. package/lib/transaction/trace/segment.js +6 -11
  83. package/lib/transaction/tracecontext.js +10 -6
  84. package/lib/transaction/tracer/index.js +35 -43
  85. package/lib/transaction/transaction-event-aggregator.js +1 -3
  86. package/lib/util/arity.js +4 -9
  87. package/lib/util/attribute-types.js +1 -2
  88. package/lib/util/byte-limit.js +1 -3
  89. package/lib/util/cat.js +16 -13
  90. package/lib/util/codec.js +0 -2
  91. package/lib/util/copy.js +1 -2
  92. package/lib/util/deep-equal.js +7 -0
  93. package/lib/util/flatten.js +4 -6
  94. package/lib/util/hashes.js +1 -3
  95. package/lib/util/process-version.js +2 -3
  96. package/lib/util/properties.js +2 -51
  97. package/lib/util/stream-sink.js +2 -0
  98. package/lib/util/urltils.js +4 -10
  99. package/newrelic.js +1 -1
  100. package/package.json +2 -1
  101. package/lib/config/env.js +0 -294
  102. package/lib/instrumentation/hapi/hapi.js +0 -207
  103. package/lib/instrumentation/hapi/shared.js +0 -28
  104. package/lib/instrumentation/hapi.js +0 -254
@@ -5,13 +5,16 @@
5
5
 
6
6
  'use strict'
7
7
 
8
+ /* eslint sonarjs/cognitive-complexity: ["error", 30] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
9
+
8
10
  const logger = require('../logger').child({ component: 'PromiseShim' })
9
11
  const Shim = require('./shim')
12
+ const symbols = require('../symbols')
10
13
 
11
14
  /**
12
15
  * A helper class for wrapping promise modules.
13
16
  *
14
- * @extends Shim
17
+ * @augments Shim
15
18
  */
16
19
  /* eslint-disable camelcase */
17
20
  class PromiseShim extends Shim {
@@ -21,13 +24,10 @@ class PromiseShim extends Shim {
21
24
  *
22
25
  * @param {Agent} agent
23
26
  * The agent this shim will use.
24
- *
25
27
  * @param {string} moduleName
26
28
  * The name of the module being instrumented.
27
- *
28
29
  * @param {string} resolvedName
29
30
  * The full path to the loaded module.
30
- *
31
31
  * @see Shim
32
32
  */
33
33
  constructor(agent, moduleName, resolvedName) {
@@ -49,7 +49,7 @@ class PromiseShim extends Shim {
49
49
  /**
50
50
  * Sets the class used to identify promises from the wrapped promise library.
51
51
  *
52
- * @param {function} clss - The promise library's class.
52
+ * @param {Function} clss - The promise library's class.
53
53
  */
54
54
  setClass(clss) {
55
55
  this._class = clss
@@ -60,10 +60,8 @@ class PromiseShim extends Shim {
60
60
  * library being wrapped.
61
61
  *
62
62
  * @param {*} obj - The object to check the instance type of.
63
- *
64
- * @return {bool} True if the provided object is an instance of a promise from
63
+ * @returns {bool} True if the provided object is an instance of a promise from
65
64
  * this promise library.
66
- *
67
65
  * @see PromiseShim#setClass
68
66
  */
69
67
  isPromiseInstance(obj) {
@@ -82,16 +80,13 @@ class PromiseShim extends Shim {
82
80
  * better to wrap that using {@link PromiseShim#wrapExecutorCaller} than to
83
81
  * use this method.
84
82
  *
85
- * @param {object|function} nodule
83
+ * @param {object | Function} nodule
86
84
  * The source of the properties to wrap, or a single function to wrap.
87
- *
88
- * @param {string|array.<string>} [properties]
85
+ * @param {string | Array.<string>} [properties]
89
86
  * One or more properties to wrap. If omitted, the `nodule` parameter is
90
87
  * assumed to be the constructor to wrap.
91
- *
92
- * @return {object|function} The first parameter to this function, after
88
+ * @returns {object | Function} The first parameter to this function, after
93
89
  * wrapping it or its properties.
94
- *
95
90
  * @see PromiseShim#wrapExecutorCaller
96
91
  */
97
92
  wrapConstructor(nodule, properties) {
@@ -108,7 +103,7 @@ class PromiseShim extends Shim {
108
103
  post: function postPromise(shim, Promise, name, args) {
109
104
  // This extra property is added by `_wrapExecutorContext` in the pre step.
110
105
  const executor = args[0]
111
- const context = executor && executor.__NR_executorContext
106
+ const context = executor && executor[symbols.executorContext]
112
107
  if (!context || !shim.isFunction(context.executor)) {
113
108
  return
114
109
  }
@@ -135,16 +130,13 @@ class PromiseShim extends Shim {
135
130
  * Wrapping the executor caller method directly is preferable to wrapping
136
131
  * the constructor of the promise class.
137
132
  *
138
- * @param {object|function} nodule
133
+ * @param {object | Function} nodule
139
134
  * The source of the properties to wrap, or a single function to wrap.
140
- *
141
- * @param {string|array.<string>} [properties]
135
+ * @param {string | Array.<string>} [properties]
142
136
  * One or more properties to wrap. If omitted, the `nodule` parameter is
143
137
  * assumed to be the function to wrap.
144
- *
145
- * @return {object|function} The first parameter to this function, after
138
+ * @returns {object | Function} The first parameter to this function, after
146
139
  * wrapping it or its properties.
147
- *
148
140
  * @see PromiseShim#wrapConstructor
149
141
  */
150
142
  wrapExecutorCaller(nodule, properties) {
@@ -159,14 +151,14 @@ class PromiseShim extends Shim {
159
151
  return caller.apply(this, arguments)
160
152
  }
161
153
 
162
- if (!this.__NR_context) {
154
+ if (!this[symbols.context]) {
163
155
  Contextualizer.link(null, this, parent)
164
156
  }
165
157
 
166
158
  const args = shim.argsToArray.apply(shim, arguments)
167
159
  _wrapExecutorContext(shim, args)
168
160
  const ret = caller.apply(this, args)
169
- const context = args[0].__NR_executorContext
161
+ const context = args[0][symbols.executorContext]
170
162
  context.promise = this
171
163
 
172
164
  // Bluebird catches executor errors and auto-rejects when it catches them,
@@ -196,14 +188,12 @@ class PromiseShim extends Shim {
196
188
  * and Bluebird's `Promise.delay`. These are static methods which accept some
197
189
  * arbitrary value and return a Promise instance.
198
190
  *
199
- * @param {object|function} nodule
191
+ * @param {object | Function} nodule
200
192
  * The source of the properties to wrap, or a single function to wrap.
201
- *
202
- * @param {string|array.<string>} [properties]
193
+ * @param {string | Array.<string>} [properties]
203
194
  * One or more properties to wrap. If omitted, the `nodule` parameter is
204
195
  * assumed to be the function to wrap.
205
- *
206
- * @return {object|function} The first parameter to this function, after
196
+ * @returns {object | Function} The first parameter to this function, after
207
197
  * wrapping it or its properties.
208
198
  */
209
199
  wrapCast(nodule, properties) {
@@ -235,16 +225,13 @@ class PromiseShim extends Shim {
235
225
  * and Bluebird's `Promise#map`. These are methods which take a function to
236
226
  * execute once the promise resolves and hands back a new promise.
237
227
  *
238
- * @param {object|function} nodule
228
+ * @param {object | Function} nodule
239
229
  * The source of the properties to wrap, or a single function to wrap.
240
- *
241
- * @param {string|array.<string>} [properties]
230
+ * @param {string | Array.<string>} [properties]
242
231
  * One or more properties to wrap. If omitted, the `nodule` parameter is
243
232
  * assumed to be the function to wrap.
244
- *
245
- * @return {object|function} The first parameter to this function, after
233
+ * @returns {object | Function} The first parameter to this function, after
246
234
  * wrapping it or its properties.
247
- *
248
235
  * @see PromiseShim#setClass
249
236
  * @see PromiseShim#wrapCatch
250
237
  */
@@ -265,16 +252,13 @@ class PromiseShim extends Shim {
265
252
  * an additional argument to `Promise#catch` which is usually an error class
266
253
  * to filter rejections by. This wrap method will handle that case.
267
254
  *
268
- * @param {object|function} nodule
255
+ * @param {object | Function} nodule
269
256
  * The source of the properties to wrap, or a single function to wrap.
270
- *
271
- * @param {string|array.<string>} [properties]
257
+ * @param {string | Array.<string>} [properties]
272
258
  * One or more properties to wrap. If omitted, the `nodule` parameter is
273
259
  * assumed to be the function to wrap.
274
- *
275
- * @return {object|function} The first parameter to this function, after
260
+ * @returns {object | Function} The first parameter to this function, after
276
261
  * wrapping it or its properties.
277
- *
278
262
  * @see PromiseShim#setClass
279
263
  * @see PromiseShim#wrapThen
280
264
  */
@@ -288,14 +272,12 @@ class PromiseShim extends Shim {
288
272
  * - `wrapPromisify(nodule, properties)`
289
273
  * - `wrapPromisify(func)`
290
274
  *
291
- * @param {object|function} nodule
275
+ * @param {object | Function} nodule
292
276
  * The source of the properties to wrap, or a single function to wrap.
293
- *
294
- * @param {string|array.<string>} [properties]
277
+ * @param {string | Array.<string>} [properties]
295
278
  * One or more properties to wrap. If omitted, the `nodule` parameter is
296
279
  * assumed to be the function to wrap.
297
- *
298
- * @return {object|function} The first parameter to this function, after
280
+ * @returns {object | Function} The first parameter to this function, after
299
281
  * wrapping it or its properties.
300
282
  */
301
283
  wrapPromisify(nodule, properties) {
@@ -315,6 +297,9 @@ class PromiseShim extends Shim {
315
297
  })
316
298
 
317
299
  return __NR_wrappedPromisified
300
+ /**
301
+ *
302
+ */
318
303
  function __NR_wrappedPromisified() {
319
304
  const segment = shim.getActiveSegment()
320
305
  if (!segment) {
@@ -334,6 +319,8 @@ module.exports = PromiseShim
334
319
  // -------------------------------------------------------------------------- //
335
320
 
336
321
  /**
322
+ * @param shim
323
+ * @param args
337
324
  * @private
338
325
  */
339
326
  function _wrapExecutorContext(shim, args) {
@@ -343,9 +330,14 @@ function _wrapExecutorContext(shim, args) {
343
330
  self: null,
344
331
  args: null
345
332
  }
346
- contextExporter.__NR_executorContext = context
333
+ contextExporter[symbols.executorContext] = context
347
334
  args[0] = contextExporter
348
335
 
336
+ /**
337
+ *
338
+ * @param resolve
339
+ * @param reject
340
+ */
349
341
  function contextExporter(resolve, reject) {
350
342
  context.self = this
351
343
  context.args = shim.argsToArray.apply(shim, arguments)
@@ -355,19 +347,25 @@ function _wrapExecutorContext(shim, args) {
355
347
  }
356
348
 
357
349
  /**
350
+ * @param context
351
+ * @param fn
358
352
  * @private
359
353
  */
360
354
  function _wrapResolver(context, fn) {
361
355
  return function wrappedResolveReject(val) {
362
356
  const promise = context.promise
363
- if (promise && promise.__NR_context) {
364
- promise.__NR_context.getSegment().touch()
357
+ if (promise && promise[symbols.context]) {
358
+ promise[symbols.context].getSegment().touch()
365
359
  }
366
360
  fn(val)
367
361
  }
368
362
  }
369
363
 
370
364
  /**
365
+ * @param shim
366
+ * @param fn
367
+ * @param name
368
+ * @param useAllParams
371
369
  * @private
372
370
  */
373
371
  function _wrapThen(shim, fn, name, useAllParams) {
@@ -398,6 +396,12 @@ function _wrapThen(shim, fn, name, useAllParams) {
398
396
  }
399
397
  return next
400
398
 
399
+ /**
400
+ *
401
+ * @param handler
402
+ * @param i
403
+ * @param length
404
+ */
401
405
  function wrapHandler(handler, i, length) {
402
406
  if (
403
407
  !shim.isFunction(handler) || // Not a function
@@ -409,14 +413,14 @@ function _wrapThen(shim, fn, name, useAllParams) {
409
413
  }
410
414
 
411
415
  return function __NR_wrappedThenHandler() {
412
- if (!next || !next.__NR_context) {
416
+ if (!next || !next[symbols.context]) {
413
417
  return handler.apply(this, arguments)
414
418
  }
415
419
 
416
- let promSegment = next.__NR_context.getSegment()
420
+ let promSegment = next[symbols.context].getSegment()
417
421
  const segment = promSegment || shim.getSegment()
418
422
  if (segment && segment !== promSegment) {
419
- next.__NR_context.setSegment(segment)
423
+ next[symbols.context].setSegment(segment)
420
424
  promSegment = segment
421
425
  }
422
426
 
@@ -425,7 +429,7 @@ function _wrapThen(shim, fn, name, useAllParams) {
425
429
  ret = shim.applySegment(handler, promSegment, true, this, arguments)
426
430
  } finally {
427
431
  if (ret && typeof ret.then === 'function') {
428
- ret = next.__NR_context.continueContext(ret)
432
+ ret = next[symbols.context].continueContext(ret)
429
433
  }
430
434
  }
431
435
  return ret
@@ -459,9 +463,9 @@ class Contextualizer {
459
463
  }
460
464
 
461
465
  static link(prev, next, segment) {
462
- let ctxlzr = prev && prev.__NR_context
466
+ let ctxlzr = prev && prev[symbols.context]
463
467
  if (ctxlzr && !ctxlzr.isActive()) {
464
- ctxlzr = prev.__NR_context = null
468
+ ctxlzr = prev[symbols.context] = null
465
469
  }
466
470
 
467
471
  if (ctxlzr) {
@@ -503,17 +507,17 @@ class Contextualizer {
503
507
  const idx = ctxlzr.child === false ? ctxlzr.context.branch() : ctxlzr.idx
504
508
 
505
509
  // Create a new context for this next promise.
506
- next.__NR_context = new Contextualizer(idx, ctxlzr.context)
507
- next.__NR_context.parentIdx = ctxlzr.idx
510
+ next[symbols.context] = new Contextualizer(idx, ctxlzr.context)
511
+ next[symbols.context].parentIdx = ctxlzr.idx
508
512
 
509
513
  // If this was our first child, remember it in case we have a 2nd.
510
514
  if (ctxlzr.child === null) {
511
- ctxlzr.child = next.__NR_context
515
+ ctxlzr.child = next[symbols.context]
512
516
  }
513
517
  } else if (segment) {
514
518
  // This next promise is the root of a chain. Either there was no previous
515
519
  // promise or the promise was created out of context.
516
- next.__NR_context = new Contextualizer(0, new Context(segment))
520
+ next[symbols.context] = new Contextualizer(0, new Context(segment))
517
521
  }
518
522
  }
519
523
 
@@ -542,7 +546,7 @@ class Contextualizer {
542
546
 
543
547
  continueContext(prom) {
544
548
  const self = this
545
- const nextContext = prom.__NR_context
549
+ const nextContext = prom[symbols.context]
546
550
  if (!nextContext) {
547
551
  return prom
548
552
  }
@@ -565,6 +569,9 @@ class Contextualizer {
565
569
  }
566
570
  )
567
571
 
572
+ /**
573
+ *
574
+ */
568
575
  function __NR_continueContext() {
569
576
  self.setSegment(nextContext.getSegment())
570
577
  }
package/lib/shim/shim.js CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  'use strict'
7
7
 
8
+ /* eslint sonarjs/cognitive-complexity: ["error", 59] -- TODO: https://issues.newrelic.com/browse/NEWRELIC-5252 */
9
+
8
10
  const arity = require('../util/arity')
9
- const constants = require('./constants')
10
11
  const hasOwnProperty = require('../util/properties').hasOwn
11
12
  const logger = require('../logger').child({ component: 'Shim' })
12
13
  const path = require('path')
13
14
  const specs = require('./specs')
14
15
  const util = require('util')
16
+ const symbols = require('../symbols')
15
17
 
16
18
  // Some modules do terrible things, like change the prototype of functions. To
17
19
  // avoid crashing things we'll use a cached copy of apply everywhere.
@@ -52,14 +54,14 @@ module.exports = Shim
52
54
  Shim.defineProperty = defineProperty
53
55
  Shim.defineProperties = defineProperties
54
56
 
57
+ // This is for backwards compat for external libraries like aws-sdk that expect the symbol to be defined here
58
+ defineProperty(Shim, 'DISABLE_DT', symbols.disableDT)
59
+ defineProperty(Shim.prototype, 'DISABLE_DT', symbols.disableDT)
60
+
55
61
  // Copy the argument index enumeration onto the shim.
56
62
  Shim.prototype.ARG_INDEXES = specs.ARG_INDEXES
57
63
  defineProperties(Shim.prototype, specs.ARG_INDEXES)
58
64
 
59
- // Copy symbols to the shim as well.
60
- defineProperties(Shim, constants.SYMBOLS)
61
- defineProperties(Shim.prototype, constants.SYMBOLS)
62
-
63
65
  // Define other miscellaneous properties of the shim.
64
66
  defineProperties(Shim.prototype, {
65
67
  /**
@@ -130,8 +132,6 @@ Shim.prototype.argsToArray = argsToArray
130
132
  Shim.prototype.normalizeIndex = normalizeIndex
131
133
  Shim.prototype.once = once
132
134
 
133
- Shim.prototype.setInternalProperty = setInternalProperty
134
-
135
135
  Shim.prototype.defineProperty = defineProperty
136
136
  Shim.prototype.defineProperties = defineProperties
137
137
  Shim.prototype.setDefaults = setDefaults
@@ -144,7 +144,7 @@ Shim.prototype.fixArity = arity.fixArity
144
144
  // Internal methods.
145
145
  Shim.prototype.getExport = getExport
146
146
  Shim.prototype.enableDebug = enableDebug
147
- Shim.prototype.__NR_unwrap = unwrapAll
147
+ Shim.prototype[symbols.unwrap] = unwrapAll
148
148
 
149
149
  // -------------------------------------------------------------------------- //
150
150
 
@@ -291,10 +291,10 @@ Shim.prototype.__NR_unwrap = unwrapAll
291
291
  * `true`. Good for preventing double wrapping of prototype methods.
292
292
  *
293
293
  * ```js
294
- * if (spec.$once && spec.__NR_onceExecuted) {
294
+ * if (spec.$once && spec[symbols.onceExecuted]) {
295
295
  * return context
296
296
  * }
297
- * spec.__NR_onceExecuted = true
297
+ * spec[symbols.onceExecuted] = true
298
298
  * ```
299
299
  * @property {ArgumentsFunction} $arguments
300
300
  * Executes the function with all of the arguments passed in. The arguments can
@@ -350,7 +350,7 @@ Shim.prototype.__NR_unwrap = unwrapAll
350
350
  * segment = shim.createSegment(seg.name, seg.recorder, seg.parent)
351
351
  * }
352
352
  * ```
353
- * @property {object.<string, *>} $cache
353
+ * @property {Object<string, *>} $cache
354
354
  * Adds the value as an extra parameter to all specs in the same context as the
355
355
  * cache. If the current context is a function, the cache will be recreated on
356
356
  * each invocation of the function. This value can be useful for passing a
@@ -468,7 +468,7 @@ function execute(nodule, spec) {
468
468
  if (this.isFunction(spec)) {
469
469
  spec(this, nodule)
470
470
  } else {
471
- _specToFunction(spec)(this, nodule)
471
+ _specToFunction(spec)
472
472
  }
473
473
  }
474
474
 
@@ -522,7 +522,7 @@ function wrap(nodule, properties, spec, args) {
522
522
  }
523
523
  }
524
524
 
525
- // TODO: Add option for omitting __NR_original; unwrappable: false
525
+ // TODO: Add option for omitting symbols.original; unwrappable: false
526
526
  spec = this.setDefaults(spec, { matchArity: false })
527
527
 
528
528
  // If we're just wrapping one thing, just wrap it and return.
@@ -553,10 +553,10 @@ function wrap(nodule, properties, spec, args) {
553
553
  this.logger.trace('Replacing "%s" with wrapped version', prop)
554
554
 
555
555
  nodule[prop] = wrapped
556
- this.setInternalProperty(wrapped, '__NR_unwrap', function unwrapWrap() {
556
+ wrapped[symbols.unwrap] = function unwrapWrap() {
557
557
  nodule[prop] = original
558
558
  return original
559
- })
559
+ }
560
560
  }
561
561
  }, this)
562
562
  return nodule
@@ -597,7 +597,7 @@ function wrapReturn(nodule, properties, spec, args) {
597
597
  properties = null
598
598
  }
599
599
  if (!this.isFunction(spec)) {
600
- spec = _specToFunction(spec)
600
+ _specToFunction(spec)
601
601
  }
602
602
  if (!this.isArray(args)) {
603
603
  args = []
@@ -614,17 +614,17 @@ function wrapReturn(nodule, properties, spec, args) {
614
614
  const handler = {
615
615
  get: function getTrap(target, prop) {
616
616
  // Allow for look up of the target
617
- if (prop === '__NR_original') {
617
+ if (prop === symbols.original) {
618
618
  return target
619
619
  }
620
- if (prop === '__NR_unwrap') {
620
+ if (prop === symbols.unwrap) {
621
621
  return unwrapReference
622
622
  }
623
623
 
624
624
  return target[prop]
625
625
  },
626
626
  defineProperty: function definePropertyTrap(target, key, descriptor) {
627
- if (key === '__NR_unwrap') {
627
+ if (key === symbols.unwrap) {
628
628
  unwrapReference = descriptor.value
629
629
  } else {
630
630
  Object.defineProperty(target, key, descriptor)
@@ -632,7 +632,7 @@ function wrapReturn(nodule, properties, spec, args) {
632
632
  return true
633
633
  },
634
634
  set: function setTrap(target, key, val) {
635
- if (key === '__NR_unwrap') {
635
+ if (key === symbols.unwrap) {
636
636
  unwrapReference = val
637
637
  } else {
638
638
  target[key] = val
@@ -784,9 +784,9 @@ function getExport(defaultExport) {
784
784
  */
785
785
  function isWrapped(nodule, property) {
786
786
  if (property) {
787
- return !!(nodule && nodule[property] && nodule[property].__NR_original)
787
+ return !!(nodule && nodule[property] && nodule[property][symbols.original])
788
788
  }
789
- return !!(nodule && nodule.__NR_original)
789
+ return !!(nodule && nodule[symbols.original])
790
790
  }
791
791
 
792
792
  /**
@@ -991,10 +991,10 @@ function unwrap(nodule, properties) {
991
991
 
992
992
  this.logger.trace('Unwrapping %s', properties || '<nodule>')
993
993
  let original = properties ? nodule[properties] : nodule
994
- while (original && original.__NR_original) {
995
- original = this.isFunction(original.__NR_unwrap)
996
- ? original.__NR_unwrap()
997
- : original.__NR_original
994
+ while (original && original[symbols.original]) {
995
+ original = this.isFunction(original[symbols.unwrap])
996
+ ? original[symbols.unwrap]()
997
+ : original[symbols.original]
998
998
  }
999
999
  return original
1000
1000
  }
@@ -1030,10 +1030,10 @@ function unwrapOnce(nodule, properties) {
1030
1030
 
1031
1031
  this.logger.trace('Unwrapping %s', properties || '<nodule>')
1032
1032
  let original = properties ? nodule[properties] : nodule
1033
- if (original && original.__NR_original) {
1034
- original = this.isFunction(original.__NR_unwrap)
1035
- ? original.__NR_unwrap()
1036
- : original.__NR_original
1033
+ if (original && original[symbols.original]) {
1034
+ original = this.isFunction(original[symbols.unwrap])
1035
+ ? original[symbols.unwrap]()
1036
+ : original[symbols.original]
1037
1037
  }
1038
1038
  return original
1039
1039
  }
@@ -1057,8 +1057,8 @@ function getOriginal(nodule, property) {
1057
1057
  }
1058
1058
 
1059
1059
  let original = property ? nodule[property] : nodule
1060
- while (original && original.__NR_original) {
1061
- original = original.__NR_original
1060
+ while (original && original[symbols.original]) {
1061
+ original = original[symbols.original]
1062
1062
  }
1063
1063
  return original
1064
1064
  }
@@ -1107,7 +1107,7 @@ function bindSegment(nodule, property, segment, full) {
1107
1107
  return nodule
1108
1108
  }
1109
1109
 
1110
- const wrapped = this.wrap(nodule, property, function wrapFunc(shim, func) {
1110
+ return this.wrap(nodule, property, function wrapFunc(shim, func) {
1111
1111
  if (!shim.isFunction(func)) {
1112
1112
  return func
1113
1113
  }
@@ -1122,8 +1122,6 @@ function bindSegment(nodule, property, segment, full) {
1122
1122
  shim.storeSegment(binder, segment)
1123
1123
  return binder
1124
1124
  })
1125
-
1126
- return wrapped
1127
1125
  }
1128
1126
 
1129
1127
  /**
@@ -1206,8 +1204,8 @@ function bindCallbackSegment(args, cbIdx, parentSegment) {
1206
1204
  * with the object.
1207
1205
  */
1208
1206
  function getSegment(obj) {
1209
- if (obj && obj.__NR_segment) {
1210
- return obj.__NR_segment
1207
+ if (obj && obj[symbols.segment]) {
1208
+ return obj[symbols.segment]
1211
1209
  }
1212
1210
 
1213
1211
  return this._contextManager.getContext()
@@ -1264,7 +1262,9 @@ function setActiveSegment(segment) {
1264
1262
  * @param {TraceSegment} [segment] - The segment to link the object to.
1265
1263
  */
1266
1264
  function storeSegment(obj, segment) {
1267
- this.setInternalProperty(obj, '__NR_segment', segment || this.getSegment())
1265
+ if (obj) {
1266
+ obj[symbols.segment] = segment || this.getSegment()
1267
+ }
1268
1268
  }
1269
1269
 
1270
1270
  /* eslint-disable max-params */
@@ -1300,7 +1300,7 @@ function applySegment(func, segment, full, context, args, inContextCB) {
1300
1300
  const contextManager = this._contextManager
1301
1301
  const prevSegment = contextManager.getContext()
1302
1302
 
1303
- return contextManager.runInContext(segment, () => {
1303
+ return contextManager.runInContext(segment, function runInContextCb() {
1304
1304
  if (full) {
1305
1305
  segment.start()
1306
1306
  }
@@ -1313,7 +1313,7 @@ function applySegment(func, segment, full, context, args, inContextCB) {
1313
1313
  return fnApply.call(func, context, args)
1314
1314
  } catch (error) {
1315
1315
  if (prevSegment === null && process.domain != null) {
1316
- process.domain.__NR_segment = contextManager.getContext()
1316
+ process.domain[symbols.segment] = contextManager.getContext()
1317
1317
  }
1318
1318
 
1319
1319
  throw error // Re-throwing application error, this is not an agent error.
@@ -1571,51 +1571,6 @@ function once(fn) {
1571
1571
  }
1572
1572
  }
1573
1573
 
1574
- /**
1575
- * Sets a property to the given value. If the property doesn't exist yet it will
1576
- * be made writable and non-enumerable.
1577
- *
1578
- * @memberof Shim.prototype
1579
- * @param {!object} obj - The object to add the property to.
1580
- * @param {!string} name - The name for this property.
1581
- * @param {*} val - The value to set the property as.
1582
- * @returns {object} The `obj` value.
1583
- */
1584
- function setInternalProperty(obj, name, val) {
1585
- if (!obj || !name) {
1586
- this.logger.debug('Not setting property; object or name is missing.')
1587
- return obj
1588
- }
1589
-
1590
- try {
1591
- if (this.agent.config.transaction_tracer.hide_internals) {
1592
- _slowSetInternalProperty(obj, name, val)
1593
- } else {
1594
- obj[name] = val
1595
- }
1596
- } catch (err) {
1597
- this.logger.debug(err, 'Failed to set property "%s" to %j', name, val)
1598
- }
1599
- return obj
1600
- }
1601
-
1602
- /**
1603
- * @param obj
1604
- * @param name
1605
- * @param val
1606
- */
1607
- function _slowSetInternalProperty(obj, name, val) {
1608
- if (!hasOwnProperty(obj, name)) {
1609
- Object.defineProperty(obj, name, {
1610
- enumerable: false,
1611
- writable: true,
1612
- value: val
1613
- })
1614
- } else {
1615
- obj[name] = val
1616
- }
1617
- }
1618
-
1619
1574
  /**
1620
1575
  * Defines a read-only property on the given object.
1621
1576
  *
@@ -1805,7 +1760,7 @@ function enableDebug() {
1805
1760
  * enabled first.
1806
1761
  *
1807
1762
  * @private
1808
- * @member Shim.prototype.__NR_unwrap
1763
+ * @member Shim.prototype.unwrap
1809
1764
  */
1810
1765
  function unwrapAll() {
1811
1766
  if (this._wrapped) {
@@ -1870,9 +1825,9 @@ function _wrap(shim, original, name, spec, args) {
1870
1825
 
1871
1826
  // TODO: Once all wrapping is converted to proxies, we won't need to
1872
1827
  // set this property as the trap on 'get' will return the original for
1873
- // __NR_original. For now, we have to prevent setting this on original.
1874
- if (!wrapped.__NR_original) {
1875
- shim.setInternalProperty(wrapped, '__NR_original', original)
1828
+ // symbols.original. For now, we have to prevent setting this on original.
1829
+ if (!wrapped[symbols.original]) {
1830
+ wrapped[symbols.original] = original
1876
1831
  }
1877
1832
 
1878
1833
  if (shim._debug) {
@@ -295,7 +295,7 @@ function insertCATRequestHeaders(headers, useAlternateHeaderNames) {
295
295
  }
296
296
 
297
297
  if (distributedTracingEnabled) {
298
- // TODO: Should probably honor SHIM_SYMBOLS.DISABLE_DT.
298
+ // TODO: Should probably honor symbols.disableDT.
299
299
  // TODO: Official testing and support.
300
300
  tx.insertDistributedTraceHeaders(headers)
301
301
  } else {