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
@@ -31,17 +31,19 @@ class MergeServerConfig {
31
31
  }
32
32
 
33
33
  updateArray(value, local, localKey) {
34
- value.forEach( (element) => {
35
- if (local[localKey].indexOf(element) === -1) local[localKey].push(element)
34
+ value.forEach((element) => {
35
+ if (local[localKey].indexOf(element) === -1) {
36
+ local[localKey].push(element)
37
+ }
36
38
  })
37
39
  }
38
40
 
39
41
  updateObject(value, local, localKey) {
40
42
  // go through each key of the object and update it
41
- Object.keys(value).forEach( (element) => {
43
+ Object.keys(value).forEach((element) => {
42
44
  if (Array.isArray(local[localKey][element]) && Array.isArray(value[element])) {
43
45
  // if both key-values are arrays, push the remote value onto the local array
44
- value[element].forEach( (elementValue) => {
46
+ value[element].forEach((elementValue) => {
45
47
  if (-1 === local[localKey][element].indexOf(elementValue)) {
46
48
  local[localKey][element].push(elementValue)
47
49
  }
@@ -54,7 +56,7 @@ class MergeServerConfig {
54
56
  }
55
57
 
56
58
  isSimpleObject(thing) {
57
- return 'object' === (typeof thing) && thing !== null
59
+ return 'object' === typeof thing && thing !== null
58
60
  }
59
61
  }
60
62
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const logger = require('../logger').child({component: 'custom-event-aggregator'})
8
+ const logger = require('../logger').child({ component: 'custom-event-aggregator' })
9
9
  const EventAggregator = require('../aggregators/event-aggregator')
10
10
 
11
11
  const NAMES = require('../metrics/names')
@@ -8,12 +8,11 @@
8
8
  // TODO: remove in favor of /lib/db/query-parsers/sql.js
9
9
  // This module is currently used only in the Oracle instrumentation
10
10
 
11
- var logger = require('../logger').child({component: 'parse_sql'})
11
+ var logger = require('../logger').child({ component: 'parse_sql' })
12
12
  var StatementMatcher = require('./statement-matcher')
13
13
  var ParsedStatement = require('./parsed-statement')
14
14
  var stringify = require('json-stringify-safe')
15
15
 
16
-
17
16
  var OPERATIONS = [
18
17
  new StatementMatcher('select', /^\s*select[\S\s]*from[\s\[]+([^\]\s,)(;]*).*/gi),
19
18
  new StatementMatcher('update', /^\s*update\s+([^\s,;]*).*/gi),
@@ -29,14 +28,13 @@ module.exports = function parseSql(type, sql) {
29
28
  // Sometimes we get an object here from MySQL. We have been unable to
30
29
  // reproduce it, so we'll just log what that object is and return a statement
31
30
  // type of `other`.
32
- if (typeof sql === 'object' && sql.sql !== undefined) sql = sql.sql
31
+ if (typeof sql === 'object' && sql.sql !== undefined) {
32
+ sql = sql.sql
33
+ }
33
34
  if (typeof sql !== 'string') {
34
- if (logger.traceEnabled()) {
35
+ if (logger.traceEnabled()) {
35
36
  try {
36
- logger.trace(
37
- 'parseSQL got an a non-string sql that looks like: %s',
38
- stringify(sql)
39
- )
37
+ logger.trace('parseSQL got an a non-string sql that looks like: %s', stringify(sql))
40
38
  } catch (err) {
41
39
  logger.debug(err, 'Unabled to stringify SQL')
42
40
  }
@@ -46,7 +44,6 @@ module.exports = function parseSql(type, sql) {
46
44
 
47
45
  sql = sql.replace(COMMENT_PATTERN, '').trim()
48
46
 
49
-
50
47
  var parsedStatement
51
48
 
52
49
  for (var i = 0, l = OPERATIONS.length; i < l; i++) {
@@ -5,9 +5,8 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const {DB, ALL} = require('../metrics/names')
9
- const {DESTINATIONS} = require('../config/attribute-filter')
10
-
8
+ const { DB, ALL } = require('../metrics/names')
9
+ const { DESTINATIONS } = require('../config/attribute-filter')
11
10
 
12
11
  function ParsedStatement(type, operation, collection, raw) {
13
12
  this.type = type
@@ -45,8 +44,7 @@ ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope)
45
44
  // 'statement' metric and use the 'operation' metric as the scoped metric for
46
45
  // transaction breakdowns.
47
46
  if (this.collection) {
48
- var collection =
49
- DB.STATEMENT + '/' + thisTypeSlash + this.collection + '/' + this.operation
47
+ var collection = DB.STATEMENT + '/' + thisTypeSlash + this.collection + '/' + this.operation
50
48
  transaction.measure(collection, null, duration, exclusive)
51
49
  if (scope) {
52
50
  transaction.measure(collection, scope, duration, exclusive)
@@ -63,18 +61,13 @@ ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope)
63
61
  // Datastore instance metrics.
64
62
  const attributes = segment.attributes.get(DESTINATIONS.TRANS_SEGMENT)
65
63
  if (attributes.host && attributes.port_path_or_id) {
66
- var instanceName = DB.INSTANCE + '/' + thisTypeSlash + attributes.host +
67
- '/' + attributes.port_path_or_id
64
+ var instanceName =
65
+ DB.INSTANCE + '/' + thisTypeSlash + attributes.host + '/' + attributes.port_path_or_id
68
66
  transaction.measure(instanceName, null, duration, exclusive)
69
67
  }
70
68
 
71
69
  if (this.raw) {
72
- transaction.agent.queries.add(
73
- segment,
74
- this.type.toLowerCase(),
75
- this.raw,
76
- this.trace
77
- )
70
+ transaction.agent.queries.add(segment, this.type.toLowerCase(), this.raw, this.trace)
78
71
  }
79
72
  }
80
73
 
@@ -5,11 +5,10 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- var logger = require('../../logger').child({component: 'sql_query_parser'})
8
+ var logger = require('../../logger').child({ component: 'sql_query_parser' })
9
9
  var StatementMatcher = require('../statement-matcher')
10
10
  var stringify = require('json-stringify-safe')
11
11
 
12
-
13
12
  var OPERATIONS = [
14
13
  new StatementMatcher(
15
14
  'select',
@@ -31,14 +30,13 @@ module.exports = function parseSql(sql) {
31
30
  // Sometimes we get an object here from MySQL. We have been unable to
32
31
  // reproduce it, so we'll just log what that object is and return a statement
33
32
  // type of `other`.
34
- if (typeof sql === 'object' && sql.sql !== undefined) sql = sql.sql
33
+ if (typeof sql === 'object' && sql.sql !== undefined) {
34
+ sql = sql.sql
35
+ }
35
36
  if (typeof sql !== 'string') {
36
- if (logger.traceEnabled()) {
37
+ if (logger.traceEnabled()) {
37
38
  try {
38
- logger.trace(
39
- 'parseSQL got an a non-string sql that looks like: %s',
40
- stringify(sql)
41
- )
39
+ logger.trace('parseSQL got an a non-string sql that looks like: %s', stringify(sql))
42
40
  } catch (err) {
43
41
  logger.debug(err, 'Unabler to stringify SQL')
44
42
  }
@@ -52,7 +50,6 @@ module.exports = function parseSql(sql) {
52
50
 
53
51
  sql = sql.replace(COMMENT_PATTERN, '').trim()
54
52
 
55
-
56
53
  var parsedStatement
57
54
 
58
55
  for (var i = 0, l = OPERATIONS.length; i < l; i++) {
@@ -20,7 +20,9 @@ util.inherits(QuerySample, Stats)
20
20
 
21
21
  QuerySample.prototype.aggregate = function aggregate(slowQuery) {
22
22
  this.recordValue(slowQuery.duration)
23
- if (this.trace && this.trace.duration >= slowQuery.duration) return
23
+ if (this.trace && this.trace.duration >= slowQuery.duration) {
24
+ return
25
+ }
24
26
  this.trace = slowQuery
25
27
  }
26
28
 
@@ -45,7 +47,9 @@ QuerySample.prototype.prepareJSON = function prepareJSON(done) {
45
47
  }
46
48
 
47
49
  function respond(err, data) {
48
- if (err) return done(err)
50
+ if (err) {
51
+ return done(err)
52
+ }
49
53
 
50
54
  done(null, _getJSON(sample, trace, transaction, data))
51
55
  }
@@ -79,7 +83,7 @@ function _getJSON(sample, trace, transaction, data) {
79
83
  QuerySample.prototype.getParams = function getParams() {
80
84
  var segmentAttrs = this.trace.segment.getAttributes()
81
85
  var params = {
82
- backtrace: this.trace.trace,
86
+ backtrace: this.trace.trace
83
87
  }
84
88
 
85
89
  if (segmentAttrs.host) {
@@ -6,7 +6,7 @@
6
6
  'use strict'
7
7
 
8
8
  const a = require('async')
9
- const logger = require('../logger').child({component: 'query_tracer'})
9
+ const logger = require('../logger').child({ component: 'query_tracer' })
10
10
  const Aggregator = require('../aggregators/base-aggregator')
11
11
  const SlowQuery = require('./slow-query')
12
12
  const QuerySample = require('./query-sample')
@@ -19,10 +19,10 @@ class QueryTraceAggregator extends Aggregator {
19
19
  throw new Error('config required by query trace aggregator')
20
20
  }
21
21
  super(opts, collector)
22
-
22
+
23
23
  const config = opts.config
24
24
  this.samples = new Map()
25
-
25
+
26
26
  this.config = config
27
27
  }
28
28
 
@@ -34,7 +34,7 @@ class QueryTraceAggregator extends Aggregator {
34
34
  shortest = trace
35
35
  }
36
36
  }
37
-
37
+
38
38
  this.samples.delete(shortest.normalized)
39
39
  }
40
40
 
@@ -74,32 +74,32 @@ class QueryTraceAggregator extends Aggregator {
74
74
  )
75
75
  return
76
76
  }
77
-
77
+
78
78
  if (segment.getDurationInMillis() < ttConfig.explain_threshold) {
79
79
  return
80
80
  }
81
-
81
+
82
82
  slowQuery = slowQuery || new SlowQuery(segment, type, query, trace)
83
-
83
+
84
84
  segment.addAttribute('backtrace', slowQuery.trace)
85
-
85
+
86
86
  if (!this.config.slow_sql.enabled) {
87
87
  return
88
88
  }
89
-
89
+
90
90
  const ownSample = this.samples.get(slowQuery.normalized)
91
91
  if (ownSample) {
92
92
  return ownSample.aggregate(slowQuery)
93
93
  }
94
-
94
+
95
95
  this.samples.set(slowQuery.normalized, new QuerySample(this, slowQuery))
96
-
96
+
97
97
  // Do not remove the shortest sample when in serverless mode, since
98
98
  // sampling is disabled.
99
99
  if (this.config.serverless_mode.enabled) {
100
100
  return
101
101
  }
102
-
102
+
103
103
  if (this.samples.size > this.config.slow_sql.max_samples) {
104
104
  this.removeShortest()
105
105
  }
package/lib/db/utils.js CHANGED
@@ -11,5 +11,5 @@ function extractDatabaseChangeFromUse(sql) {
11
11
  // The character ranges for this were pulled from
12
12
  // http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
13
13
  var match = /^\s*use[^\w`]+([\w$_\u0080-\uFFFF]+|`[^`]+`)[\s;]*$/i.exec(sql)
14
- return match && match[1] || null
14
+ return (match && match[1]) || null
15
15
  }