newrelic 8.0.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/NEWS.md +5023 -4922
  2. package/THIRD_PARTY_NOTICES.md +618 -209
  3. package/api.js +156 -219
  4. package/bin/test-naming-rules.js +57 -51
  5. package/bin/tracetractor +0 -1
  6. package/index.js +7 -14
  7. package/lib/agent.js +111 -114
  8. package/lib/aggregators/base-aggregator.js +1 -1
  9. package/lib/aggregators/event-aggregator.js +6 -6
  10. package/lib/attributes.js +13 -14
  11. package/lib/collector/api.js +44 -54
  12. package/lib/collector/facts.js +68 -66
  13. package/lib/collector/http-agents.js +36 -32
  14. package/lib/collector/key-parser.js +1 -1
  15. package/lib/collector/parse-response.js +1 -2
  16. package/lib/collector/remote-method.js +69 -61
  17. package/lib/collector/serverless.js +13 -18
  18. package/lib/collector/ssl/certificates.js +1056 -1056
  19. package/lib/config/attribute-filter.js +109 -101
  20. package/lib/config/default.js +35 -21
  21. package/lib/config/env.js +17 -12
  22. package/lib/config/harvest-config-validator.js +1 -1
  23. package/lib/config/hsm.js +1 -1
  24. package/lib/config/index.js +240 -234
  25. package/lib/config/lasp.js +3 -3
  26. package/lib/config/merge-server-config.js +8 -6
  27. package/lib/custom-events/custom-event-aggregator.js +1 -1
  28. package/lib/db/parse-sql.js +13 -16
  29. package/lib/db/parsed-statement.js +13 -19
  30. package/lib/db/query-parsers/sql.js +12 -15
  31. package/lib/db/query-sample.js +16 -12
  32. package/lib/db/query-trace-aggregator.js +16 -16
  33. package/lib/db/statement-matcher.js +5 -5
  34. package/lib/db/utils.js +2 -2
  35. package/lib/environment.js +210 -175
  36. package/lib/errors/error-collector.js +20 -33
  37. package/lib/errors/error-event-aggregator.js +1 -1
  38. package/lib/errors/error-trace-aggregator.js +3 -4
  39. package/lib/errors/helper.js +23 -32
  40. package/lib/errors/index.js +31 -43
  41. package/lib/feature_flags.js +3 -4
  42. package/lib/grpc/connection/states.js +6 -6
  43. package/lib/grpc/connection.js +35 -46
  44. package/lib/header-attributes.js +55 -59
  45. package/lib/header-processing.js +1 -1
  46. package/lib/instrumentation/amqplib.js +34 -43
  47. package/lib/instrumentation/bluebird.js +63 -22
  48. package/lib/instrumentation/cassandra-driver.js +8 -4
  49. package/lib/instrumentation/connect.js +7 -6
  50. package/lib/instrumentation/core/async_hooks.js +16 -9
  51. package/lib/instrumentation/core/child_process.js +20 -28
  52. package/lib/instrumentation/core/crypto.js +1 -7
  53. package/lib/instrumentation/core/dns.js +3 -7
  54. package/lib/instrumentation/core/domain.js +4 -10
  55. package/lib/instrumentation/core/fs.js +22 -37
  56. package/lib/instrumentation/core/globals.js +4 -8
  57. package/lib/instrumentation/core/http-outbound.js +20 -114
  58. package/lib/instrumentation/core/http.js +61 -128
  59. package/lib/instrumentation/core/inspector.js +7 -11
  60. package/lib/instrumentation/core/net.js +3 -1
  61. package/lib/instrumentation/core/timers.js +21 -28
  62. package/lib/instrumentation/core/zlib.js +3 -11
  63. package/lib/instrumentation/director.js +4 -4
  64. package/lib/instrumentation/express.js +12 -10
  65. package/lib/instrumentation/fastify/spec-builders.js +5 -0
  66. package/lib/instrumentation/fastify.js +37 -10
  67. package/lib/instrumentation/generic-pool.js +1 -1
  68. package/lib/instrumentation/hapi/hapi-17.js +20 -21
  69. package/lib/instrumentation/hapi/shared.js +1 -1
  70. package/lib/instrumentation/hapi.js +37 -37
  71. package/lib/instrumentation/ioredis.js +8 -9
  72. package/lib/instrumentation/memcached.js +41 -45
  73. package/lib/instrumentation/mongodb/common.js +221 -0
  74. package/lib/instrumentation/mongodb/constants.js +87 -0
  75. package/lib/instrumentation/mongodb/v2-mongo.js +110 -0
  76. package/lib/instrumentation/mongodb/v3-mongo.js +80 -0
  77. package/lib/instrumentation/mongodb/v4-mongo.js +90 -0
  78. package/lib/instrumentation/mongodb.js +20 -312
  79. package/lib/instrumentation/mysql.js +51 -44
  80. package/lib/instrumentation/oracle.js +24 -28
  81. package/lib/instrumentation/pg.js +34 -25
  82. package/lib/instrumentation/promise.js +65 -62
  83. package/lib/instrumentation/q.js +2 -2
  84. package/lib/instrumentation/redis.js +38 -38
  85. package/lib/instrumentation/restify.js +1 -1
  86. package/lib/instrumentation/vision.js +4 -4
  87. package/lib/instrumentation/when.js +12 -4
  88. package/lib/instrumentations.js +25 -25
  89. package/lib/logger.js +6 -6
  90. package/lib/metrics/index.js +50 -30
  91. package/lib/metrics/mapper.js +15 -15
  92. package/lib/metrics/metric-aggregator.js +5 -10
  93. package/lib/metrics/names.js +8 -7
  94. package/lib/metrics/normalizer/rule.js +14 -15
  95. package/lib/metrics/normalizer/tx_segment.js +33 -29
  96. package/lib/metrics/normalizer.js +51 -54
  97. package/lib/metrics/recorders/custom.js +8 -6
  98. package/lib/metrics/recorders/distributed-trace.js +3 -18
  99. package/lib/metrics/recorders/generic.js +6 -5
  100. package/lib/metrics/recorders/http.js +11 -13
  101. package/lib/metrics/recorders/http_external.js +8 -10
  102. package/lib/metrics/recorders/message-transaction.js +7 -18
  103. package/lib/metrics/recorders/other.js +7 -17
  104. package/lib/parse-proc-cpuinfo.js +26 -31
  105. package/lib/parse-proc-meminfo.js +5 -3
  106. package/lib/prioritized-attributes.js +14 -19
  107. package/lib/priority-queue.js +11 -11
  108. package/lib/proxy/grpc.js +1 -1
  109. package/lib/reservoir.js +12 -6
  110. package/lib/sampler.js +33 -34
  111. package/lib/serverless/api-gateway.js +3 -3
  112. package/lib/serverless/aws-lambda.js +28 -37
  113. package/lib/shim/conglomerate-shim.js +4 -4
  114. package/lib/shim/datastore-shim.js +61 -67
  115. package/lib/shim/index.js +10 -11
  116. package/lib/shim/message-shim.js +149 -151
  117. package/lib/shim/promise-shim.js +19 -14
  118. package/lib/shim/shim.js +131 -125
  119. package/lib/shim/specs/index.js +21 -22
  120. package/lib/shim/transaction-shim.js +52 -210
  121. package/lib/shim/webframework-shim.js +75 -85
  122. package/lib/shimmer.js +184 -166
  123. package/lib/spans/create-span-event-aggregator.js +11 -8
  124. package/lib/spans/span-context.js +4 -10
  125. package/lib/spans/span-event-aggregator.js +68 -13
  126. package/lib/spans/span-event.js +6 -8
  127. package/lib/spans/span-streamer.js +10 -18
  128. package/lib/spans/streaming-span-attributes.js +1 -1
  129. package/lib/spans/streaming-span-event-aggregator.js +1 -1
  130. package/lib/spans/streaming-span-event.js +4 -4
  131. package/lib/stats/apdex.js +7 -13
  132. package/lib/stats/index.js +14 -19
  133. package/lib/system-info.js +29 -25
  134. package/lib/timer.js +35 -21
  135. package/lib/transaction/dt-payload.js +1 -1
  136. package/lib/transaction/handle.js +19 -19
  137. package/lib/transaction/index.js +133 -151
  138. package/lib/transaction/name-state.js +18 -19
  139. package/lib/transaction/trace/aggregator.js +78 -73
  140. package/lib/transaction/trace/exclusive-time-calculator.js +9 -13
  141. package/lib/transaction/trace/index.js +37 -35
  142. package/lib/transaction/trace/segment.js +56 -73
  143. package/lib/transaction/tracecontext.js +38 -46
  144. package/lib/transaction/tracer/index.js +130 -91
  145. package/lib/transaction/transaction-event-aggregator.js +29 -31
  146. package/lib/uninstrumented.js +11 -12
  147. package/lib/util/arity.js +2 -2
  148. package/lib/util/attribute-types.js +1 -5
  149. package/lib/util/byte-limit.js +4 -5
  150. package/lib/util/cat.js +270 -33
  151. package/lib/util/codec.js +10 -6
  152. package/lib/util/copy.js +2 -2
  153. package/lib/util/deep-equal.js +51 -21
  154. package/lib/util/flatten.js +9 -6
  155. package/lib/util/hashes.js +16 -16
  156. package/lib/util/label-parser.js +22 -28
  157. package/lib/util/logger.js +53 -35
  158. package/lib/util/process-version.js +3 -3
  159. package/lib/util/properties.js +5 -5
  160. package/lib/util/sql/obfuscate.js +21 -31
  161. package/lib/util/stream-sink.js +5 -6
  162. package/lib/util/unwrapped-core.js +2 -2
  163. package/lib/util/urltils.js +26 -30
  164. package/lib/utilization/aws-info.js +8 -9
  165. package/lib/utilization/azure-info.js +37 -35
  166. package/lib/utilization/common.js +17 -16
  167. package/lib/utilization/docker-info.js +14 -16
  168. package/lib/utilization/gcp-info.js +38 -37
  169. package/lib/utilization/index.js +5 -5
  170. package/lib/utilization/kubernetes-info.js +2 -2
  171. package/lib/utilization/pcf-info.js +12 -12
  172. package/package.json +23 -6
  173. package/stub_api.js +16 -14
package/api.js CHANGED
@@ -6,7 +6,7 @@
6
6
  'use strict'
7
7
 
8
8
  const util = require('util')
9
- const logger = require('./lib/logger').child({component: 'api'})
9
+ const logger = require('./lib/logger').child({ component: 'api' })
10
10
  const recordWeb = require('./lib/metrics/recorders/http')
11
11
  const recordBackground = require('./lib/metrics/recorders/other')
12
12
  const customRecorder = require('./lib/metrics/recorders/custom')
@@ -28,8 +28,8 @@ const NAMES = require('./lib/metrics/names')
28
28
  * CONSTANTS
29
29
  *
30
30
  */
31
- const RUM_STUB = "<script type='text/javascript' %s>window.NREUM||(NREUM={});" +
32
- "NREUM.info = %s; %s</script>"
31
+ const RUM_STUB =
32
+ "<script type='text/javascript' %s>window.NREUM||(NREUM={});" + 'NREUM.info = %s; %s</script>'
33
33
 
34
34
  // these messages are used in the _gracefail() method below in getBrowserTimingHeader
35
35
  const RUM_ISSUES = [
@@ -44,9 +44,7 @@ const RUM_ISSUES = [
44
44
  ]
45
45
 
46
46
  // Can't overwrite internal parameters or all heck will break loose.
47
- const CUSTOM_DENYLIST = new Set([
48
- 'nr_flatten_leading'
49
- ])
47
+ const CUSTOM_DENYLIST = new Set(['nr_flatten_leading'])
50
48
 
51
49
  const CUSTOM_EVENT_TYPE_REGEX = /^[a-zA-Z0-9:_ ]+$/
52
50
 
@@ -78,24 +76,21 @@ function API(agent) {
78
76
  * Relic UI. Will be prefixed with 'Custom/' when sent.
79
77
  */
80
78
  API.prototype.setTransactionName = function setTransactionName(name) {
81
- var metric = this.agent.metrics.getOrCreateMetric(
79
+ const metric = this.agent.metrics.getOrCreateMetric(
82
80
  NAMES.SUPPORTABILITY.API + '/setTransactionName'
83
81
  )
84
82
  metric.incrementCallCount()
85
83
 
86
- var transaction = this.agent.tracer.getTransaction()
84
+ const transaction = this.agent.tracer.getTransaction()
87
85
  if (!transaction) {
88
86
  return logger.warn("No transaction found when setting name to '%s'.", name)
89
87
  }
90
88
 
91
89
  if (!name) {
92
90
  if (transaction && transaction.url) {
93
- logger.error(
94
- "Must include name in setTransactionName call for URL %s.",
95
- transaction.url
96
- )
91
+ logger.error('Must include name in setTransactionName call for URL %s.', transaction.url)
97
92
  } else {
98
- logger.error("Must include name in setTransactionName call.")
93
+ logger.error('Must include name in setTransactionName call.')
99
94
  }
100
95
 
101
96
  return
@@ -117,14 +112,12 @@ API.prototype.setTransactionName = function setTransactionName(name) {
117
112
  * `ignore` methods on it.
118
113
  */
119
114
  API.prototype.getTransaction = function getTransaction() {
120
- var metric = this.agent.metrics.getOrCreateMetric(
121
- NAMES.SUPPORTABILITY.API + '/getTransaction'
122
- )
115
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/getTransaction')
123
116
  metric.incrementCallCount()
124
117
 
125
- var transaction = this.agent.tracer.getTransaction()
118
+ const transaction = this.agent.tracer.getTransaction()
126
119
  if (!transaction) {
127
- logger.debug("No transaction found when calling API#getTransaction")
120
+ logger.debug('No transaction found when calling API#getTransaction')
128
121
  return new TransactionHandle.Stub()
129
122
  }
130
123
 
@@ -198,13 +191,11 @@ API.prototype.getLinkingMetadata = function getLinkingMetadata(omitSupportabilit
198
191
  * report to New Relic
199
192
  */
200
193
  API.prototype.setDispatcher = function setDispatcher(name, version) {
201
- var metric = this.agent.metrics.getOrCreateMetric(
202
- NAMES.SUPPORTABILITY.API + '/setDispatcher'
203
- )
194
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/setDispatcher')
204
195
  metric.incrementCallCount()
205
196
 
206
197
  if (!name || typeof name !== 'string') {
207
- logger.error("setDispatcher must be called with a name, and name must be a string.")
198
+ logger.error('setDispatcher must be called with a name, and name must be a string.')
208
199
  return
209
200
  }
210
201
 
@@ -239,24 +230,21 @@ API.prototype.setDispatcher = function setDispatcher(name, version) {
239
230
  * to the HTTP method used for the request.
240
231
  */
241
232
  API.prototype.setControllerName = function setControllerName(name, action) {
242
- var metric = this.agent.metrics.getOrCreateMetric(
233
+ const metric = this.agent.metrics.getOrCreateMetric(
243
234
  NAMES.SUPPORTABILITY.API + '/setControllerName'
244
235
  )
245
236
  metric.incrementCallCount()
246
237
 
247
- var transaction = this.agent.tracer.getTransaction()
238
+ const transaction = this.agent.tracer.getTransaction()
248
239
  if (!transaction) {
249
- return logger.warn("No transaction found when setting controller to %s.", name)
240
+ return logger.warn('No transaction found when setting controller to %s.', name)
250
241
  }
251
242
 
252
243
  if (!name) {
253
244
  if (transaction && transaction.url) {
254
- logger.error(
255
- "Must include name in setControllerName call for URL %s.",
256
- transaction.url
257
- )
245
+ logger.error('Must include name in setControllerName call for URL %s.', transaction.url)
258
246
  } else {
259
- logger.error("Must include name in setControllerName call.")
247
+ logger.error('Must include name in setControllerName call.')
260
248
  }
261
249
 
262
250
  return
@@ -266,7 +254,6 @@ API.prototype.setControllerName = function setControllerName(name, action) {
266
254
  transaction.forceName = NAMES.CONTROLLER + '/' + name + '/' + action
267
255
  }
268
256
 
269
-
270
257
  /**
271
258
  * Add a custom attribute to the current transaction. Some attributes are
272
259
  * reserved (see CUSTOM_DENYLIST for the current, very short list), and
@@ -284,15 +271,10 @@ API.prototype.addCustomAttribute = function addCustomAttribute(key, value) {
284
271
 
285
272
  // If high security mode is on, custom attributes are disabled.
286
273
  if (this.agent.config.high_security) {
287
- logger.warnOnce(
288
- 'Custom attributes',
289
- 'Custom attributes are disabled by high security mode.'
290
- )
274
+ logger.warnOnce('Custom attributes', 'Custom attributes are disabled by high security mode.')
291
275
  return false
292
276
  } else if (!this.agent.config.api.custom_attributes_enabled) {
293
- logger.debug(
294
- 'Config.api.custom_attributes_enabled set to false, not collecting value'
295
- )
277
+ logger.debug('Config.api.custom_attributes_enabled set to false, not collecting value')
296
278
  return false
297
279
  }
298
280
 
@@ -304,10 +286,7 @@ API.prototype.addCustomAttribute = function addCustomAttribute(key, value) {
304
286
 
305
287
  const trace = transaction.trace
306
288
  if (!trace.custom) {
307
- logger.warn(
308
- 'Could not add attribute %s to nonexistent custom attributes.',
309
- key
310
- )
289
+ logger.warn('Could not add attribute %s to nonexistent custom attributes.', key)
311
290
  return false
312
291
  }
313
292
 
@@ -343,12 +322,12 @@ API.prototype.addCustomAttribute = function addCustomAttribute(key, value) {
343
322
  * @param {string} [atts.KEY.VALUE] The value you want displayed. Must be serializable.
344
323
  */
345
324
  API.prototype.addCustomAttributes = function addCustomAttributes(atts) {
346
- var metric = this.agent.metrics.getOrCreateMetric(
325
+ const metric = this.agent.metrics.getOrCreateMetric(
347
326
  NAMES.SUPPORTABILITY.API + '/addCustomAttributes'
348
327
  )
349
328
  metric.incrementCallCount()
350
329
 
351
- for (var key in atts) {
330
+ for (const key in atts) {
352
331
  if (!properties.hasOwn(atts, key)) {
353
332
  continue
354
333
  }
@@ -376,7 +355,7 @@ API.prototype.addCustomSpanAttributes = function addCustomSpanAttributes(atts) {
376
355
  )
377
356
  metric.incrementCallCount()
378
357
 
379
- for (let key in atts) {
358
+ for (const key in atts) {
380
359
  if (properties.hasOwn(atts, key)) {
381
360
  this.addCustomSpanAttribute(key, atts[key])
382
361
  }
@@ -406,19 +385,14 @@ API.prototype.addCustomSpanAttribute = function addCustomSpanAttribute(key, valu
406
385
  )
407
386
  return false
408
387
  } else if (!this.agent.config.api.custom_attributes_enabled) {
409
- logger.debug(
410
- 'Config.api.custom_attributes_enabled set to false, not collecting value'
411
- )
388
+ logger.debug('Config.api.custom_attributes_enabled set to false, not collecting value')
412
389
  return false
413
390
  }
414
391
 
415
392
  const spanContext = this.agent.tracer.getSpanContext()
416
393
 
417
394
  if (!spanContext) {
418
- logger.debug(
419
- 'Could not add attribute %s. No available span.',
420
- key
421
- )
395
+ logger.debug('Could not add attribute %s. No available span.', key)
422
396
  return false
423
397
  }
424
398
 
@@ -445,28 +419,21 @@ API.prototype.addCustomSpanAttribute = function addCustomSpanAttribute(key, valu
445
419
  * Optional. Any custom attributes to be displayed in the New Relic UI.
446
420
  */
447
421
  API.prototype.noticeError = function noticeError(error, customAttributes) {
448
- const metric = this.agent.metrics.getOrCreateMetric(
449
- NAMES.SUPPORTABILITY.API + '/noticeError'
450
- )
422
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/noticeError')
451
423
  metric.incrementCallCount()
452
424
 
453
425
  if (!this.agent.config.api.notice_error_enabled) {
454
- logger.debug(
455
- 'Config.api.notice_error_enabled set to false, not collecting error'
456
- )
426
+ logger.debug('Config.api.notice_error_enabled set to false, not collecting error')
457
427
  return false
458
428
  }
459
429
 
460
430
  // If high security mode is on or custom attributes are disabled,
461
431
  // noticeError does not collect custom attributes.
462
432
  if (this.agent.config.high_security) {
463
- logger.debug(
464
- 'Passing custom attributes to notice error API is disabled in high security mode.'
465
- )
433
+ logger.debug('Passing custom attributes to notice error API is disabled in high security mode.')
466
434
  } else if (!this.agent.config.api.custom_attributes_enabled) {
467
435
  logger.debug(
468
- 'Config.api.custom_attributes_enabled set to false, ' +
469
- 'ignoring custom error attributes.'
436
+ 'Config.api.custom_attributes_enabled set to false, ' + 'ignoring custom error attributes.'
470
437
  )
471
438
  }
472
439
 
@@ -513,13 +480,12 @@ API.prototype.noticeError = function noticeError(error, customAttributes) {
513
480
  * @param {string} name The name to use for the transaction.
514
481
  */
515
482
  API.prototype.addNamingRule = function addNamingRule(pattern, name) {
516
- var metric = this.agent.metrics.getOrCreateMetric(
517
- NAMES.SUPPORTABILITY.API + '/addNamingRule'
518
- )
483
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/addNamingRule')
519
484
  metric.incrementCallCount()
520
485
 
521
-
522
- if (!name) return logger.error("Simple naming rules require a replacement name.")
486
+ if (!name) {
487
+ return logger.error('Simple naming rules require a replacement name.')
488
+ }
523
489
 
524
490
  this.agent.userNormalizer.addSimple(pattern, '/' + name)
525
491
  }
@@ -538,12 +504,12 @@ API.prototype.addNamingRule = function addNamingRule(pattern, name) {
538
504
  * @param {RegExp} pattern The pattern to ignore.
539
505
  */
540
506
  API.prototype.addIgnoringRule = function addIgnoringRule(pattern) {
541
- var metric = this.agent.metrics.getOrCreateMetric(
542
- NAMES.SUPPORTABILITY.API + '/addIgnoringRule'
543
- )
507
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/addIgnoringRule')
544
508
  metric.incrementCallCount()
545
509
 
546
- if (!pattern) return logger.error("Must include a URL pattern to ignore.")
510
+ if (!pattern) {
511
+ return logger.error('Must include a URL pattern to ignore.')
512
+ }
547
513
 
548
514
  this.agent.userNormalizer.addSimple(pattern, null)
549
515
  }
@@ -564,12 +530,12 @@ API.prototype.addIgnoringRule = function addIgnoringRule(pattern) {
564
530
  * @returns {string} The `<script>` header to be injected.
565
531
  */
566
532
  API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options) {
567
- var metric = this.agent.metrics.getOrCreateMetric(
533
+ const metric = this.agent.metrics.getOrCreateMetric(
568
534
  NAMES.SUPPORTABILITY.API + '/getBrowserTimingHeader'
569
535
  )
570
536
  metric.incrementCallCount()
571
537
 
572
- var config = this.agent.config
538
+ const config = this.agent.config
573
539
 
574
540
  /**
575
541
  * Gracefully fail.
@@ -591,62 +557,74 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
591
557
  return '<!-- NREUM: (' + num + ') -->'
592
558
  }
593
559
 
594
- var browser_monitoring = config.browser_monitoring
560
+ const browserMonitoring = config.browser_monitoring
595
561
 
596
562
  // config.browser_monitoring should always exist, but we don't want the agent
597
563
  // to bail here if something goes wrong
598
- if (!browser_monitoring) return _gracefail(2)
564
+ if (!browserMonitoring) {
565
+ return _gracefail(2)
566
+ }
599
567
 
600
568
  /* Can control header generation with configuration this setting is only
601
569
  * available in the newrelic.js config file, it is not ever set by the
602
570
  * server.
603
571
  */
604
- if (!browser_monitoring.enable) {
572
+ if (!browserMonitoring.enable) {
605
573
  // It has been disabled by the user; no need to warn them about their own
606
574
  // settings so fail quietly and gracefully.
607
575
  return _gracefail(0, true)
608
576
  }
609
577
 
610
- var trans = this.agent.getTransaction()
578
+ const trans = this.agent.getTransaction()
611
579
 
612
580
  // bail gracefully outside a transaction
613
- if (!trans || trans.isIgnored()) return _gracefail(1)
581
+ if (!trans || trans.isIgnored()) {
582
+ return _gracefail(1)
583
+ }
614
584
 
615
- var name = trans.getFullName()
585
+ const name = trans.getFullName()
616
586
 
617
587
  /* If we're in an unnamed transaction, add a friendly warning this is to
618
588
  * avoid people going crazy, trying to figure out why browser monitoring is
619
589
  * not working when they're missing a transaction name.
620
590
  */
621
- if (!name) return _gracefail(3)
591
+ if (!name) {
592
+ return _gracefail(3)
593
+ }
622
594
 
623
- var time = trans.timer.getDurationInMillis()
595
+ const time = trans.timer.getDurationInMillis()
624
596
 
625
597
  /*
626
598
  * Only the first 13 chars of the license should be used for hashing with
627
599
  * the transaction name.
628
600
  */
629
- var key = config.license_key.substr(0, 13)
630
- var appid = config.application_id
601
+ const key = config.license_key.substr(0, 13)
602
+ const appid = config.application_id
631
603
 
632
604
  /* This is only going to work if the agent has successfully handshaked with
633
605
  * the collector. If the networks is bad, or there is no license key set in
634
606
  * newrelic.js, there will be no application_id set. We bail instead of
635
607
  * outputting null/undefined configuration values.
636
608
  */
637
- if (!appid) return _gracefail(4)
609
+ if (!appid) {
610
+ return _gracefail(4)
611
+ }
638
612
 
639
613
  /* If there is no browser_key, the server has likely decided to disable
640
614
  * browser monitoring.
641
615
  */
642
- var licenseKey = browser_monitoring.browser_key
643
- if (!licenseKey) return _gracefail(5)
616
+ const licenseKey = browserMonitoring.browser_key
617
+ if (!licenseKey) {
618
+ return _gracefail(5)
619
+ }
644
620
 
645
621
  /* If there is no agent_loader script, there is no point
646
622
  * in setting the rum data
647
623
  */
648
- var js_agent_loader = browser_monitoring.js_agent_loader
649
- if (!js_agent_loader) return _gracefail(6)
624
+ const jsAgentLoader = browserMonitoring.js_agent_loader
625
+ if (!jsAgentLoader) {
626
+ return _gracefail(6)
627
+ }
650
628
 
651
629
  /* If rum is enabled, but then later disabled on the server,
652
630
  * this is the only parameter that gets updated.
@@ -655,14 +633,16 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
655
633
  * the lifetime of an application, and it should be picked up
656
634
  * on the next ForceRestart by the collector.
657
635
  */
658
- var loader = browser_monitoring.loader
659
- if (loader === 'none') return _gracefail(7)
636
+ const loader = browserMonitoring.loader
637
+ if (loader === 'none') {
638
+ return _gracefail(7)
639
+ }
660
640
 
661
641
  // This hash gets written directly into the browser.
662
- var rum_hash = {
663
- agent: browser_monitoring.js_agent_file,
664
- beacon: browser_monitoring.beacon,
665
- errorBeacon: browser_monitoring.error_beacon,
642
+ const rumHash = {
643
+ agent: browserMonitoring.js_agent_file,
644
+ beacon: browserMonitoring.beacon,
645
+ errorBeacon: browserMonitoring.error_beacon,
666
646
  licenseKey: licenseKey,
667
647
  applicationID: appid,
668
648
  applicationTime: time,
@@ -674,7 +654,7 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
674
654
  agentToken: null
675
655
  }
676
656
 
677
- var attrs = Object.create(null)
657
+ const attrs = Object.create(null)
678
658
 
679
659
  const customAttrs = trans.trace.custom.get(ATTR_DEST.BROWSER_EVENT)
680
660
  if (!properties.isEmpty(customAttrs)) {
@@ -687,23 +667,18 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
687
667
  }
688
668
 
689
669
  if (!properties.isEmpty(attrs)) {
690
- rum_hash.atts = hashes.obfuscateNameUsingKey(JSON.stringify(attrs), key)
670
+ rumHash.atts = hashes.obfuscateNameUsingKey(JSON.stringify(attrs), key)
691
671
  }
692
672
 
693
673
  // if debugging, do pretty format of JSON
694
- var tabs = config.browser_monitoring.debug ? 2 : 0
695
- var json = JSON.stringify(rum_hash, null, tabs)
674
+ const tabs = config.browser_monitoring.debug ? 2 : 0
675
+ const json = JSON.stringify(rumHash, null, tabs)
696
676
 
697
677
  // set nonce attribute if passed in options
698
- var nonce = options && options.nonce ? 'nonce="' + options.nonce + '"' : ''
678
+ const nonce = options && options.nonce ? 'nonce="' + options.nonce + '"' : ''
699
679
 
700
680
  // the complete header to be written to the browser
701
- var out = util.format(
702
- RUM_STUB,
703
- nonce,
704
- json,
705
- js_agent_loader
706
- )
681
+ const out = util.format(RUM_STUB, nonce, json, jsAgentLoader)
707
682
 
708
683
  logger.trace('generating RUM header', out)
709
684
 
@@ -745,9 +720,9 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
745
720
  * @return {*} Returns the result of calling `handler`.
746
721
  */
747
722
  API.prototype.startSegment = function startSegment(name, record, handler, callback) {
748
- this.agent.metrics.getOrCreateMetric(
749
- NAMES.SUPPORTABILITY.API + '/startSegment'
750
- ).incrementCallCount()
723
+ this.agent.metrics
724
+ .getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/startSegment')
725
+ .incrementCallCount()
751
726
 
752
727
  // Check that we have usable arguments.
753
728
  if (!name || typeof handler !== 'function') {
@@ -769,7 +744,7 @@ API.prototype.startSegment = function startSegment(name, record, handler, callba
769
744
  }
770
745
 
771
746
  // Create the segment and call the handler.
772
- var wrappedHandler = this.shim.record(handler, function handlerNamer(shim) {
747
+ const wrappedHandler = this.shim.record(handler, function handlerNamer(shim) {
773
748
  return {
774
749
  name: name,
775
750
  recorder: record ? customRecorder : null,
@@ -809,7 +784,7 @@ API.prototype.startSegment = function startSegment(name, record, handler, callba
809
784
  * Function that represents the transaction work.
810
785
  */
811
786
  API.prototype.startWebTransaction = function startWebTransaction(url, handle) {
812
- var metric = this.agent.metrics.getOrCreateMetric(
787
+ const metric = this.agent.metrics.getOrCreateMetric(
813
788
  NAMES.SUPPORTABILITY.API + '/startWebTransaction'
814
789
  )
815
790
  metric.incrementCallCount()
@@ -824,29 +799,21 @@ API.prototype.startWebTransaction = function startWebTransaction(url, handle) {
824
799
  return handle()
825
800
  }
826
801
 
827
- logger.debug(
828
- 'starting web transaction %s (%s).',
829
- url,
830
- handle && handle.name
831
- )
802
+ logger.debug('starting web transaction %s (%s).', url, handle && handle.name)
832
803
 
833
- var shim = this.shim
834
- var tracer = this.agent.tracer
835
- var parent = tracer.getTransaction()
804
+ const shim = this.shim
805
+ const tracer = this.agent.tracer
806
+ const parent = tracer.getTransaction()
836
807
 
837
808
  return tracer.transactionNestProxy('web', function startWebSegment() {
838
- var tx = tracer.getTransaction()
809
+ const tx = tracer.getTransaction()
839
810
 
840
811
  if (!tx) {
841
812
  return handle.apply(this, arguments)
842
813
  }
843
814
 
844
815
  if (tx === parent) {
845
- logger.debug(
846
- 'not creating nested transaction %s using transaction %s',
847
- url,
848
- tx.id
849
- )
816
+ logger.debug('not creating nested transaction %s using transaction %s', url, tx.id)
850
817
  return tracer.addSegment(url, null, null, true, handle)
851
818
  }
852
819
 
@@ -862,8 +829,8 @@ API.prototype.startWebTransaction = function startWebTransaction(url, handle) {
862
829
  tx.baseSegment = tracer.createSegment(url, recordWeb)
863
830
  tx.baseSegment.start()
864
831
 
865
- var boundHandle = tracer.bindFunction(handle, tx.baseSegment)
866
- var returnResult = boundHandle.call(this)
832
+ const boundHandle = tracer.bindFunction(handle, tx.baseSegment)
833
+ let returnResult = boundHandle.call(this)
867
834
  if (returnResult && shim.isPromise(returnResult)) {
868
835
  returnResult = shim.interceptPromise(returnResult, tx.end.bind(tx))
869
836
  } else if (!tx.handledExternally) {
@@ -912,7 +879,7 @@ API.prototype.startBackgroundTransaction = startBackgroundTransaction
912
879
  * @memberOf API#
913
880
  */
914
881
  function startBackgroundTransaction(name, group, handle) {
915
- var metric = this.agent.metrics.getOrCreateMetric(
882
+ const metric = this.agent.metrics.getOrCreateMetric(
916
883
  NAMES.SUPPORTABILITY.API + '/startBackgroundTransaction'
917
884
  )
918
885
  metric.incrementCallCount()
@@ -932,31 +899,22 @@ function startBackgroundTransaction(name, group, handle) {
932
899
  return handle()
933
900
  }
934
901
 
935
- logger.debug(
936
- 'starting background transaction %s:%s (%s)',
937
- name,
938
- group,
939
- handle && handle.name
940
- )
902
+ logger.debug('starting background transaction %s:%s (%s)', name, group, handle && handle.name)
941
903
 
942
- var tracer = this.agent.tracer
943
- var shim = this.shim
944
- var txName = group + '/' + name
945
- var parent = tracer.getTransaction()
904
+ const tracer = this.agent.tracer
905
+ const shim = this.shim
906
+ const txName = group + '/' + name
907
+ const parent = tracer.getTransaction()
946
908
 
947
909
  return tracer.transactionNestProxy('bg', function startBackgroundSegment() {
948
- var tx = tracer.getTransaction()
910
+ const tx = tracer.getTransaction()
949
911
 
950
912
  if (!tx) {
951
913
  return handle.apply(this, arguments)
952
914
  }
953
915
 
954
916
  if (tx === parent) {
955
- logger.debug(
956
- 'not creating nested transaction %s using transaction %s',
957
- txName,
958
- tx.id
959
- )
917
+ logger.debug('not creating nested transaction %s using transaction %s', txName, tx.id)
960
918
  return tracer.addSegment(txName, null, null, true, handle)
961
919
  }
962
920
 
@@ -973,8 +931,8 @@ function startBackgroundTransaction(name, group, handle) {
973
931
  tx.baseSegment.partialName = group
974
932
  tx.baseSegment.start()
975
933
 
976
- var boundHandle = tracer.bindFunction(handle, tx.baseSegment)
977
- var returnResult = boundHandle.call(this)
934
+ const boundHandle = tracer.bindFunction(handle, tx.baseSegment)
935
+ let returnResult = boundHandle.call(this)
978
936
  if (returnResult && shim.isPromise(returnResult)) {
979
937
  returnResult = shim.interceptPromise(returnResult, tx.end.bind(tx))
980
938
  } else if (!tx.handledExternally) {
@@ -990,13 +948,11 @@ function startBackgroundTransaction(name, group, handle) {
990
948
  * the correct transaction context when called.
991
949
  */
992
950
  API.prototype.endTransaction = function endTransaction() {
993
- var metric = this.agent.metrics.getOrCreateMetric(
994
- NAMES.SUPPORTABILITY.API + '/endTransaction'
995
- )
951
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/endTransaction')
996
952
  metric.incrementCallCount()
997
953
 
998
- var tracer = this.agent.tracer
999
- var tx = tracer.getTransaction()
954
+ const tracer = this.agent.tracer
955
+ const tx = tracer.getTransaction()
1000
956
 
1001
957
  if (tx) {
1002
958
  if (tx.baseSegment) {
@@ -1053,7 +1009,7 @@ API.prototype.recordMetric = function recordMetric(name, value) {
1053
1009
 
1054
1010
  const stats = Object.create(null)
1055
1011
  const required = ['count', 'total', 'min', 'max', 'sumOfSquares']
1056
- const keyMap = {count: 'callCount'}
1012
+ const keyMap = { count: 'callCount' }
1057
1013
 
1058
1014
  for (let i = 0, l = required.length; i < l; ++i) {
1059
1015
  if (typeof value[required[i]] !== 'number') {
@@ -1084,9 +1040,7 @@ API.prototype.recordMetric = function recordMetric(name, value) {
1084
1040
  * by. Defaults to 1.
1085
1041
  */
1086
1042
  API.prototype.incrementMetric = function incrementMetric(name, value) {
1087
- const metric = this.agent.metrics.getOrCreateMetric(
1088
- NAMES.SUPPORTABILITY.API + '/incrementMetric'
1089
- )
1043
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/incrementMetric')
1090
1044
  metric.incrementCallCount()
1091
1045
 
1092
1046
  if (!value && value !== 0) {
@@ -1117,22 +1071,17 @@ API.prototype.incrementMetric = function incrementMetric(name, value) {
1117
1071
  * or boolean.
1118
1072
  */
1119
1073
  API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attributes) {
1120
- var metric = this.agent.metrics.getOrCreateMetric(
1074
+ const metric = this.agent.metrics.getOrCreateMetric(
1121
1075
  NAMES.SUPPORTABILITY.API + '/recordCustomEvent'
1122
1076
  )
1123
1077
  metric.incrementCallCount()
1124
1078
 
1125
1079
  // If high security mode is on, custom events are disabled.
1126
1080
  if (this.agent.config.high_security) {
1127
- logger.warnOnce(
1128
- "Custom Event",
1129
- "Custom events are disabled by high security mode."
1130
- )
1081
+ logger.warnOnce('Custom Event', 'Custom events are disabled by high security mode.')
1131
1082
  return false
1132
1083
  } else if (!this.agent.config.api.custom_events_enabled) {
1133
- logger.debug(
1134
- "Config.api.custom_events_enabled set to false, not collecting value"
1135
- )
1084
+ logger.debug('Config.api.custom_events_enabled set to false, not collecting value')
1136
1085
  return false
1137
1086
  }
1138
1087
 
@@ -1141,7 +1090,7 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1141
1090
  }
1142
1091
  // Check all the arguments before bailing to give maximum information in a
1143
1092
  // single invocation.
1144
- var fail = false
1093
+ let fail = false
1145
1094
 
1146
1095
  if (!eventType || typeof eventType !== 'string') {
1147
1096
  logger.warn(
@@ -1186,13 +1135,13 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1186
1135
  // Filter all object type valued attributes out
1187
1136
  const filteredAttributes = _filterAttributes(attributes, `${eventType} custom event`)
1188
1137
 
1189
- var instrinics = {
1138
+ const instrinics = {
1190
1139
  type: eventType,
1191
1140
  timestamp: Date.now()
1192
1141
  }
1193
1142
 
1194
- var tx = this.agent.getTransaction()
1195
- var priority = tx && tx.priority || Math.random()
1143
+ const tx = this.agent.getTransaction()
1144
+ const priority = (tx && tx.priority) || Math.random()
1196
1145
  this.agent.customEventAggregator.add([instrinics, filteredAttributes], priority)
1197
1146
  }
1198
1147
 
@@ -1216,12 +1165,10 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1216
1165
  * this function.
1217
1166
  */
1218
1167
  API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
1219
- var metric = this.agent.metrics.getOrCreateMetric(
1220
- NAMES.SUPPORTABILITY.API + '/instrument'
1221
- )
1168
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/instrument')
1222
1169
  metric.incrementCallCount()
1223
1170
 
1224
- var opts = moduleName
1171
+ let opts = moduleName
1225
1172
  if (typeof opts === 'string') {
1226
1173
  opts = {
1227
1174
  moduleName: moduleName,
@@ -1253,15 +1200,18 @@ API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
1253
1200
  * If provided, should `onRequire` throw an error, the error will be passed to
1254
1201
  * this function.
1255
1202
  */
1256
- API.prototype.instrumentConglomerate =
1257
- function instrumentConglomerate(moduleName, onRequire, onError) {
1258
- this.agent.metrics.getOrCreateMetric(
1259
- NAMES.SUPPORTABILITY.API + '/instrumentConglomerate'
1260
- ).incrementCallCount()
1203
+ API.prototype.instrumentConglomerate = function instrumentConglomerate(
1204
+ moduleName,
1205
+ onRequire,
1206
+ onError
1207
+ ) {
1208
+ this.agent.metrics
1209
+ .getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/instrumentConglomerate')
1210
+ .incrementCallCount()
1261
1211
 
1262
1212
  let opts = moduleName
1263
1213
  if (typeof opts === 'string') {
1264
- opts = {moduleName, onRequire, onError}
1214
+ opts = { moduleName, onRequire, onError }
1265
1215
  }
1266
1216
 
1267
1217
  opts.type = MODULE_TYPE.CONGLOMERATE
@@ -1287,14 +1237,13 @@ function instrumentConglomerate(moduleName, onRequire, onError) {
1287
1237
  * If provided, should `onRequire` throw an error, the error will be passed to
1288
1238
  * this function.
1289
1239
  */
1290
- API.prototype.instrumentDatastore =
1291
- function instrumentDatastore(moduleName, onRequire, onError) {
1292
- var metric = this.agent.metrics.getOrCreateMetric(
1240
+ API.prototype.instrumentDatastore = function instrumentDatastore(moduleName, onRequire, onError) {
1241
+ const metric = this.agent.metrics.getOrCreateMetric(
1293
1242
  NAMES.SUPPORTABILITY.API + '/instrumentDatastore'
1294
1243
  )
1295
1244
  metric.incrementCallCount()
1296
1245
 
1297
- var opts = moduleName
1246
+ let opts = moduleName
1298
1247
  if (typeof opts === 'string') {
1299
1248
  opts = {
1300
1249
  moduleName: moduleName,
@@ -1325,9 +1274,8 @@ function instrumentDatastore(moduleName, onRequire, onError) {
1325
1274
  * @param {object} module
1326
1275
  * The actual module object or function we're instrumenting
1327
1276
  */
1328
- API.prototype.instrumentLoadedModule =
1329
- function instrumentLoadedModule(moduleName, module) {
1330
- var metric = this.agent.metrics.getOrCreateMetric(
1277
+ API.prototype.instrumentLoadedModule = function instrumentLoadedModule(moduleName, module) {
1278
+ const metric = this.agent.metrics.getOrCreateMetric(
1331
1279
  NAMES.SUPPORTABILITY.API + '/instrumentLoadedModule'
1332
1280
  )
1333
1281
  metric.incrementCallCount()
@@ -1357,10 +1305,7 @@ function instrumentLoadedModule(moduleName, module) {
1357
1305
 
1358
1306
  return true
1359
1307
  } catch (error) {
1360
- logger.error(
1361
- 'instrumentLoadedModule encountered an error, module not instrumentend: %s',
1362
- error
1363
- )
1308
+ logger.error('instrumentLoadedModule encountered an error, module not instrumentend: %s', error)
1364
1309
  }
1365
1310
  }
1366
1311
 
@@ -1383,14 +1328,17 @@ function instrumentLoadedModule(moduleName, module) {
1383
1328
  * If provided, should `onRequire` throw an error, the error will be passed to
1384
1329
  * this function.
1385
1330
  */
1386
- API.prototype.instrumentWebframework =
1387
- function instrumentWebframework(moduleName, onRequire, onError) {
1388
- var metric = this.agent.metrics.getOrCreateMetric(
1331
+ API.prototype.instrumentWebframework = function instrumentWebframework(
1332
+ moduleName,
1333
+ onRequire,
1334
+ onError
1335
+ ) {
1336
+ const metric = this.agent.metrics.getOrCreateMetric(
1389
1337
  NAMES.SUPPORTABILITY.API + '/instrumentWebframework'
1390
1338
  )
1391
1339
  metric.incrementCallCount()
1392
1340
 
1393
- var opts = moduleName
1341
+ let opts = moduleName
1394
1342
  if (typeof opts === 'string') {
1395
1343
  opts = {
1396
1344
  moduleName: moduleName,
@@ -1422,14 +1370,13 @@ function instrumentWebframework(moduleName, onRequire, onError) {
1422
1370
  * If provided, should `onRequire` throw an error, the error will be passed to
1423
1371
  * this function.
1424
1372
  */
1425
- API.prototype.instrumentMessages =
1426
- function instrumentMessages(moduleName, onRequire, onError) {
1427
- var metric = this.agent.metrics.getOrCreateMetric(
1373
+ API.prototype.instrumentMessages = function instrumentMessages(moduleName, onRequire, onError) {
1374
+ const metric = this.agent.metrics.getOrCreateMetric(
1428
1375
  NAMES.SUPPORTABILITY.API + '/instrumentMessages'
1429
1376
  )
1430
1377
  metric.incrementCallCount()
1431
1378
 
1432
- var opts = moduleName
1379
+ let opts = moduleName
1433
1380
  if (typeof opts === 'string') {
1434
1381
  opts = {
1435
1382
  moduleName: moduleName,
@@ -1448,7 +1395,7 @@ function instrumentMessages(moduleName, onRequire, onError) {
1448
1395
  * @returns {*} The object containing the current trace and span ids
1449
1396
  */
1450
1397
  API.prototype.getTraceMetadata = function getTraceMetadata() {
1451
- var metric = this.agent.metrics.getOrCreateMetric(
1398
+ const metric = this.agent.metrics.getOrCreateMetric(
1452
1399
  NAMES.SUPPORTABILITY.API + '/getTraceMetadata'
1453
1400
  )
1454
1401
  metric.incrementCallCount()
@@ -1457,9 +1404,9 @@ API.prototype.getTraceMetadata = function getTraceMetadata() {
1457
1404
 
1458
1405
  const segment = this.agent.tracer.getSegment()
1459
1406
  if (!segment) {
1460
- logger.debug("No transaction found when calling API#getTraceMetadata")
1407
+ logger.debug('No transaction found when calling API#getTraceMetadata')
1461
1408
  } else if (!this.agent.config.distributed_tracing.enabled) {
1462
- logger.debug("Distributed tracing disabled when calling API#getTraceMetadata")
1409
+ logger.debug('Distributed tracing disabled when calling API#getTraceMetadata')
1463
1410
  } else {
1464
1411
  metadata.traceId = segment.transaction.traceId
1465
1412
 
@@ -1492,8 +1439,7 @@ API.prototype.getTraceMetadata = function getTraceMetadata() {
1492
1439
  * Callback function that runs when agent stops.
1493
1440
  */
1494
1441
  API.prototype.shutdown = function shutdown(options, cb) {
1495
- this.agent.metrics.getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/shutdown`)
1496
- .incrementCallCount()
1442
+ this.agent.metrics.getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/shutdown`).incrementCallCount()
1497
1443
 
1498
1444
  let callback = cb
1499
1445
  if (typeof options === 'function') {
@@ -1529,10 +1475,7 @@ function _doShutdown(api, options, callback) {
1529
1475
 
1530
1476
  function afterHarvest(error) {
1531
1477
  if (error) {
1532
- logger.error(
1533
- error,
1534
- 'An error occurred while running last harvest before shutdown.'
1535
- )
1478
+ logger.error(error, 'An error occurred while running last harvest before shutdown.')
1536
1479
  }
1537
1480
  agent.stop(callback)
1538
1481
  }
@@ -1543,10 +1486,7 @@ function _doShutdown(api, options, callback) {
1543
1486
  agent.stop(callback)
1544
1487
  }, options.timeout).unref()
1545
1488
  } else if (options.timeout) {
1546
- logger.warn(
1547
- 'options.timeout should be of type "number". Got %s',
1548
- typeof options.timeout
1549
- )
1489
+ logger.warn('options.timeout should be of type "number". Got %s', typeof options.timeout)
1550
1490
  }
1551
1491
 
1552
1492
  agent.on('started', function shutdownHarvest() {
@@ -1556,10 +1496,7 @@ function _doShutdown(api, options, callback) {
1556
1496
  agent.on('errored', function logShutdownError(error) {
1557
1497
  agent.stop(callback)
1558
1498
  if (error) {
1559
- logger.error(
1560
- error,
1561
- 'The agent encountered an error after calling shutdown.'
1562
- )
1499
+ logger.error(error, 'The agent encountered an error after calling shutdown.')
1563
1500
  }
1564
1501
  })
1565
1502
  } else if (options.collectPendingData) {
@@ -1570,11 +1507,11 @@ function _doShutdown(api, options, callback) {
1570
1507
  }
1571
1508
 
1572
1509
  function _checkKeyLength(object, maxLength) {
1573
- var keys = Object.keys(object)
1574
- var badKey = false
1575
- var len = keys.length
1576
- var key = '' // init to string because gotta go fast
1577
- for (var i = 0; i < len; i++) {
1510
+ const keys = Object.keys(object)
1511
+ let badKey = false
1512
+ const len = keys.length
1513
+ let key = '' // init to string because gotta go fast
1514
+ for (let i = 0; i < len; i++) {
1578
1515
  key = keys[i]
1579
1516
  if (key.length > maxLength) {
1580
1517
  logger.warn(
@@ -1603,7 +1540,7 @@ function _filterAttributes(attributes, name) {
1603
1540
  if (!isValidType(attributes[attributeKey])) {
1604
1541
  logger.info(
1605
1542
  `Omitting attribute ${attributeKey} from ${name} call, type must ` +
1606
- 'be boolean, number, or string'
1543
+ 'be boolean, number, or string'
1607
1544
  )
1608
1545
  return
1609
1546
  }