newrelic 7.5.2 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/NEWS.md +4989 -4886
  2. package/THIRD_PARTY_NOTICES.md +625 -216
  3. package/api.js +105 -174
  4. package/bin/test-naming-rules.js +38 -32
  5. package/bin/tracetractor +0 -1
  6. package/index.js +12 -18
  7. package/lib/agent.js +108 -111
  8. package/lib/aggregators/base-aggregator.js +1 -1
  9. package/lib/aggregators/event-aggregator.js +6 -6
  10. package/lib/attributes.js +12 -13
  11. package/lib/collector/api.js +32 -42
  12. package/lib/collector/facts.js +67 -65
  13. package/lib/collector/http-agents.js +30 -27
  14. package/lib/collector/parse-response.js +1 -2
  15. package/lib/collector/remote-method.js +43 -36
  16. package/lib/collector/serverless.js +13 -18
  17. package/lib/collector/ssl/certificates.js +1056 -1056
  18. package/lib/config/attribute-filter.js +90 -82
  19. package/lib/config/default.js +30 -18
  20. package/lib/config/env.js +17 -12
  21. package/lib/config/harvest-config-validator.js +1 -1
  22. package/lib/config/index.js +160 -177
  23. package/lib/config/merge-server-config.js +7 -5
  24. package/lib/custom-events/custom-event-aggregator.js +1 -1
  25. package/lib/db/parse-sql.js +6 -9
  26. package/lib/db/parsed-statement.js +6 -13
  27. package/lib/db/query-parsers/sql.js +6 -9
  28. package/lib/db/query-sample.js +7 -3
  29. package/lib/db/query-trace-aggregator.js +12 -12
  30. package/lib/db/utils.js +1 -1
  31. package/lib/environment.js +173 -138
  32. package/lib/errors/error-collector.js +18 -31
  33. package/lib/errors/error-event-aggregator.js +1 -1
  34. package/lib/errors/error-trace-aggregator.js +2 -3
  35. package/lib/errors/helper.js +21 -30
  36. package/lib/errors/index.js +16 -28
  37. package/lib/feature_flags.js +5 -8
  38. package/lib/grpc/connection/states.js +6 -6
  39. package/lib/grpc/connection.js +35 -46
  40. package/lib/header-attributes.js +49 -53
  41. package/lib/instrumentation/amqplib.js +8 -17
  42. package/lib/instrumentation/bluebird.js +61 -20
  43. package/lib/instrumentation/cassandra-driver.js +2 -2
  44. package/lib/instrumentation/connect.js +4 -3
  45. package/lib/instrumentation/core/async_hooks.js +11 -4
  46. package/lib/instrumentation/core/child_process.js +20 -28
  47. package/lib/instrumentation/core/crypto.js +1 -7
  48. package/lib/instrumentation/core/dns.js +3 -7
  49. package/lib/instrumentation/core/domain.js +2 -8
  50. package/lib/instrumentation/core/fs.js +22 -37
  51. package/lib/instrumentation/core/globals.js +3 -7
  52. package/lib/instrumentation/core/http-outbound.js +15 -40
  53. package/lib/instrumentation/core/http.js +29 -63
  54. package/lib/instrumentation/core/inspector.js +6 -10
  55. package/lib/instrumentation/core/net.js +3 -1
  56. package/lib/instrumentation/core/timers.js +17 -24
  57. package/lib/instrumentation/core/zlib.js +2 -10
  58. package/lib/instrumentation/express.js +4 -2
  59. package/lib/instrumentation/fastify/spec-builders.js +5 -0
  60. package/lib/instrumentation/fastify.js +37 -10
  61. package/lib/instrumentation/hapi/hapi-17.js +9 -10
  62. package/lib/instrumentation/hapi.js +15 -15
  63. package/lib/instrumentation/ioredis.js +1 -2
  64. package/lib/instrumentation/memcached.js +39 -43
  65. package/lib/instrumentation/mongodb/common.js +218 -0
  66. package/lib/instrumentation/mongodb/constants.js +87 -0
  67. package/lib/instrumentation/mongodb/v2-mongo.js +110 -0
  68. package/lib/instrumentation/mongodb/v3-mongo.js +80 -0
  69. package/lib/instrumentation/mongodb/v4-mongo.js +90 -0
  70. package/lib/instrumentation/mongodb.js +20 -312
  71. package/lib/instrumentation/mysql.js +33 -26
  72. package/lib/instrumentation/oracle.js +10 -14
  73. package/lib/instrumentation/pg.js +30 -21
  74. package/lib/instrumentation/promise.js +20 -17
  75. package/lib/instrumentation/redis.js +30 -30
  76. package/lib/instrumentation/when.js +9 -1
  77. package/lib/instrumentations.js +24 -24
  78. package/lib/logger.js +1 -1
  79. package/lib/metrics/index.js +37 -17
  80. package/lib/metrics/mapper.js +9 -9
  81. package/lib/metrics/metric-aggregator.js +5 -10
  82. package/lib/metrics/names.js +8 -7
  83. package/lib/metrics/normalizer/rule.js +6 -7
  84. package/lib/metrics/normalizer/tx_segment.js +17 -13
  85. package/lib/metrics/normalizer.js +30 -33
  86. package/lib/metrics/recorders/custom.js +3 -1
  87. package/lib/metrics/recorders/distributed-trace.js +3 -18
  88. package/lib/metrics/recorders/generic.js +3 -2
  89. package/lib/metrics/recorders/http.js +4 -6
  90. package/lib/metrics/recorders/http_external.js +1 -3
  91. package/lib/metrics/recorders/message-transaction.js +2 -12
  92. package/lib/metrics/recorders/other.js +2 -12
  93. package/lib/parse-proc-cpuinfo.js +11 -16
  94. package/lib/parse-proc-meminfo.js +5 -3
  95. package/lib/prioritized-attributes.js +12 -17
  96. package/lib/priority-queue.js +1 -1
  97. package/lib/proxy/grpc.js +1 -1
  98. package/lib/reservoir.js +9 -3
  99. package/lib/sampler.js +12 -13
  100. package/lib/serverless/api-gateway.js +3 -3
  101. package/lib/serverless/aws-lambda.js +28 -37
  102. package/lib/shim/conglomerate-shim.js +4 -4
  103. package/lib/shim/datastore-shim.js +29 -38
  104. package/lib/shim/index.js +8 -9
  105. package/lib/shim/message-shim.js +111 -113
  106. package/lib/shim/promise-shim.js +18 -13
  107. package/lib/shim/shim.js +72 -66
  108. package/lib/shim/specs/index.js +18 -19
  109. package/lib/shim/transaction-shim.js +26 -36
  110. package/lib/shim/webframework-shim.js +25 -35
  111. package/lib/shimmer.js +184 -166
  112. package/lib/spans/create-span-event-aggregator.js +24 -44
  113. package/lib/spans/span-context.js +4 -10
  114. package/lib/spans/span-event-aggregator.js +68 -13
  115. package/lib/spans/span-event.js +5 -7
  116. package/lib/spans/span-streamer.js +10 -18
  117. package/lib/spans/streaming-span-event-aggregator.js +1 -1
  118. package/lib/spans/streaming-span-event.js +4 -4
  119. package/lib/stats/apdex.js +5 -11
  120. package/lib/stats/index.js +12 -17
  121. package/lib/system-info.js +7 -3
  122. package/lib/timer.js +30 -16
  123. package/lib/transaction/dt-payload.js +1 -1
  124. package/lib/transaction/handle.js +19 -19
  125. package/lib/transaction/index.js +94 -112
  126. package/lib/transaction/name-state.js +5 -6
  127. package/lib/transaction/trace/aggregator.js +78 -73
  128. package/lib/transaction/trace/exclusive-time-calculator.js +5 -9
  129. package/lib/transaction/trace/index.js +26 -24
  130. package/lib/transaction/trace/segment.js +39 -56
  131. package/lib/transaction/tracecontext.js +37 -45
  132. package/lib/transaction/tracer/index.js +79 -44
  133. package/lib/transaction/transaction-event-aggregator.js +29 -31
  134. package/lib/uninstrumented.js +4 -5
  135. package/lib/util/attribute-types.js +1 -5
  136. package/lib/util/byte-limit.js +0 -1
  137. package/lib/util/cat.js +5 -13
  138. package/lib/util/codec.js +8 -4
  139. package/lib/util/deep-equal.js +48 -18
  140. package/lib/util/flatten.js +5 -2
  141. package/lib/util/hashes.js +2 -2
  142. package/lib/util/label-parser.js +7 -13
  143. package/lib/util/logger.js +31 -13
  144. package/lib/util/process-version.js +1 -1
  145. package/lib/util/properties.js +1 -1
  146. package/lib/util/sql/obfuscate.js +7 -17
  147. package/lib/util/stream-sink.js +2 -3
  148. package/lib/util/urltils.js +9 -13
  149. package/lib/utilization/aws-info.js +2 -3
  150. package/lib/utilization/azure-info.js +32 -30
  151. package/lib/utilization/common.js +5 -4
  152. package/lib/utilization/docker-info.js +4 -6
  153. package/lib/utilization/gcp-info.js +36 -35
  154. package/lib/utilization/index.js +1 -1
  155. package/lib/utilization/kubernetes-info.js +2 -2
  156. package/lib/utilization/pcf-info.js +4 -4
  157. package/package.json +32 -18
  158. package/stub_api.js +8 -6
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
 
@@ -90,12 +88,9 @@ API.prototype.setTransactionName = function setTransactionName(name) {
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
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/getTransaction')
123
116
  metric.incrementCallCount()
124
117
 
125
118
  var 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
+ var 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,19 @@ 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(
243
- NAMES.SUPPORTABILITY.API + '/setControllerName'
244
- )
233
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/setControllerName')
245
234
  metric.incrementCallCount()
246
235
 
247
236
  var transaction = this.agent.tracer.getTransaction()
248
237
  if (!transaction) {
249
- return logger.warn("No transaction found when setting controller to %s.", name)
238
+ return logger.warn('No transaction found when setting controller to %s.', name)
250
239
  }
251
240
 
252
241
  if (!name) {
253
242
  if (transaction && transaction.url) {
254
- logger.error(
255
- "Must include name in setControllerName call for URL %s.",
256
- transaction.url
257
- )
243
+ logger.error('Must include name in setControllerName call for URL %s.', transaction.url)
258
244
  } else {
259
- logger.error("Must include name in setControllerName call.")
245
+ logger.error('Must include name in setControllerName call.')
260
246
  }
261
247
 
262
248
  return
@@ -266,7 +252,6 @@ API.prototype.setControllerName = function setControllerName(name, action) {
266
252
  transaction.forceName = NAMES.CONTROLLER + '/' + name + '/' + action
267
253
  }
268
254
 
269
-
270
255
  /**
271
256
  * Add a custom attribute to the current transaction. Some attributes are
272
257
  * reserved (see CUSTOM_DENYLIST for the current, very short list), and
@@ -284,15 +269,10 @@ API.prototype.addCustomAttribute = function addCustomAttribute(key, value) {
284
269
 
285
270
  // If high security mode is on, custom attributes are disabled.
286
271
  if (this.agent.config.high_security) {
287
- logger.warnOnce(
288
- 'Custom attributes',
289
- 'Custom attributes are disabled by high security mode.'
290
- )
272
+ logger.warnOnce('Custom attributes', 'Custom attributes are disabled by high security mode.')
291
273
  return false
292
274
  } 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
- )
275
+ logger.debug('Config.api.custom_attributes_enabled set to false, not collecting value')
296
276
  return false
297
277
  }
298
278
 
@@ -304,10 +284,7 @@ API.prototype.addCustomAttribute = function addCustomAttribute(key, value) {
304
284
 
305
285
  const trace = transaction.trace
306
286
  if (!trace.custom) {
307
- logger.warn(
308
- 'Could not add attribute %s to nonexistent custom attributes.',
309
- key
310
- )
287
+ logger.warn('Could not add attribute %s to nonexistent custom attributes.', key)
311
288
  return false
312
289
  }
313
290
 
@@ -406,19 +383,14 @@ API.prototype.addCustomSpanAttribute = function addCustomSpanAttribute(key, valu
406
383
  )
407
384
  return false
408
385
  } 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
- )
386
+ logger.debug('Config.api.custom_attributes_enabled set to false, not collecting value')
412
387
  return false
413
388
  }
414
389
 
415
390
  const spanContext = this.agent.tracer.getSpanContext()
416
391
 
417
392
  if (!spanContext) {
418
- logger.debug(
419
- 'Could not add attribute %s. No available span.',
420
- key
421
- )
393
+ logger.debug('Could not add attribute %s. No available span.', key)
422
394
  return false
423
395
  }
424
396
 
@@ -445,28 +417,21 @@ API.prototype.addCustomSpanAttribute = function addCustomSpanAttribute(key, valu
445
417
  * Optional. Any custom attributes to be displayed in the New Relic UI.
446
418
  */
447
419
  API.prototype.noticeError = function noticeError(error, customAttributes) {
448
- const metric = this.agent.metrics.getOrCreateMetric(
449
- NAMES.SUPPORTABILITY.API + '/noticeError'
450
- )
420
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/noticeError')
451
421
  metric.incrementCallCount()
452
422
 
453
423
  if (!this.agent.config.api.notice_error_enabled) {
454
- logger.debug(
455
- 'Config.api.notice_error_enabled set to false, not collecting error'
456
- )
424
+ logger.debug('Config.api.notice_error_enabled set to false, not collecting error')
457
425
  return false
458
426
  }
459
427
 
460
428
  // If high security mode is on or custom attributes are disabled,
461
429
  // noticeError does not collect custom attributes.
462
430
  if (this.agent.config.high_security) {
463
- logger.debug(
464
- 'Passing custom attributes to notice error API is disabled in high security mode.'
465
- )
431
+ logger.debug('Passing custom attributes to notice error API is disabled in high security mode.')
466
432
  } else if (!this.agent.config.api.custom_attributes_enabled) {
467
433
  logger.debug(
468
- 'Config.api.custom_attributes_enabled set to false, ' +
469
- 'ignoring custom error attributes.'
434
+ 'Config.api.custom_attributes_enabled set to false, ' + 'ignoring custom error attributes.'
470
435
  )
471
436
  }
472
437
 
@@ -513,13 +478,12 @@ API.prototype.noticeError = function noticeError(error, customAttributes) {
513
478
  * @param {string} name The name to use for the transaction.
514
479
  */
515
480
  API.prototype.addNamingRule = function addNamingRule(pattern, name) {
516
- var metric = this.agent.metrics.getOrCreateMetric(
517
- NAMES.SUPPORTABILITY.API + '/addNamingRule'
518
- )
481
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/addNamingRule')
519
482
  metric.incrementCallCount()
520
483
 
521
-
522
- if (!name) return logger.error("Simple naming rules require a replacement name.")
484
+ if (!name) {
485
+ return logger.error('Simple naming rules require a replacement name.')
486
+ }
523
487
 
524
488
  this.agent.userNormalizer.addSimple(pattern, '/' + name)
525
489
  }
@@ -538,12 +502,12 @@ API.prototype.addNamingRule = function addNamingRule(pattern, name) {
538
502
  * @param {RegExp} pattern The pattern to ignore.
539
503
  */
540
504
  API.prototype.addIgnoringRule = function addIgnoringRule(pattern) {
541
- var metric = this.agent.metrics.getOrCreateMetric(
542
- NAMES.SUPPORTABILITY.API + '/addIgnoringRule'
543
- )
505
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/addIgnoringRule')
544
506
  metric.incrementCallCount()
545
507
 
546
- if (!pattern) return logger.error("Must include a URL pattern to ignore.")
508
+ if (!pattern) {
509
+ return logger.error('Must include a URL pattern to ignore.')
510
+ }
547
511
 
548
512
  this.agent.userNormalizer.addSimple(pattern, null)
549
513
  }
@@ -591,17 +555,19 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
591
555
  return '<!-- NREUM: (' + num + ') -->'
592
556
  }
593
557
 
594
- var browser_monitoring = config.browser_monitoring
558
+ var browserMonitoring = config.browser_monitoring
595
559
 
596
560
  // config.browser_monitoring should always exist, but we don't want the agent
597
561
  // to bail here if something goes wrong
598
- if (!browser_monitoring) return _gracefail(2)
562
+ if (!browserMonitoring) {
563
+ return _gracefail(2)
564
+ }
599
565
 
600
566
  /* Can control header generation with configuration this setting is only
601
567
  * available in the newrelic.js config file, it is not ever set by the
602
568
  * server.
603
569
  */
604
- if (!browser_monitoring.enable) {
570
+ if (!browserMonitoring.enable) {
605
571
  // It has been disabled by the user; no need to warn them about their own
606
572
  // settings so fail quietly and gracefully.
607
573
  return _gracefail(0, true)
@@ -610,7 +576,9 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
610
576
  var trans = this.agent.getTransaction()
611
577
 
612
578
  // bail gracefully outside a transaction
613
- if (!trans || trans.isIgnored()) return _gracefail(1)
579
+ if (!trans || trans.isIgnored()) {
580
+ return _gracefail(1)
581
+ }
614
582
 
615
583
  var name = trans.getFullName()
616
584
 
@@ -618,7 +586,9 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
618
586
  * avoid people going crazy, trying to figure out why browser monitoring is
619
587
  * not working when they're missing a transaction name.
620
588
  */
621
- if (!name) return _gracefail(3)
589
+ if (!name) {
590
+ return _gracefail(3)
591
+ }
622
592
 
623
593
  var time = trans.timer.getDurationInMillis()
624
594
 
@@ -634,19 +604,25 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
634
604
  * newrelic.js, there will be no application_id set. We bail instead of
635
605
  * outputting null/undefined configuration values.
636
606
  */
637
- if (!appid) return _gracefail(4)
607
+ if (!appid) {
608
+ return _gracefail(4)
609
+ }
638
610
 
639
611
  /* If there is no browser_key, the server has likely decided to disable
640
612
  * browser monitoring.
641
613
  */
642
- var licenseKey = browser_monitoring.browser_key
643
- if (!licenseKey) return _gracefail(5)
614
+ var licenseKey = browserMonitoring.browser_key
615
+ if (!licenseKey) {
616
+ return _gracefail(5)
617
+ }
644
618
 
645
619
  /* If there is no agent_loader script, there is no point
646
620
  * in setting the rum data
647
621
  */
648
- var js_agent_loader = browser_monitoring.js_agent_loader
649
- if (!js_agent_loader) return _gracefail(6)
622
+ var jsAgentLoader = browserMonitoring.js_agent_loader
623
+ if (!jsAgentLoader) {
624
+ return _gracefail(6)
625
+ }
650
626
 
651
627
  /* If rum is enabled, but then later disabled on the server,
652
628
  * this is the only parameter that gets updated.
@@ -655,14 +631,16 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
655
631
  * the lifetime of an application, and it should be picked up
656
632
  * on the next ForceRestart by the collector.
657
633
  */
658
- var loader = browser_monitoring.loader
659
- if (loader === 'none') return _gracefail(7)
634
+ var loader = browserMonitoring.loader
635
+ if (loader === 'none') {
636
+ return _gracefail(7)
637
+ }
660
638
 
661
639
  // 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,
640
+ var rumHash = {
641
+ agent: browserMonitoring.js_agent_file,
642
+ beacon: browserMonitoring.beacon,
643
+ errorBeacon: browserMonitoring.error_beacon,
666
644
  licenseKey: licenseKey,
667
645
  applicationID: appid,
668
646
  applicationTime: time,
@@ -687,23 +665,18 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
687
665
  }
688
666
 
689
667
  if (!properties.isEmpty(attrs)) {
690
- rum_hash.atts = hashes.obfuscateNameUsingKey(JSON.stringify(attrs), key)
668
+ rumHash.atts = hashes.obfuscateNameUsingKey(JSON.stringify(attrs), key)
691
669
  }
692
670
 
693
671
  // if debugging, do pretty format of JSON
694
672
  var tabs = config.browser_monitoring.debug ? 2 : 0
695
- var json = JSON.stringify(rum_hash, null, tabs)
673
+ var json = JSON.stringify(rumHash, null, tabs)
696
674
 
697
675
  // set nonce attribute if passed in options
698
676
  var nonce = options && options.nonce ? 'nonce="' + options.nonce + '"' : ''
699
677
 
700
678
  // 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
- )
679
+ var out = util.format(RUM_STUB, nonce, json, jsAgentLoader)
707
680
 
708
681
  logger.trace('generating RUM header', out)
709
682
 
@@ -745,9 +718,9 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options)
745
718
  * @return {*} Returns the result of calling `handler`.
746
719
  */
747
720
  API.prototype.startSegment = function startSegment(name, record, handler, callback) {
748
- this.agent.metrics.getOrCreateMetric(
749
- NAMES.SUPPORTABILITY.API + '/startSegment'
750
- ).incrementCallCount()
721
+ this.agent.metrics
722
+ .getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/startSegment')
723
+ .incrementCallCount()
751
724
 
752
725
  // Check that we have usable arguments.
753
726
  if (!name || typeof handler !== 'function') {
@@ -824,11 +797,7 @@ API.prototype.startWebTransaction = function startWebTransaction(url, handle) {
824
797
  return handle()
825
798
  }
826
799
 
827
- logger.debug(
828
- 'starting web transaction %s (%s).',
829
- url,
830
- handle && handle.name
831
- )
800
+ logger.debug('starting web transaction %s (%s).', url, handle && handle.name)
832
801
 
833
802
  var shim = this.shim
834
803
  var tracer = this.agent.tracer
@@ -842,11 +811,7 @@ API.prototype.startWebTransaction = function startWebTransaction(url, handle) {
842
811
  }
843
812
 
844
813
  if (tx === parent) {
845
- logger.debug(
846
- 'not creating nested transaction %s using transaction %s',
847
- url,
848
- tx.id
849
- )
814
+ logger.debug('not creating nested transaction %s using transaction %s', url, tx.id)
850
815
  return tracer.addSegment(url, null, null, true, handle)
851
816
  }
852
817
 
@@ -932,12 +897,7 @@ function startBackgroundTransaction(name, group, handle) {
932
897
  return handle()
933
898
  }
934
899
 
935
- logger.debug(
936
- 'starting background transaction %s:%s (%s)',
937
- name,
938
- group,
939
- handle && handle.name
940
- )
900
+ logger.debug('starting background transaction %s:%s (%s)', name, group, handle && handle.name)
941
901
 
942
902
  var tracer = this.agent.tracer
943
903
  var shim = this.shim
@@ -952,11 +912,7 @@ function startBackgroundTransaction(name, group, handle) {
952
912
  }
953
913
 
954
914
  if (tx === parent) {
955
- logger.debug(
956
- 'not creating nested transaction %s using transaction %s',
957
- txName,
958
- tx.id
959
- )
915
+ logger.debug('not creating nested transaction %s using transaction %s', txName, tx.id)
960
916
  return tracer.addSegment(txName, null, null, true, handle)
961
917
  }
962
918
 
@@ -990,9 +946,7 @@ function startBackgroundTransaction(name, group, handle) {
990
946
  * the correct transaction context when called.
991
947
  */
992
948
  API.prototype.endTransaction = function endTransaction() {
993
- var metric = this.agent.metrics.getOrCreateMetric(
994
- NAMES.SUPPORTABILITY.API + '/endTransaction'
995
- )
949
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/endTransaction')
996
950
  metric.incrementCallCount()
997
951
 
998
952
  var tracer = this.agent.tracer
@@ -1053,7 +1007,7 @@ API.prototype.recordMetric = function recordMetric(name, value) {
1053
1007
 
1054
1008
  const stats = Object.create(null)
1055
1009
  const required = ['count', 'total', 'min', 'max', 'sumOfSquares']
1056
- const keyMap = {count: 'callCount'}
1010
+ const keyMap = { count: 'callCount' }
1057
1011
 
1058
1012
  for (let i = 0, l = required.length; i < l; ++i) {
1059
1013
  if (typeof value[required[i]] !== 'number') {
@@ -1084,9 +1038,7 @@ API.prototype.recordMetric = function recordMetric(name, value) {
1084
1038
  * by. Defaults to 1.
1085
1039
  */
1086
1040
  API.prototype.incrementMetric = function incrementMetric(name, value) {
1087
- const metric = this.agent.metrics.getOrCreateMetric(
1088
- NAMES.SUPPORTABILITY.API + '/incrementMetric'
1089
- )
1041
+ const metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/incrementMetric')
1090
1042
  metric.incrementCallCount()
1091
1043
 
1092
1044
  if (!value && value !== 0) {
@@ -1117,22 +1069,15 @@ API.prototype.incrementMetric = function incrementMetric(name, value) {
1117
1069
  * or boolean.
1118
1070
  */
1119
1071
  API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attributes) {
1120
- var metric = this.agent.metrics.getOrCreateMetric(
1121
- NAMES.SUPPORTABILITY.API + '/recordCustomEvent'
1122
- )
1072
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/recordCustomEvent')
1123
1073
  metric.incrementCallCount()
1124
1074
 
1125
1075
  // If high security mode is on, custom events are disabled.
1126
1076
  if (this.agent.config.high_security) {
1127
- logger.warnOnce(
1128
- "Custom Event",
1129
- "Custom events are disabled by high security mode."
1130
- )
1077
+ logger.warnOnce('Custom Event', 'Custom events are disabled by high security mode.')
1131
1078
  return false
1132
1079
  } 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
- )
1080
+ logger.debug('Config.api.custom_events_enabled set to false, not collecting value')
1136
1081
  return false
1137
1082
  }
1138
1083
 
@@ -1192,7 +1137,7 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1192
1137
  }
1193
1138
 
1194
1139
  var tx = this.agent.getTransaction()
1195
- var priority = tx && tx.priority || Math.random()
1140
+ var priority = (tx && tx.priority) || Math.random()
1196
1141
  this.agent.customEventAggregator.add([instrinics, filteredAttributes], priority)
1197
1142
  }
1198
1143
 
@@ -1216,9 +1161,7 @@ API.prototype.recordCustomEvent = function recordCustomEvent(eventType, attribut
1216
1161
  * this function.
1217
1162
  */
1218
1163
  API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
1219
- var metric = this.agent.metrics.getOrCreateMetric(
1220
- NAMES.SUPPORTABILITY.API + '/instrument'
1221
- )
1164
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/instrument')
1222
1165
  metric.incrementCallCount()
1223
1166
 
1224
1167
  var opts = moduleName
@@ -1253,15 +1196,18 @@ API.prototype.instrument = function instrument(moduleName, onRequire, onError) {
1253
1196
  * If provided, should `onRequire` throw an error, the error will be passed to
1254
1197
  * this function.
1255
1198
  */
1256
- API.prototype.instrumentConglomerate =
1257
- function instrumentConglomerate(moduleName, onRequire, onError) {
1258
- this.agent.metrics.getOrCreateMetric(
1259
- NAMES.SUPPORTABILITY.API + '/instrumentConglomerate'
1260
- ).incrementCallCount()
1199
+ API.prototype.instrumentConglomerate = function instrumentConglomerate(
1200
+ moduleName,
1201
+ onRequire,
1202
+ onError
1203
+ ) {
1204
+ this.agent.metrics
1205
+ .getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/instrumentConglomerate')
1206
+ .incrementCallCount()
1261
1207
 
1262
1208
  let opts = moduleName
1263
1209
  if (typeof opts === 'string') {
1264
- opts = {moduleName, onRequire, onError}
1210
+ opts = { moduleName, onRequire, onError }
1265
1211
  }
1266
1212
 
1267
1213
  opts.type = MODULE_TYPE.CONGLOMERATE
@@ -1287,8 +1233,7 @@ function instrumentConglomerate(moduleName, onRequire, onError) {
1287
1233
  * If provided, should `onRequire` throw an error, the error will be passed to
1288
1234
  * this function.
1289
1235
  */
1290
- API.prototype.instrumentDatastore =
1291
- function instrumentDatastore(moduleName, onRequire, onError) {
1236
+ API.prototype.instrumentDatastore = function instrumentDatastore(moduleName, onRequire, onError) {
1292
1237
  var metric = this.agent.metrics.getOrCreateMetric(
1293
1238
  NAMES.SUPPORTABILITY.API + '/instrumentDatastore'
1294
1239
  )
@@ -1325,8 +1270,7 @@ function instrumentDatastore(moduleName, onRequire, onError) {
1325
1270
  * @param {object} module
1326
1271
  * The actual module object or function we're instrumenting
1327
1272
  */
1328
- API.prototype.instrumentLoadedModule =
1329
- function instrumentLoadedModule(moduleName, module) {
1273
+ API.prototype.instrumentLoadedModule = function instrumentLoadedModule(moduleName, module) {
1330
1274
  var metric = this.agent.metrics.getOrCreateMetric(
1331
1275
  NAMES.SUPPORTABILITY.API + '/instrumentLoadedModule'
1332
1276
  )
@@ -1357,10 +1301,7 @@ function instrumentLoadedModule(moduleName, module) {
1357
1301
 
1358
1302
  return true
1359
1303
  } catch (error) {
1360
- logger.error(
1361
- 'instrumentLoadedModule encountered an error, module not instrumentend: %s',
1362
- error
1363
- )
1304
+ logger.error('instrumentLoadedModule encountered an error, module not instrumentend: %s', error)
1364
1305
  }
1365
1306
  }
1366
1307
 
@@ -1383,8 +1324,11 @@ function instrumentLoadedModule(moduleName, module) {
1383
1324
  * If provided, should `onRequire` throw an error, the error will be passed to
1384
1325
  * this function.
1385
1326
  */
1386
- API.prototype.instrumentWebframework =
1387
- function instrumentWebframework(moduleName, onRequire, onError) {
1327
+ API.prototype.instrumentWebframework = function instrumentWebframework(
1328
+ moduleName,
1329
+ onRequire,
1330
+ onError
1331
+ ) {
1388
1332
  var metric = this.agent.metrics.getOrCreateMetric(
1389
1333
  NAMES.SUPPORTABILITY.API + '/instrumentWebframework'
1390
1334
  )
@@ -1422,8 +1366,7 @@ function instrumentWebframework(moduleName, onRequire, onError) {
1422
1366
  * If provided, should `onRequire` throw an error, the error will be passed to
1423
1367
  * this function.
1424
1368
  */
1425
- API.prototype.instrumentMessages =
1426
- function instrumentMessages(moduleName, onRequire, onError) {
1369
+ API.prototype.instrumentMessages = function instrumentMessages(moduleName, onRequire, onError) {
1427
1370
  var metric = this.agent.metrics.getOrCreateMetric(
1428
1371
  NAMES.SUPPORTABILITY.API + '/instrumentMessages'
1429
1372
  )
@@ -1448,18 +1391,16 @@ function instrumentMessages(moduleName, onRequire, onError) {
1448
1391
  * @returns {*} The object containing the current trace and span ids
1449
1392
  */
1450
1393
  API.prototype.getTraceMetadata = function getTraceMetadata() {
1451
- var metric = this.agent.metrics.getOrCreateMetric(
1452
- NAMES.SUPPORTABILITY.API + '/getTraceMetadata'
1453
- )
1394
+ var metric = this.agent.metrics.getOrCreateMetric(NAMES.SUPPORTABILITY.API + '/getTraceMetadata')
1454
1395
  metric.incrementCallCount()
1455
1396
 
1456
1397
  const metadata = {}
1457
1398
 
1458
1399
  const segment = this.agent.tracer.getSegment()
1459
1400
  if (!segment) {
1460
- logger.debug("No transaction found when calling API#getTraceMetadata")
1401
+ logger.debug('No transaction found when calling API#getTraceMetadata')
1461
1402
  } else if (!this.agent.config.distributed_tracing.enabled) {
1462
- logger.debug("Distributed tracing disabled when calling API#getTraceMetadata")
1403
+ logger.debug('Distributed tracing disabled when calling API#getTraceMetadata')
1463
1404
  } else {
1464
1405
  metadata.traceId = segment.transaction.traceId
1465
1406
 
@@ -1492,8 +1433,7 @@ API.prototype.getTraceMetadata = function getTraceMetadata() {
1492
1433
  * Callback function that runs when agent stops.
1493
1434
  */
1494
1435
  API.prototype.shutdown = function shutdown(options, cb) {
1495
- this.agent.metrics.getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/shutdown`)
1496
- .incrementCallCount()
1436
+ this.agent.metrics.getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/shutdown`).incrementCallCount()
1497
1437
 
1498
1438
  let callback = cb
1499
1439
  if (typeof options === 'function') {
@@ -1529,10 +1469,7 @@ function _doShutdown(api, options, callback) {
1529
1469
 
1530
1470
  function afterHarvest(error) {
1531
1471
  if (error) {
1532
- logger.error(
1533
- error,
1534
- 'An error occurred while running last harvest before shutdown.'
1535
- )
1472
+ logger.error(error, 'An error occurred while running last harvest before shutdown.')
1536
1473
  }
1537
1474
  agent.stop(callback)
1538
1475
  }
@@ -1543,10 +1480,7 @@ function _doShutdown(api, options, callback) {
1543
1480
  agent.stop(callback)
1544
1481
  }, options.timeout).unref()
1545
1482
  } else if (options.timeout) {
1546
- logger.warn(
1547
- 'options.timeout should be of type "number". Got %s',
1548
- typeof options.timeout
1549
- )
1483
+ logger.warn('options.timeout should be of type "number". Got %s', typeof options.timeout)
1550
1484
  }
1551
1485
 
1552
1486
  agent.on('started', function shutdownHarvest() {
@@ -1556,10 +1490,7 @@ function _doShutdown(api, options, callback) {
1556
1490
  agent.on('errored', function logShutdownError(error) {
1557
1491
  agent.stop(callback)
1558
1492
  if (error) {
1559
- logger.error(
1560
- error,
1561
- 'The agent encountered an error after calling shutdown.'
1562
- )
1493
+ logger.error(error, 'The agent encountered an error after calling shutdown.')
1563
1494
  }
1564
1495
  })
1565
1496
  } else if (options.collectPendingData) {
@@ -1603,7 +1534,7 @@ function _filterAttributes(attributes, name) {
1603
1534
  if (!isValidType(attributes[attributeKey])) {
1604
1535
  logger.info(
1605
1536
  `Omitting attribute ${attributeKey} from ${name} call, type must ` +
1606
- 'be boolean, number, or string'
1537
+ 'be boolean, number, or string'
1607
1538
  )
1608
1539
  return
1609
1540
  }